mirror of
https://github.com/wassname/talk.git
synced 2026-08-08 11:28:12 +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');
|
||||
@@ -8,18 +8,22 @@ const UsersService = require('../../../../services/users');
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-datetime'));
|
||||
const {expect} = chai;
|
||||
const { expect } = chai;
|
||||
|
||||
[
|
||||
{status: 'APPROVED', name: 'approve', mutation: 'approveUsername'},
|
||||
{status: 'REJECTED', name: 'reject', mutation: 'rejectUsername'}
|
||||
].forEach(({status, name, mutation}) => {
|
||||
{ status: 'APPROVED', name: 'approve', mutation: 'approveUsername' },
|
||||
{ status: 'REJECTED', name: 'reject', mutation: 'rejectUsername' },
|
||||
].forEach(({ status, name, mutation }) => {
|
||||
describe(`graph.mutations.${mutation}`, () => {
|
||||
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'
|
||||
);
|
||||
});
|
||||
|
||||
const setUserUsernameStatusMutation = `
|
||||
@@ -33,17 +37,21 @@ const {expect} = chai;
|
||||
`;
|
||||
|
||||
[
|
||||
{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'} ${name} a username with the user role ${role}${self ? ' on themself' : ''}`, 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'
|
||||
} ${name} a username with the user role ${role}${
|
||||
self ? ' on themself' : ''
|
||||
}`, 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.
|
||||
@@ -51,11 +59,17 @@ const {expect} = chai;
|
||||
actor.id = user.id;
|
||||
}
|
||||
|
||||
const ctx = new Context({user: actor});
|
||||
const ctx = new Context({ user: actor });
|
||||
|
||||
const {data, errors} = await graphql(schema, setUserUsernameStatusMutation, {}, ctx, {
|
||||
user_id: user.id,
|
||||
});
|
||||
const { data, errors } = await graphql(
|
||||
schema,
|
||||
setUserUsernameStatusMutation,
|
||||
{},
|
||||
ctx,
|
||||
{
|
||||
user_id: user.id,
|
||||
}
|
||||
);
|
||||
|
||||
if (errors && errors.length > 0) {
|
||||
console.error(errors);
|
||||
@@ -63,22 +77,40 @@ const {expect} = chai;
|
||||
expect(errors).to.be.undefined;
|
||||
if (error) {
|
||||
expect(data[mutation]).to.have.property('errors').not.null;
|
||||
expect(data[mutation].errors[0]).to.have.property('translation_key', error);
|
||||
expect(data[mutation].errors[0]).to.have.property(
|
||||
'translation_key',
|
||||
error
|
||||
);
|
||||
} else {
|
||||
expect(data[mutation]).to.be.null;
|
||||
|
||||
user = await UserModel.findOne({id: user.id});
|
||||
user = await UserModel.findOne({ id: user.id });
|
||||
|
||||
expect(user.status.username.status).to.equal(status);
|
||||
expect(user.status.username.history).to.have.length(2);
|
||||
expect(user.status.username.history[0]).to.have.property('status', 'SET');
|
||||
expect(user.status.username.history[0]).to.have.property('assigned_by').is.null;
|
||||
expect(user.status.username.history[0]).to.have.property('created_at').not.null;
|
||||
expect(user.status.username.history[1]).to.have.property('status', status);
|
||||
expect(user.status.username.history[1]).to.have.property('assigned_by', actor.id);
|
||||
expect(user.status.username.history[1]).to.have.property('created_at').not.null;
|
||||
expect(user.status.username.history[0]).to.have.property(
|
||||
'status',
|
||||
'SET'
|
||||
);
|
||||
expect(user.status.username.history[0]).to.have.property(
|
||||
'assigned_by'
|
||||
).is.null;
|
||||
expect(user.status.username.history[0]).to.have.property('created_at')
|
||||
.not.null;
|
||||
expect(user.status.username.history[1]).to.have.property(
|
||||
'status',
|
||||
status
|
||||
);
|
||||
expect(user.status.username.history[1]).to.have.property(
|
||||
'assigned_by',
|
||||
actor.id
|
||||
);
|
||||
expect(user.status.username.history[1]).to.have.property('created_at')
|
||||
.not.null;
|
||||
|
||||
expect(user.status.username.history[1].created_at).afterTime(user.status.username.history[0].created_at);
|
||||
expect(user.status.username.history[1].created_at).afterTime(
|
||||
user.status.username.history[0].created_at
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user