Skip to content

Commit

Permalink
fix permission tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Nov 22, 2023
1 parent 442d3ce commit d52b031
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions test/services/school/services/permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ const { Configuration } = require('@hpi-schul-cloud/commons');
const appPromise = require('../../../../src/app');
const { setupNestServices, closeNestServices } = require('../../../utils/setup.nest.services');
const schoolServices = require('../../../../src/services/school/index');
const testObjects = require('../../helpers/testObjects');
const testObjects = require('../../helpers/testObjects')(appPromise());

describe('permissons service', () => {
let app;
let server;
let testHelper;
let testSchool;
let testUser;
let testParams;
Expand All @@ -17,36 +16,48 @@ describe('permissons service', () => {
before(async () => {
app = await appPromise();
nestServices = await setupNestServices(app);
testHelper = testObjects(appPromise());
server = await app.listen(0);
testSchool = await testHelper.createTestSchool();
testUser = await testHelper.createTestUser({ schoolId: testSchool._id, roles: ['administrator'] });
testParams = await testHelper.generateRequestParamsFromUser(testUser);
testParams.query = {};
});

beforeEach(() => {
delete app.services['school/student/studentlernstorevisibility'];
delete app.services['school/teacher/studentvisibility'];
});

after(async () => {
await testHelper.cleanup();
await server.close();
await closeNestServices(nestServices);
await server.close();
});

beforeEach(async () => {
testSchool = await testObjects.createTestSchool();
testUser = await testObjects.createTestUser({ schoolId: testSchool._id, roles: ['administrator'] });
testParams = await testObjects.generateRequestParamsFromUser(testUser);
testParams.query = {};

app.unuse('schools');
app.unuse('schools/api');
app.unuse('/schools/:schoolId/maintenance');
app.unuse('schoolsList');
app.unuse('schoolsList/api');
app.unuse('schoolGroup');
app.unuse('gradeLevels');
app.unuse('/school/teacher/studentvisibility');
app.unuse('/school/student/studentlernstorevisibility');
});
afterEach(async () => {
await testObjects.cleanup();
});

describe('for STUDENT_LIST permission', () => {
it('is not registered if TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE is false', async () => {
Configuration.set('TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE', 'false');
app.configure(schoolServices);

const service = app.service('/school/teacher/studentvisibility');
expect(service).to.be.undefined;
try {
const service = app.service('/school/teacher/studentvisibility');
throw new Error('service should not be registered');
} catch (error) {
expect(error.message).to.equal(`Can not find service 'school/teacher/studentvisibility'`);
}
});

it('changes the STUDENT_LIST permission if TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE is true', async () => {
Configuration.set('TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE', 'true');

app.configure(schoolServices);

const service = app.service('/school/teacher/studentvisibility');
Expand All @@ -67,8 +78,12 @@ describe('permissons service', () => {
Configuration.set('FEATURE_ADMIN_TOGGLE_STUDENT_LERNSTORE_VIEW_ENABLED', 'false');
app.configure(schoolServices);

const service = app.service('/school/student/studentlernstorevisibility');
expect(service).to.be.undefined;
try {
const service = app.service('/school/student/studentlernstorevisibility');
throw new Error('service should not be registered');
} catch (error) {
expect(error.message).to.equal(`Can not find service 'school/student/studentlernstorevisibility'`);
}
});

it('changes the LERNSTORE_VIEW permission if FEATURE_ADMIN_TOGGLE_STUDENT_LERNSTORE_VIEW_ENABLED is true', async () => {
Expand Down

0 comments on commit d52b031

Please sign in to comment.