{"size": 2948, "ext": "js", "max_stars_repo_path": "__tests__/unit/models/user.test.js", "max_stars_repo_name": "KCFindstr/ourpixels-node", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "__tests__/unit/models/user.test.js", "max_issues_repo_name": "KCFindstr/ourpixels-node", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "__tests__/unit/models/user.test.js", "max_forks_repo_name": "KCFindstr/ourpixels-node", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.4137931034, "max_line_length": 84, "alphanum_fraction": 0.5814111262}
const User = require('../../../models/user');
const { expect, assert } = require('chai');

function getUserStruct() {
	return {
		id: 100,
		username: 'admin',
		password: '123456',
		admin: 0,
		createdAt: Date(),
		updatedAt: Date(),
		token: '987654'
	};
}

describe('user', () => {
	describe('general', () => {
		it('should pass if everything is good', async () => {
			let temp = getUserStruct();
			let user = new User(temp);
			assert(await user.validate());
		});
	});

	describe('id', () => {
		it('should fail if not presented', async () => {
			try {
				let temp = getUserStruct();
				temp.id = undefined;
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Id is required.');
			}
		});
		it('should fail if not numeric', async () => {
			try {
				let temp = getUserStruct();
				temp.id = 'test';
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Id must be numeric.');
			}
		});
	});

	describe('username', () => {
		it('should fail if not presented', async () => {
			try {
				let temp = getUserStruct();
				temp.username = undefined;
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Username is required.');
			}
		});
		it('should fail if too short', async () => {
			try {
				let temp = getUserStruct();
				temp.username = 'lo';
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Username must have 3-18 characters.');
			}
		});
		it('should fail if too long', async () => {
			try {
				let temp = getUserStruct();
				temp.username = 'areallylongusername';
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Username must have 3-18 characters.');
			}
		});
	});

	describe('password', () => {
		it('should fail if not presented', async () => {
			try {
				let temp = getUserStruct();
				temp.password = undefined;
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Password is required.');
			}
		});
	});

	describe('admin', () => {
		it('should fail if not presented', async () => {
			try {
				let temp = getUserStruct();
				temp.admin = undefined;
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Admin is required.');
			}
		});	
		it('should fail if not numeric', async () => {
			try {
				let temp = getUserStruct();
				temp.admin = 'test';
				let user = new User(temp);
				assert(!await user.validate());
			} catch (error) {
				expect(error.errors[0].message).to.equal('Admin must be numeric.');
			}
		});
	});
});