Merge branch 'master' into toggle_comment_date

This commit is contained in:
Kim Gardner
2018-09-10 10:53:34 -04:00
committed by GitHub
3 changed files with 66 additions and 3 deletions
@@ -61,6 +61,7 @@
line-height: 1.5;
font-weight: 300;
margin-bottom: 8px;
overflow-wrap: break-word;
}
.body {
@@ -188,4 +189,4 @@
.commentContentFooter {
flex: 1;
}
}
+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🖕')