mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
Test some editComment state transitions
This commit is contained in:
@@ -11,8 +11,9 @@ const CommentsService = require('../../../../services/comments');
|
||||
describe('graph.mutations.editComment', () => {
|
||||
let asset;
|
||||
let user;
|
||||
let settings;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
settings = await SettingsService.init();
|
||||
asset = await AssetModel.create({});
|
||||
user = await UsersService.createLocalUser(
|
||||
'usernameA@example.com', 'password', 'usernameA');
|
||||
@@ -20,6 +21,7 @@ describe('graph.mutations.editComment', () => {
|
||||
afterEach(async () => {
|
||||
await asset.remove();
|
||||
await user.remove();
|
||||
await settings.remove();
|
||||
});
|
||||
|
||||
const editCommentMutation = `
|
||||
@@ -32,15 +34,6 @@ describe('graph.mutations.editComment', () => {
|
||||
}
|
||||
`;
|
||||
|
||||
// const queryCommentById = `
|
||||
// query commentQuery($id: ID!) {
|
||||
// comment(id: $id) {
|
||||
// body,
|
||||
// status
|
||||
// }
|
||||
// }
|
||||
// `;
|
||||
|
||||
it('a user can edit their own comment', async () => {
|
||||
const context = new Context({user});
|
||||
const testStartedAt = new Date();
|
||||
@@ -80,6 +73,108 @@ describe('graph.mutations.editComment', () => {
|
||||
expect(commentAfterEdit.status).to.equal('NONE');
|
||||
});
|
||||
|
||||
const bannedWord = 'BANNED_WORD';
|
||||
[
|
||||
{
|
||||
description: 'premod: editing a REJECTED comment sets back to PREMOD',
|
||||
settings: {
|
||||
moderation: 'PRE',
|
||||
},
|
||||
beforeEdit: {
|
||||
body: 'I was offensive and thus REJECTED',
|
||||
status: 'REJECTED',
|
||||
},
|
||||
edit: {
|
||||
body: 'I have been edited to be less offensive',
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'PREMOD',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'editing an ACCEPTED comment to add a bad word sets status to REJECTED',
|
||||
settings: {
|
||||
moderation: 'POST',
|
||||
wordlist: {
|
||||
banned: [bannedWord]
|
||||
}
|
||||
},
|
||||
beforeEdit: {
|
||||
body: 'I\'m a perfectly acceptable comment',
|
||||
status: 'ACCEPTED',
|
||||
},
|
||||
edit: {
|
||||
body: `I have been sneakily edited to add a banned word: ${bannedWord}`
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'REJECTED',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'postmod: editing a REJECTED comment with banned word to remove banned word sets status to NONE',
|
||||
settings: {
|
||||
moderation: 'POST',
|
||||
wordlist: {
|
||||
banned: [bannedWord]
|
||||
}
|
||||
},
|
||||
beforeEdit: {
|
||||
body: `I'm a rejected comment with bad word ${bannedWord}`,
|
||||
status: 'REJECTED',
|
||||
},
|
||||
edit: {
|
||||
body: 'I have been edited to remove the bad word'
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'NONE',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'postmod + premodLinksEnable: editing an ACCEPTED comment to add a link sets status to PREMOD',
|
||||
settings: {
|
||||
moderation: 'POST',
|
||||
premodLinksEnable: true,
|
||||
},
|
||||
beforeEdit: {
|
||||
body: 'I\'m a perfectly acceptable comment',
|
||||
status: 'ACCEPTED',
|
||||
},
|
||||
edit: {
|
||||
body: 'I have been edited to add a link: https://coralproject.net/'
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'PREMOD',
|
||||
},
|
||||
},
|
||||
].forEach(({description, settings, beforeEdit, edit, afterEdit, only}) => {
|
||||
const test = only ? it.only : it;
|
||||
test(description, async () => {
|
||||
await SettingsService.update(settings);
|
||||
const context = new Context({user});
|
||||
const comment = await CommentsService.publicCreate(Object.assign(
|
||||
{
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
},
|
||||
beforeEdit,
|
||||
));
|
||||
|
||||
// now edit
|
||||
const newBody = edit.body;
|
||||
const response = await graphql(schema, editCommentMutation, {}, context, {
|
||||
id: comment.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
});
|
||||
if (response.errors && response.errors.length) {console.error(response.errors);}
|
||||
expect(response.errors).to.be.empty;
|
||||
const commentAfterEdit = await CommentsService.findById(comment.id);
|
||||
expect(commentAfterEdit.body).to.equal(newBody);
|
||||
expect(commentAfterEdit.status).to.equal(afterEdit.status);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
Server: When an Edit is sent to the server
|
||||
-- The (old) comment.body and (current) timestamp are pushed onto the comment.body_history array.
|
||||
|
||||
Reference in New Issue
Block a user