mirror of
https://github.com/wassname/talk.git
synced 2026-08-05 13:30:26 +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 schema = require('../../../../graph/schema');
|
||||
const Context = require('../../../../graph/context');
|
||||
@@ -10,14 +10,18 @@ const mailer = require('../../../../services/mailer');
|
||||
const sinon = require('sinon');
|
||||
const chai = require('chai');
|
||||
chai.use(require('sinon-chai'));
|
||||
const {expect} = chai;
|
||||
const { expect } = chai;
|
||||
|
||||
describe('graph.mutations.banUser', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
|
||||
user = await UsersService.createLocalUser(
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
);
|
||||
});
|
||||
|
||||
let spy;
|
||||
@@ -57,17 +61,19 @@ describe('graph.mutations.banUser', () => {
|
||||
`;
|
||||
|
||||
[
|
||||
{self: true, error: 'NOT_AUTHORIZED', role: 'COMMENTER'},
|
||||
{self: true, error: 'NOT_AUTHORIZED', role: 'STAFF'},
|
||||
{self: true, error: 'NOT_AUTHORIZED', role: 'COMMENTER'},
|
||||
{error: 'NOT_AUTHORIZED', role: 'COMMENTER'},
|
||||
{error: 'NOT_AUTHORIZED', role: 'STAFF'},
|
||||
{error: 'NOT_AUTHORIZED', role: 'COMMENTER'},
|
||||
{error: false, role: 'MODERATOR'},
|
||||
{error: false, role: 'ADMIN'},
|
||||
].forEach(({self, error, role}) => {
|
||||
it(`${error ? 'can not' : 'can'} ban ${self ? 'themself' : 'another user'} as a user with role=${role}`, async () => {
|
||||
const actor = new UserModel({role});
|
||||
{ self: true, error: 'NOT_AUTHORIZED', role: 'COMMENTER' },
|
||||
{ self: true, error: 'NOT_AUTHORIZED', role: 'STAFF' },
|
||||
{ self: true, error: 'NOT_AUTHORIZED', role: 'COMMENTER' },
|
||||
{ error: 'NOT_AUTHORIZED', role: 'COMMENTER' },
|
||||
{ error: 'NOT_AUTHORIZED', role: 'STAFF' },
|
||||
{ error: 'NOT_AUTHORIZED', role: 'COMMENTER' },
|
||||
{ error: false, role: 'MODERATOR' },
|
||||
{ error: false, role: 'ADMIN' },
|
||||
].forEach(({ self, error, role }) => {
|
||||
it(`${error ? 'can not' : 'can'} ban ${
|
||||
self ? 'themself' : 'another user'
|
||||
} as a user with role=${role}`, async () => {
|
||||
const actor = new UserModel({ role });
|
||||
|
||||
// If we're testing self assign, set the id of the actor to the user
|
||||
// we're acting on.
|
||||
@@ -75,12 +81,19 @@ describe('graph.mutations.banUser', () => {
|
||||
actor.id = user.id;
|
||||
}
|
||||
|
||||
const ctx = new Context({user: actor});
|
||||
const ctx = new Context({ user: actor });
|
||||
|
||||
const {data, errors} = await graphql(schema, banUserMutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
message: 'This is a message'
|
||||
}, 'BanUser');
|
||||
const { data, errors } = await graphql(
|
||||
schema,
|
||||
banUserMutation,
|
||||
{},
|
||||
ctx,
|
||||
{
|
||||
user_id: user.id,
|
||||
message: 'This is a message',
|
||||
},
|
||||
'BanUser'
|
||||
);
|
||||
|
||||
if (errors && errors.length > 0) {
|
||||
console.error(errors);
|
||||
@@ -88,42 +101,69 @@ describe('graph.mutations.banUser', () => {
|
||||
expect(errors).to.be.undefined;
|
||||
if (error) {
|
||||
expect(data.banUser).to.have.property('errors').not.null;
|
||||
expect(data.banUser.errors[0]).to.have.property('translation_key', error);
|
||||
expect(data.banUser.errors[0]).to.have.property(
|
||||
'translation_key',
|
||||
error
|
||||
);
|
||||
} else {
|
||||
expect(data.banUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
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.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;
|
||||
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
|
||||
const res = await graphql(schema, banUserMutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
}, 'UnBanUser');
|
||||
const res = await graphql(
|
||||
schema,
|
||||
banUserMutation,
|
||||
{},
|
||||
ctx,
|
||||
{
|
||||
user_id: user.id,
|
||||
},
|
||||
'UnBanUser'
|
||||
);
|
||||
if (res.errors && res.errors.length > 0) {
|
||||
console.error(res.errors);
|
||||
}
|
||||
expect(res.errors).to.be.undefined;
|
||||
expect(res.data.unbanUser).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
user = await UserModel.findOne({ id: user.id });
|
||||
|
||||
expect(user.status.banned.status).to.be.false;
|
||||
expect(user.status.banned.history).to.have.length(2);
|
||||
expect(user.status.banned.history[0]).to.have.property('status').to.be.true;
|
||||
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.status.banned.history[1]).to.have.property('status').to.be.false;
|
||||
expect(user.status.banned.history[1]).to.have.property('assigned_by', actor.id);
|
||||
expect(user.status.banned.history[1]).to.have.property('created_at').not.null;
|
||||
expect(user.status.banned.history[0]).to.have.property('status').to.be
|
||||
.true;
|
||||
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.status.banned.history[1]).to.have.property('status').to.be
|
||||
.false;
|
||||
expect(user.status.banned.history[1]).to.have.property(
|
||||
'assigned_by',
|
||||
actor.id
|
||||
);
|
||||
expect(user.status.banned.history[1]).to.have.property('created_at').not
|
||||
.null;
|
||||
|
||||
expect(user.banned).to.be.false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user