2018-10-09 17:00:08 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2018-10-09 17:00:08 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
|
|
|
|
describe('Roles API', function () {
|
|
|
|
let request;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(() => {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return localUtils.doAuth(request, 'posts');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('Can request all roles', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('roles/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const response = res.body;
|
|
|
|
should.exist(response);
|
|
|
|
should.exist(response.roles);
|
|
|
|
localUtils.API.checkResponse(response, 'roles');
|
2019-07-31 23:34:49 +03:00
|
|
|
response.roles.should.have.length(8);
|
2019-02-04 17:16:24 +03:00
|
|
|
localUtils.API.checkResponse(response.roles[0], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[1], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[2], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[3], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[4], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[5], 'role');
|
2019-08-02 12:28:02 +03:00
|
|
|
localUtils.API.checkResponse(response.roles[6], 'role');
|
2019-07-31 23:34:49 +03:00
|
|
|
localUtils.API.checkResponse(response.roles[7], 'role');
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('Can request roles which i am able to assign to other users', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('roles/?permissions=assign'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const response = res.body;
|
|
|
|
should.exist(response.roles);
|
|
|
|
localUtils.API.checkResponse(response, 'roles');
|
|
|
|
response.roles.should.have.length(4);
|
|
|
|
localUtils.API.checkResponse(response.roles[0], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[1], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[2], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[3], 'role');
|
|
|
|
response.roles[0].name.should.equal('Administrator');
|
|
|
|
response.roles[1].name.should.equal('Editor');
|
|
|
|
response.roles[2].name.should.equal('Author');
|
|
|
|
response.roles[3].name.should.equal('Contributor');
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
done();
|
|
|
|
});
|
2018-10-09 17:00:08 +03:00
|
|
|
});
|
|
|
|
});
|