1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/user.test.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
2018-12-17 09:24:49 +01:00
const test = require('ava');
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,
'https://gravatar.com/avatar/d8ffeba65ee5baf57e4901690edc8e1b?size=42&default=retro',
);
});
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 => {
const error = t.throws(
() => {
const user = new User(); // eslint-disable-line
},
{ instanceOf: Error },
);
t.is(error.message, 'Username or Email us reuqired');
});
test('Should create user with only email defined', t => {
const user = new User({ email: 'some@email.com' });
t.is(user.email, 'some@email.com');
});
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');
});
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');
});