Fix tests.

This commit is contained in:
gaba
2017-05-08 13:12:24 -07:00
parent 6310528804
commit c4c0ee79cd
8 changed files with 106 additions and 54 deletions
+11
View File
@@ -32,11 +32,18 @@ describe('graph.mutations.ignoreUser', () => {
// @TODO (bengo) - test a user can't ignore themselves
it('users can ignoreUser', async () => {
UsersService.findLocalUser('usernameB@example.com')
.then((user) => {
console.log('--------- debug user', user);
});
const user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
console.log('--------------- debug aca -2');
const userToIgnore = await UsersService.createLocalUser('usernameB@example.com', 'password', 'usernameB');
console.log('--------------- debug aca -1');
const context = new Context({user});
const ignoreUserResponse = await graphql(schema, ignoreUserMutation, {}, context, {id: userToIgnore.id});
if (ignoreUserResponse.errors && ignoreUserResponse.errors.length) {
console.log('--------------- debug aca 0');
console.error(ignoreUserResponse.errors);
}
expect(ignoreUserResponse.errors).to.be.empty;
@@ -44,13 +51,17 @@ describe('graph.mutations.ignoreUser', () => {
// now check my ignored users
const myIgnoredUsersResponse = await graphql(schema, getMyIgnoredUsersQuery, {}, context, {});
if (myIgnoredUsersResponse.errors && myIgnoredUsersResponse.errors.length) {
console.log('debug aca 1');
console.error(myIgnoredUsersResponse.errors);
}
expect(myIgnoredUsersResponse.errors).to.be.empty;
const myIgnoredUsers = myIgnoredUsersResponse.data.myIgnoredUsers;
expect(myIgnoredUsers.length).to.equal(1);
console.log('debug aca 2');
expect(myIgnoredUsers[0].id).to.equal(userToIgnore.id);
console.log('debug aca 3');
expect(myIgnoredUsers[0].username).to.equal(userToIgnore.username);
console.log('debug aca 4');
});
it('users cannot ignore themselves', async () => {
+21 -18
View File
@@ -34,7 +34,7 @@ describe('graph.mutations.removeCommentTag', () => {
const context = new Context({user});
// add a tag first
await CommentsService.addTag(comment.id, 'BEST', user);
await CommentsService.addTag(comment.id, 'BEST', user.id);
const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'});
if (response.errors && response.errors.length) {
console.error(response.errors);
@@ -59,25 +59,28 @@ describe('graph.mutations.removeCommentTag', () => {
models: ['COMMENTS']
}
}
});
Object.entries({
'anonymous': undefined,
'regular commenter': new UserModel({}),
'banned moderator': new UserModel({roles: ['MODERATOR'], status: 'BANNED'})
}).forEach(([ userDescription, user ]) => {
it(userDescription, async function () {
const context = new Context({user});
})
.then(() => {
Object.entries({
'anonymous': undefined,
'regular commenter': new UserModel({}),
'banned moderator': new UserModel({roles: ['MODERATOR'], status: 'BANNED'})
}).forEach(([ userDescription, user ]) => {
it(userDescription, async function () {
const context = new Context({user});
// add a tag first
await CommentsService.addTag(comment.id, 'BEST', user);
const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'});
if (response.errors && response.errors.length) {
console.error(response.errors);
}
expect(response.errors).to.be.empty;
// add a tag first
await CommentsService.addTag(comment.id, 'BEST', user.id);
expect(response.data.removeCommentTag.errors).to.deep.equal([{'translation_key':'NOT_AUTHORIZED'}]);
expect(response.data.removeCommentTag.comment).to.be.null;
const response = await graphql(schema, query, {}, context, {id: comment.id, tag: 'BEST'});
if (response.errors && response.errors.length) {
console.error(response.errors);
}
expect(response.errors).to.be.empty;
expect(response.data.removeCommentTag.errors).to.deep.equal([{'translation_key':'NOT_AUTHORIZED'}]);
expect(response.data.removeCommentTag.comment).to.be.null;
});
});
});
});
+3 -3
View File
@@ -227,8 +227,8 @@ describe('services.CommentsService', () => {
await CommentsService.addTag(commentId, tagName, userId, 'PUBLIC');
const {tags} = await CommentsService.findById(commentId);
expect(tags.length).to.equal(1);
expect(tags[0].name).to.equal(tagName);
expect(tags[0].assigned_by).to.equal(userId);
expect(tags[0].id).to.equal(tagName);
expect(tags[0].added_by).to.equal(userId);
expect(tags[0].created_at).to.be.an.instanceof(Date);
});
it('can\'t add a tag to comment id that doesn\'t exist', async () => {
@@ -238,7 +238,7 @@ describe('services.CommentsService', () => {
await expect(CommentsService.addTag(commentId, tagName, userId, 'PUBLIC')).to.be.rejected;
});
it('can\'t add same tag.name twice', async () => {
it('can\'t add same tag.id twice', async () => {
const commentId = comments[0].id;
const tagName = 'BEST';
const userId = users[0].id;