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');
|
|
|
|
|
|
|
|
describe('Roles API', function () {
|
|
|
|
let request;
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
2021-11-18 11:55:35 +03:00
|
|
|
await localUtils.startGhost();
|
2020-11-30 17:25:22 +03:00
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await localUtils.doAuth(request, 'posts');
|
2018-10-09 17:00:08 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request all roles', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('roles/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const response = res.body;
|
|
|
|
should.exist(response);
|
|
|
|
should.exist(response.roles);
|
|
|
|
localUtils.API.checkResponse(response, 'roles');
|
2023-03-21 22:40:45 +03:00
|
|
|
response.roles.should.have.length(10);
|
2020-11-30 17:25:22 +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');
|
|
|
|
localUtils.API.checkResponse(response.roles[6], 'role');
|
|
|
|
localUtils.API.checkResponse(response.roles[7], 'role');
|
2022-07-08 10:55:58 +03:00
|
|
|
localUtils.API.checkResponse(response.roles[8], 'role');
|
2023-03-21 22:40:45 +03:00
|
|
|
localUtils.API.checkResponse(response.roles[9], 'role');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-09 17:00:08 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request roles which i am able to assign to other users', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('roles/?permissions=assign'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|