Merge branch 'master' into word_break

This commit is contained in:
Kiwi
2018-09-07 21:51:37 +02:00
committed by GitHub
2 changed files with 64 additions and 2 deletions
+12 -2
View File
@@ -68,6 +68,8 @@ async function upsertUser(
},
});
if (user) {
user.wasUpserted = false;
user.$ignore('wasUpserted');
return user;
}
@@ -98,8 +100,16 @@ async function upsertUser(
// Save the user in the database.
await user.save();
// Emit that the user was created.
ctx.pubsub.publish('userCreated', user);
if (ctx) {
// Emit that the user was created if the context is set.
ctx.pubsub.publish('userCreated', user);
}
// Indicate that the user was upserted.
user.wasUpserted = true;
user.$ignore('wasUpserted');
return user;
}
// Users is the interface for the application to interact with the
+52
View File
@@ -363,6 +363,58 @@ describe('services.UsersService', () => {
});
});
describe('#upsertExternalUser', () => {
it('should return a user when the desired user is found', async () => {
const ctx = Context.forSystem();
let user = await UsersService.upsertExternalUser(
ctx,
'an-id',
'a-provider',
'a-display-name'
);
expect(user).to.be.defined;
expect(user.wasUpserted).to.be.true;
user = await UsersService.upsertExternalUser(
ctx,
'an-id',
'a-provider',
'a-display-name'
);
expect(user).to.be.defined;
expect(user.wasUpserted).to.be.false;
});
it('should return a user when the desired user is not found', async () => {
const ctx = Context.forSystem();
let user = await UsersService.upsertExternalUser(
ctx,
'an-id',
'a-provider',
'a-display-name'
);
expect(user).to.be.defined;
expect(user.wasUpserted).to.be.true;
expect(user).to.have.property('metadata');
expect(user.metadata).to.have.property('displayName', 'a-display-name');
});
it('should work if the context passed is null', async () => {
let user = await UsersService.upsertExternalUser(
null,
'an-id',
'a-provider',
'a-display-name'
);
expect(user).to.be.defined;
expect(user.wasUpserted).to.be.true;
});
});
describe('#isValidUsername', () => {
it('should not allow non-alphanumeric characters in usernames', () => {
return UsersService.isValidUsername('hi🖕')