2017-11-16 16:45:01 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-11-16 16:45:01 +01:00
|
|
|
const User = require('./user');
|
|
|
|
|
|
|
|
test('should create user', t => {
|
|
|
|
const user = new User({ name: 'ole', email: 'some@email.com' });
|
|
|
|
t.is(user.name, 'ole');
|
|
|
|
t.is(user.email, 'some@email.com');
|
|
|
|
t.is(
|
|
|
|
user.imageUrl,
|
2020-04-14 22:29:11 +02:00
|
|
|
'https://gravatar.com/avatar/d8ffeba65ee5baf57e4901690edc8e1b?size=42&default=retro',
|
2017-11-16 16:45:01 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 20:51:15 +02:00
|
|
|
test('should create user, all fields', t => {
|
|
|
|
const user = new User({
|
|
|
|
name: 'Admin',
|
|
|
|
username: 'admin',
|
|
|
|
email: 'some@email.com',
|
|
|
|
permissions: ['admin', 'client'],
|
|
|
|
});
|
|
|
|
t.is(user.name, 'Admin');
|
|
|
|
t.is(user.username, 'admin');
|
|
|
|
t.is(user.email, 'some@email.com');
|
|
|
|
t.deepEqual(user.permissions, ['admin', 'client']);
|
|
|
|
t.is(
|
|
|
|
user.imageUrl,
|
|
|
|
'https://gravatar.com/avatar/d8ffeba65ee5baf57e4901690edc8e1b?size=42&default=retro',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should require email or username', t => {
|
2020-04-13 22:53:06 +02:00
|
|
|
const error = t.throws(
|
|
|
|
() => {
|
2017-11-16 16:45:01 +01:00
|
|
|
const user = new User(); // eslint-disable-line
|
2020-04-13 22:53:06 +02:00
|
|
|
},
|
2020-04-14 22:29:11 +02:00
|
|
|
{ instanceOf: Error },
|
2020-04-13 22:53:06 +02:00
|
|
|
);
|
2017-11-16 16:45:01 +01:00
|
|
|
|
2020-04-19 20:51:15 +02:00
|
|
|
t.is(error.message, 'Username or Email us reuqired');
|
2017-11-16 16:45:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Should create user with only email defined', t => {
|
|
|
|
const user = new User({ email: 'some@email.com' });
|
|
|
|
|
|
|
|
t.is(user.email, 'some@email.com');
|
|
|
|
});
|
2020-04-19 20:51:15 +02:00
|
|
|
|
|
|
|
test('Should require valid email', t => {
|
|
|
|
const error = t.throws(
|
|
|
|
() => {
|
|
|
|
new User({ email: 'some@' }); // eslint-disable-line
|
|
|
|
},
|
|
|
|
{ instanceOf: Error },
|
|
|
|
);
|
|
|
|
|
|
|
|
t.is(error.message, 'Email "value" must be a valid email');
|
|
|
|
});
|
2020-04-28 08:17:04 +02:00
|
|
|
|
|
|
|
test('Should create user with only username defined', t => {
|
|
|
|
const user = new User({ username: 'some-user' });
|
|
|
|
t.is(user.username, 'some-user');
|
|
|
|
t.is(
|
|
|
|
user.imageUrl,
|
|
|
|
'https://gravatar.com/avatar/140fd5a002fb8d728a9848f8c9fcea2a?size=42&default=retro',
|
|
|
|
);
|
|
|
|
});
|
2020-05-12 23:05:26 +02:00
|
|
|
|
|
|
|
test('Should create user with only username defined and undefined email', t => {
|
|
|
|
const user = new User({ username: 'some-user', email: undefined });
|
|
|
|
t.is(user.username, 'some-user');
|
|
|
|
});
|