mirror of
https://github.com/wassname/talk.git
synced 2026-08-08 11:28:12 +08:00
addCommentTag mutation works
This commit is contained in:
@@ -16,6 +16,7 @@ module.exports = {
|
||||
|
||||
const setBestCommentButton = '@setBestButton';
|
||||
const unsetBestCommentButton = '@unsetBestButton';
|
||||
|
||||
embedStreamPage
|
||||
.postComment('Hi everyone. Isn\'t this the BEST comment!?')
|
||||
.waitForElementVisible(setBestCommentButton, 2000)
|
||||
@@ -25,13 +26,9 @@ module.exports = {
|
||||
});
|
||||
|
||||
// on refresh, it should still be tagged as best :)
|
||||
// client
|
||||
// .refresh(() => {
|
||||
|
||||
// })
|
||||
// .waitForElementVisible(unsetBestCommentButton, 2000)
|
||||
|
||||
// client.pause()
|
||||
client.refresh();
|
||||
client.page.embedStreamPage().ready()
|
||||
.waitForElementVisible('.e2e__unset-best-comment', 2000);
|
||||
},
|
||||
after: client => {
|
||||
client.end();
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
const expect = require('chai').expect;
|
||||
const {graphql} = require('graphql');
|
||||
|
||||
const schema = require('../../../graph/schema');
|
||||
const Context = require('../../../graph/context');
|
||||
const UserModel = require('../../../models/user');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const CommentsService = require('../../../services/comments');
|
||||
|
||||
describe('graph.mutations.addCommentTag', () => {
|
||||
let comment;
|
||||
beforeEach(async () => {
|
||||
SettingsService.init();
|
||||
comment = await CommentsService.publicCreate({body: `hello there! ${ String(Math.random()).slice(2)}`});
|
||||
});
|
||||
|
||||
const query = `
|
||||
mutation AddCommentTag ($id: ID!, $tag: String!) {
|
||||
addCommentTag(id:$id, tag:$tag) {
|
||||
comment {
|
||||
tags {
|
||||
name
|
||||
}
|
||||
}
|
||||
errors {
|
||||
translation_key
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
it('can add tags to comments', async () => {
|
||||
const user = new UserModel({});
|
||||
const context = new Context({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;
|
||||
expect(response.data.addCommentTag.comment.tags).to.deep.equal([{name: 'BEST'}]);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ test/helpers/*.js
|
||||
test
|
||||
--compilers js:babel-core/register
|
||||
--require ignore-styles
|
||||
--require babel-polyfill
|
||||
--recursive
|
||||
--colors
|
||||
--sort
|
||||
|
||||
@@ -8,7 +8,7 @@ const CommentsService = require('../../services/comments');
|
||||
|
||||
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const expect = require('chai').use(require('chai-as-promised')).expect;
|
||||
|
||||
describe('services.CommentsService', () => {
|
||||
const comments = [{
|
||||
@@ -68,6 +68,7 @@ describe('services.CommentsService', () => {
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
id: 'u1',
|
||||
email: 'stampi@gmail.com',
|
||||
username: 'Stampi',
|
||||
password: '1Coral!!'
|
||||
@@ -218,6 +219,50 @@ describe('services.CommentsService', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('#addTag', () => {
|
||||
it('adds a tag', async () => {
|
||||
const commentId = comments[0].id;
|
||||
const tagName = 'BEST';
|
||||
const userId = users[0].id;
|
||||
await CommentsService.addTag(commentId, tagName, userId);
|
||||
const updatedComment = await CommentsService.findById(commentId);
|
||||
expect(updatedComment.tags.length).to.equal(1);
|
||||
expect(updatedComment.tags[0].name).to.equal(tagName);
|
||||
expect(updatedComment.tags[0].assigned_by).to.equal(userId);
|
||||
expect(updatedComment.tags[0].created_at).to.be.an.instanceof(Date);
|
||||
});
|
||||
it('can\'t add a tag to comment id that doesn\'t exist', async () => {
|
||||
const commentId = 'fakenews';
|
||||
const tagName = 'BEST';
|
||||
const userId = users[0].id;
|
||||
await expect(CommentsService.addTag(commentId, tagName, userId)).to.be.rejected;
|
||||
});
|
||||
it('can\'t add same tag.name twice', async () => {
|
||||
const commentId = comments[0].id;
|
||||
const tagName = 'BEST';
|
||||
const userId = users[0].id;
|
||||
|
||||
// first time
|
||||
await CommentsService.addTag(commentId, tagName, userId);
|
||||
|
||||
// second time should fail
|
||||
await expect(CommentsService.addTag(commentId, tagName, userId)).to.be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeTag', () => {
|
||||
it.skip('removes a tag', async () => {
|
||||
const commentId = comments[0].id;
|
||||
const tagName = 'BEST';
|
||||
await CommentsService.addTag(commentId, tagName, users[0].id);
|
||||
let updatedComment = await CommentsService.findById(commentId);
|
||||
expect(updatedComment.tags.length).to.equal(1);
|
||||
|
||||
// ok now to remove it
|
||||
await CommentsService.removeTag(commentId, tagName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#changeStatus', () => {
|
||||
|
||||
it('should change the status of a comment from no status', () => {
|
||||
|
||||
Reference in New Issue
Block a user