Merge branch 'master' into user-sort

Conflicts:
	client/coral-admin/src/reducers/moderation.js
	client/coral-embed-stream/src/actions/stream.js
	client/coral-embed-stream/src/components/Stream.js
	client/coral-framework/components/Slot.js
	plugin-api/beta/client/utils/index.js
	test/server/routes/api/account/index.js
This commit is contained in:
Chi Vinh Le
2017-08-25 21:55:00 +07:00
91 changed files with 1499 additions and 1222 deletions
+26 -39
View File
@@ -2,6 +2,7 @@ const passport = require('../../../passport');
const app = require('../../../../../app');
const UsersService = require('../../../../../services/users');
const SettingsService = require('../../../../../services/settings');
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
@@ -10,61 +11,47 @@ chai.should();
chai.use(require('chai-http'));
const expect = chai.expect;
const UsersService = require('../../../../../services/users');
describe('/api/v1/account/username', () => {
let mockUser;
beforeEach(() => SettingsService.init(settings).then(() => {
return UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
})
.then((user) => {
mockUser = user;
}));
beforeEach(async () => {
await SettingsService.init(settings);
mockUser = await UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
});
describe('#put', () => {
it('it should enable a user to edit their username if canEditName is enabled', () => {
return chai.request(app)
it('it should enable a user to edit their username if canEditName is enabled', async () => {
await chai.request(app)
.post(`/api/v1/users/${mockUser.id}/username-enable`)
.set(passport.inject({id: '456', roles: ['ADMIN']}))
.then(() => chai.request(app)
.set(passport.inject({id: '456', roles: ['ADMIN']}));
const res = await chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: mockUser.id, roles: []}))
.send({username: 'MojoJojo'}))
.then((res) => {
expect(res).to.have.status(204);
});
.send({username: 'MojoJojo'});
expect(res).to.have.status(204);
});
it('it should return an error if the wrong user tries to edit a username', (done) => {
chai.request(app)
it('it should return an error if the wrong user tries to edit a username', async () => {
await chai.request(app)
.post(`/api/v1/users/${mockUser.id}/username-enable`)
.set(passport.inject({id: '456', roles: ['ADMIN']}))
.then(() => chai.request(app)
.set(passport.inject({id: '456', roles: ['ADMIN']}));
let res = chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: 'wrongid', roles: []}))
.send({username: 'MojoJojo'}))
.then(() => {
done(new Error('Expected Error'));
})
.catch((err) => {
expect(err).to.be.ok;
done();
});
.send({username: 'MojoJojo'});
return expect(res).to.eventually.be.rejected;
});
it('it should return an error when the user tries to edit their username if canEditName is disabled', (done) => {
chai.request(app)
it('it should return an error when the user tries to edit their username if canEditName is disabled', () => {
let res = chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: mockUser.id, roles: []}))
.send({username: 'MojoJojo'})
.then(() => {
done(new Error('Expected Error'));
})
.catch((err) => {
expect(err).to.be.ok;
done();
});
.send({username: 'MojoJojo'});
return expect(res).to.eventually.be.rejected;
});
});
});