1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: user should not crash if email is missing

This commit is contained in:
Ivar Conradi Østhus 2020-04-28 08:17:04 +02:00
parent 9f86bce0ab
commit bf7a246707
3 changed files with 18 additions and 3 deletions

View File

@ -41,7 +41,7 @@ class ContextFieldStore {
}
async _createFromConfig(customContextFields) {
if (customContextFields) {
if (customContextFields && customContextFields.length > 0) {
this.logger.info(
'Create custom context fields',
customContextFields,

View File

@ -24,7 +24,13 @@ module.exports = class User {
this.email = email;
this.systemId = systemId;
this.permissions = permissions;
this.imageUrl =
imageUrl || gravatarUrl(email, { size: '42', default: 'retro' });
this.imageUrl = imageUrl || this.generateImageUrl();
}
generateImageUrl() {
return gravatarUrl(this.email || this.username, {
size: '42',
default: 'retro',
});
}
};

View File

@ -57,3 +57,12 @@ test('Should require valid email', t => {
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',
);
});