mirror of
https://github.com/Unleash/unleash.git
synced 2026-09-24 03:16:31 +00:00
fix: user should not crash if email is missing
This commit is contained in:
@@ -41,7 +41,7 @@ class ContextFieldStore {
|
||||
}
|
||||
|
||||
async _createFromConfig(customContextFields) {
|
||||
if (customContextFields) {
|
||||
if (customContextFields && customContextFields.length > 0) {
|
||||
this.logger.info(
|
||||
'Create custom context fields',
|
||||
customContextFields,
|
||||
|
||||
+8
-2
@@ -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',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user