{"size": 1487, "ext": "js", "max_stars_repo_path": "services/users.test.js", "max_stars_repo_name": "Thomas-Machielsen/beer-api", "max_stars_repo_stars_event_min_datetime": "2020-07-24T23:27:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T23:27:49.000Z", "max_issues_repo_path": "services/users.test.js", "max_issues_repo_name": "Thomas-Machielsen/beer-api", "max_issues_repo_issues_event_min_datetime": "2020-09-04T03:16:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-04T03:16:01.000Z", "max_forks_repo_path": "services/users.test.js", "max_forks_repo_name": "Thomas-Machielsen/beer-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 24.3770491803, "max_line_length": 77, "alphanum_fraction": 0.5870880968}
const UserService = require('./users');
const Sequelize = require("sequelize");
const UserSchema = require('../schemas/User');
const { UNDEFINED } = require('../constants').ERROR;
const { REGISTERED } = require('../constants').SUCCESS;

describe('Userservice to output data', () => {

  describe('addUser', () => {

    it('should be callable', () => {
      const Users = new UserService(Sequelize, UserSchema);

      expect(typeof Users.addUser).toBe('function');
    });

    it('should return an error when no name or password is provided', () => {
      const Users = new UserService(Sequelize, UserSchema);

      const req = {};
      const mockData = req.body = {
         username: '', password: ''
      };

      const result = Users.addUser(req);
      const expectedResult = {
        "success": false,
        "message": UNDEFINED
      };

      expect(result).rejects.toEqual(expectedResult);
    })
  });

  it('should return a success message on succces', () => {
    const UserSchemaMock = {
      User: {
        create: () => {
          return Promise.resolve(mockData)
        }
      }
    };

    const Users = new UserService(Sequelize, UserSchemaMock);

    const req = {};
    const mockData = req.body = {
      username: 'admin',
      password: 'superAdmin'
    };

    const result = Users.addUser(req);
    const expectedResult = {
      "success": true,
      "message": REGISTERED
    };

    expect(result).resolves.toEqual(expectedResult);
  })

});