diff --git a/test/services/school/services/permissions.test.js b/test/services/school/services/permissions.test.js index 135222a94c4..1709d3bc138 100644 --- a/test/services/school/services/permissions.test.js +++ b/test/services/school/services/permissions.test.js @@ -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; @@ -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'); @@ -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 () => {