mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
added message to ban/suspend workflows
This commit is contained in:
@@ -5,10 +5,14 @@ const Context = require('../../../../graph/context');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const UserModel = require('../../../../models/user');
|
||||
const UsersService = require('../../../../services/users');
|
||||
const MailerService = require('../../../../services/mailer');
|
||||
|
||||
const {expect} = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const chai = require('chai');
|
||||
chai.use(require('sinon-chai'));
|
||||
const {expect} = chai;
|
||||
|
||||
describe('graph.mutations.setUserBanStatus', () => {
|
||||
describe('graph.mutations.banUser', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
@@ -16,11 +20,34 @@ describe('graph.mutations.setUserBanStatus', () => {
|
||||
user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
});
|
||||
|
||||
const setUserBanStatusMutation = `
|
||||
mutation SetUserBanStatus($user_id: ID!, $status: Boolean!) {
|
||||
setUserBanStatus(input: {
|
||||
let spy;
|
||||
before(() => {
|
||||
spy = sinon.spy(MailerService, 'sendSimple');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
spy.reset();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
spy.restore();
|
||||
});
|
||||
|
||||
const banUserMutation = `
|
||||
mutation BanUser($user_id: ID!, $message: String!) {
|
||||
banUser(input: {
|
||||
id: $user_id,
|
||||
status: $status
|
||||
message: $message
|
||||
}) {
|
||||
errors {
|
||||
translation_key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation UnBanUser($user_id: ID!) {
|
||||
unBanUser(input: {
|
||||
id: $user_id
|
||||
}) {
|
||||
errors {
|
||||
translation_key
|
||||
@@ -51,40 +78,42 @@ describe('graph.mutations.setUserBanStatus', () => {
|
||||
|
||||
const ctx = new Context({user: actor});
|
||||
|
||||
const {data, errors} = await graphql(schema, setUserBanStatusMutation, {}, ctx, {
|
||||
const {data, errors} = await graphql(schema, banUserMutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
status: true
|
||||
});
|
||||
message: 'This is a message'
|
||||
}, 'BanUser');
|
||||
|
||||
if (errors && errors.length > 0) {
|
||||
console.error(errors);
|
||||
}
|
||||
expect(errors).to.be.undefined;
|
||||
if (error) {
|
||||
expect(data.setUserBanStatus).to.have.property('errors').not.null;
|
||||
expect(data.setUserBanStatus.errors[0]).to.have.property('translation_key', error);
|
||||
expect(data.banUser).to.have.property('errors').not.null;
|
||||
expect(data.banUser.errors[0]).to.have.property('translation_key', error);
|
||||
} else {
|
||||
expect(data.setUserBanStatus).to.be.null;
|
||||
expect(data.banUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
|
||||
expect(user.status.banned.status).to.be.true;
|
||||
expect(user.status.banned.history).to.have.length(1);
|
||||
expect(user.status.banned.history[0]).to.have.property('status', true);
|
||||
expect(user.status.banned.history[0]).to.have.property('message', 'This is a message');
|
||||
expect(user.status.banned.history[0]).to.have.property('assigned_by', actor.id);
|
||||
expect(user.status.banned.history[0]).to.have.property('created_at').not.null;
|
||||
|
||||
expect(user.banned).to.be.true;
|
||||
|
||||
const res = await graphql(schema, setUserBanStatusMutation, {}, ctx, {
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
|
||||
const res = await graphql(schema, banUserMutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
status: false
|
||||
});
|
||||
}, 'UnBanUser');
|
||||
if (res.errors && res.errors.length > 0) {
|
||||
console.error(res.errors);
|
||||
}
|
||||
expect(res.errors).to.be.undefined;
|
||||
expect(res.data.setUserBanStatus).to.be.null;
|
||||
expect(res.data.unBanUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@ const Context = require('../../../../graph/context');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const UserModel = require('../../../../models/user');
|
||||
const UsersService = require('../../../../services/users');
|
||||
const MailerService = require('../../../../services/mailer');
|
||||
|
||||
const sinon = require('sinon');
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-datetime'));
|
||||
chai.use(require('sinon-chai'));
|
||||
const {expect} = chai;
|
||||
|
||||
describe('graph.mutations.setUserSuspensionStatus', () => {
|
||||
describe('graph.mutations.suspendUser', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
@@ -19,11 +22,35 @@ describe('graph.mutations.setUserSuspensionStatus', () => {
|
||||
user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
});
|
||||
|
||||
const setUserSuspensionStatusMutation = `
|
||||
mutation SetUserUsernameStatus($user_id: ID!, $until: Date) {
|
||||
setUserSuspensionStatus(input: {
|
||||
let spy;
|
||||
before(() => {
|
||||
spy = sinon.spy(MailerService, 'sendSimple');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
spy.reset();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
spy.restore();
|
||||
});
|
||||
|
||||
const mutation = `
|
||||
mutation SuspendUser($user_id: ID!, $until: Date!, $message: String!) {
|
||||
suspendUser(input: {
|
||||
id: $user_id,
|
||||
until: $until,
|
||||
message: $message,
|
||||
}) {
|
||||
errors {
|
||||
translation_key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation UnSuspendUser($user_id: ID!) {
|
||||
unSuspendUser(input: {
|
||||
id: $user_id,
|
||||
until: $until
|
||||
}) {
|
||||
errors {
|
||||
translation_key
|
||||
@@ -57,20 +84,21 @@ describe('graph.mutations.setUserSuspensionStatus', () => {
|
||||
const now = new Date();
|
||||
const oneHourFromNow = new Date(new Date(now).setHours(now.getHours() + 1));
|
||||
|
||||
const {data, errors} = await graphql(schema, setUserSuspensionStatusMutation, {}, ctx, {
|
||||
const {data, errors} = await graphql(schema, mutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
until: oneHourFromNow
|
||||
});
|
||||
until: oneHourFromNow,
|
||||
message: 'This is a message'
|
||||
}, 'SuspendUser');
|
||||
|
||||
if (errors && errors.length > 0) {
|
||||
console.error(errors);
|
||||
}
|
||||
expect(errors).to.be.undefined;
|
||||
if (error) {
|
||||
expect(data.setUserSuspensionStatus).to.have.property('errors').not.null;
|
||||
expect(data.setUserSuspensionStatus.errors[0]).to.have.property('translation_key', error);
|
||||
expect(data.suspendUser).to.have.property('errors').not.null;
|
||||
expect(data.suspendUser.errors[0]).to.have.property('translation_key', error);
|
||||
} else {
|
||||
expect(data.setUserSuspensionStatus).to.be.null;
|
||||
expect(data.suspendUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
|
||||
@@ -79,6 +107,7 @@ describe('graph.mutations.setUserSuspensionStatus', () => {
|
||||
expect(user.status.suspension.history).to.have.length(1);
|
||||
expect(user.status.suspension.history[0]).to.have.property('until').to.be.withinTime(new Date(oneHourFromNow.getTime() - 1000), new Date(oneHourFromNow.getTime() + 1000));
|
||||
expect(user.status.suspension.history[0]).to.have.property('assigned_by', actor.id);
|
||||
expect(user.status.suspension.history[0]).to.have.property('message', 'This is a message');
|
||||
expect(user.status.suspension.history[0]).to.have.property('created_at').not.null;
|
||||
|
||||
expect(user.suspended).to.be.true;
|
||||
@@ -86,15 +115,17 @@ describe('graph.mutations.setUserSuspensionStatus', () => {
|
||||
expect(user.suspended).to.be.false;
|
||||
timekeeper.reset();
|
||||
|
||||
const res = await graphql(schema, setUserSuspensionStatusMutation, {}, ctx, {
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
|
||||
const res = await graphql(schema, mutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
until: null
|
||||
});
|
||||
}, 'UnSuspendUser');
|
||||
if (res.errors && res.errors.length > 0) {
|
||||
console.error(res.errors);
|
||||
}
|
||||
expect(res.errors).to.be.undefined;
|
||||
expect(res.data.setUserSuspensionStatus).to.be.null;
|
||||
expect(res.data.unSuspendUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user