mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 14:47:33 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const {graphql} = require('graphql');
|
||||
const { graphql } = require('graphql');
|
||||
const timekeeper = require('timekeeper');
|
||||
|
||||
const schema = require('../../../../graph/schema');
|
||||
@@ -8,7 +8,7 @@ const AssetModel = require('../../../../models/asset');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const CommentsService = require('../../../../services/comments');
|
||||
|
||||
const {expect} = require('chai');
|
||||
const { expect } = require('chai');
|
||||
|
||||
describe('graph.mutations.editComment', () => {
|
||||
let asset, user;
|
||||
@@ -16,7 +16,11 @@ describe('graph.mutations.editComment', () => {
|
||||
timekeeper.reset();
|
||||
await SettingsService.init();
|
||||
asset = await AssetModel.create({});
|
||||
user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
user = await UsersService.createLocalUser(
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
);
|
||||
});
|
||||
|
||||
const editCommentMutation = `
|
||||
@@ -30,7 +34,7 @@ describe('graph.mutations.editComment', () => {
|
||||
`;
|
||||
|
||||
it('a user can edit their own comment', async () => {
|
||||
const context = new Context({user});
|
||||
const context = new Context({ user });
|
||||
const testStartedAt = new Date();
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
@@ -50,14 +54,17 @@ describe('graph.mutations.editComment', () => {
|
||||
id: comment.id,
|
||||
asset_id: asset.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
body: newBody,
|
||||
},
|
||||
});
|
||||
if (response.errors && response.errors.length) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
if (response.data.editComment.errors && response.data.editComment.errors.length > 0) {
|
||||
if (
|
||||
response.data.editComment.errors &&
|
||||
response.data.editComment.errors.length > 0
|
||||
) {
|
||||
console.error(response.data.editComment.errors);
|
||||
}
|
||||
expect(response.data.editComment.errors).to.be.null;
|
||||
@@ -69,11 +76,13 @@ describe('graph.mutations.editComment', () => {
|
||||
expect(commentAfterEdit.body_history.length).to.equal(2);
|
||||
expect(commentAfterEdit.body_history[1].body).to.equal(newBody);
|
||||
expect(commentAfterEdit.body_history[1].created_at).to.be.instanceOf(Date);
|
||||
expect(commentAfterEdit.body_history[1].created_at).to.be.at.least(testStartedAt);
|
||||
expect(commentAfterEdit.body_history[1].created_at).to.be.at.least(
|
||||
testStartedAt
|
||||
);
|
||||
expect(commentAfterEdit.status).to.equal('NONE');
|
||||
});
|
||||
|
||||
it('A user can\'t edit their comment outside of the edit comment time window', async () => {
|
||||
it("A user can't edit their comment outside of the edit comment time window", async () => {
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
@@ -85,68 +94,78 @@ describe('graph.mutations.editComment', () => {
|
||||
timekeeper.travel(oneHourFromNow);
|
||||
|
||||
const newBody = 'This body should never be set';
|
||||
const context = new Context({user});
|
||||
const context = new Context({ user });
|
||||
const response = await graphql(schema, editCommentMutation, {}, context, {
|
||||
id: comment.id,
|
||||
asset_id: asset.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
body: newBody,
|
||||
},
|
||||
});
|
||||
if (response.errors && response.errors.length > 0) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
expect(response.data.editComment.errors).to.not.be.empty;
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('EDIT_WINDOW_ENDED');
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal(
|
||||
'EDIT_WINDOW_ENDED'
|
||||
);
|
||||
const commentAfterEdit = await CommentsService.findById(comment.id);
|
||||
|
||||
// it *hasn't* changed from the original
|
||||
expect(commentAfterEdit.body).to.equal(comment.body);
|
||||
});
|
||||
|
||||
it('A user can\'t edit someone else\'s comment', async () => {
|
||||
it("A user can't edit someone else's comment", async () => {
|
||||
const comment = await CommentsService.publicCreate({
|
||||
asset_id: asset.id,
|
||||
author_id: user.id,
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
});
|
||||
|
||||
const userB = await UsersService.createLocalUser('usernameB@example.com', 'password', 'usernameB');
|
||||
const userB = await UsersService.createLocalUser(
|
||||
'usernameB@example.com',
|
||||
'password',
|
||||
'usernameB'
|
||||
);
|
||||
const newBody = 'This body should never be set';
|
||||
const context = new Context({user: userB});
|
||||
const context = new Context({ user: userB });
|
||||
const response = await graphql(schema, editCommentMutation, {}, context, {
|
||||
id: comment.id,
|
||||
asset_id: asset.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
body: newBody,
|
||||
},
|
||||
});
|
||||
expect(response.errors).to.be.empty;
|
||||
expect(response.data.editComment.errors).to.not.be.empty;
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('NOT_AUTHORIZED');
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal(
|
||||
'NOT_AUTHORIZED'
|
||||
);
|
||||
const commentAfterEdit = await CommentsService.findById(comment.id);
|
||||
|
||||
// it *hasn't* changed from the original
|
||||
expect(commentAfterEdit.body).to.equal(comment.body);
|
||||
});
|
||||
|
||||
it('A user Can\'t edit a comment id that doesn\'t exist', async () => {
|
||||
it("A user Can't edit a comment id that doesn't exist", async () => {
|
||||
const fakeCommentId = 'nooooope';
|
||||
const newBody = 'This body should never be set';
|
||||
const context = new Context({user});
|
||||
const context = new Context({ user });
|
||||
const response = await graphql(schema, editCommentMutation, {}, context, {
|
||||
id: fakeCommentId,
|
||||
asset_id: asset.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
body: newBody,
|
||||
},
|
||||
});
|
||||
if (response.errors && response.errors.length > 0) {
|
||||
console.error(response.errors);
|
||||
}
|
||||
expect(response.errors).to.be.empty;
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal('NOT_FOUND');
|
||||
expect(response.data.editComment.errors[0].translation_key).to.equal(
|
||||
'NOT_FOUND'
|
||||
);
|
||||
});
|
||||
|
||||
const bannedWord = 'BANNED_WORD';
|
||||
@@ -163,72 +182,77 @@ describe('graph.mutations.editComment', () => {
|
||||
edit: {
|
||||
body: 'I have been edited to be less offensive',
|
||||
},
|
||||
error: true
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
description: 'editing an ACCEPTED comment to add a bad word sets status to REJECTED',
|
||||
description:
|
||||
'editing an ACCEPTED comment to add a bad word sets status to REJECTED',
|
||||
settings: {
|
||||
moderation: 'POST',
|
||||
wordlist: {
|
||||
banned: [bannedWord]
|
||||
}
|
||||
banned: [bannedWord],
|
||||
},
|
||||
},
|
||||
beforeEdit: {
|
||||
body: 'I\'m a perfectly acceptable comment',
|
||||
body: "I'm a perfectly acceptable comment",
|
||||
status: 'ACCEPTED',
|
||||
},
|
||||
edit: {
|
||||
body: `I have been sneakily edited to add a banned word: ${bannedWord}`
|
||||
body: `I have been sneakily edited to add a banned word: ${bannedWord}`,
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'REJECTED',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'postmod: editing a REJECTED comment with banned word be rejected',
|
||||
description:
|
||||
'postmod: editing a REJECTED comment with banned word be rejected',
|
||||
settings: {
|
||||
moderation: 'POST',
|
||||
wordlist: {
|
||||
banned: [bannedWord]
|
||||
}
|
||||
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'
|
||||
body: 'I have been edited to remove the bad word',
|
||||
},
|
||||
error: true
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
description: 'postmod + premodLinksEnable: editing an ACCEPTED comment to add a link sets status to PREMOD',
|
||||
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',
|
||||
body: "I'm a perfectly acceptable comment",
|
||||
status: 'ACCEPTED',
|
||||
},
|
||||
edit: {
|
||||
body: 'I have been edited to add a link: https://coralproject.net/'
|
||||
body: 'I have been edited to add a link: https://coralproject.net/',
|
||||
},
|
||||
afterEdit: {
|
||||
status: 'SYSTEM_WITHHELD',
|
||||
},
|
||||
},
|
||||
].forEach(({description, settings, beforeEdit, edit, afterEdit, error}) => {
|
||||
].forEach(({ description, settings, beforeEdit, edit, afterEdit, error }) => {
|
||||
it(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
|
||||
));
|
||||
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;
|
||||
@@ -236,14 +260,17 @@ describe('graph.mutations.editComment', () => {
|
||||
id: comment.id,
|
||||
asset_id: asset.id,
|
||||
edit: {
|
||||
body: newBody
|
||||
}
|
||||
body: newBody,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
expect(response.data.editComment.errors).to.not.be.empty;
|
||||
} else {
|
||||
if (response.data.editComment.errors && response.data.editComment.errors.length) {
|
||||
if (
|
||||
response.data.editComment.errors &&
|
||||
response.data.editComment.errors.length
|
||||
) {
|
||||
console.error(response.data.editComment.errors);
|
||||
}
|
||||
expect(response.data.editComment.errors).to.be.null;
|
||||
|
||||
Reference in New Issue
Block a user