diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts index 4b71bcd939e..44d402fa46f 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts @@ -531,6 +531,17 @@ describe('UserLoginMigrationService', () => { }; }; + it('should call schoolService.removeFeature', async () => { + const { schoolId } = setup(); + + await service.setMigration(schoolId, undefined, undefined, true); + + expect(schoolService.removeFeature).toHaveBeenCalledWith( + schoolId, + SchoolFeatures.ENABLE_LDAP_SYNC_DURING_MIGRATION + ); + }); + it('should save the UserLoginMigration with close date and finish date', async () => { const { schoolId, userLoginMigration } = setup(); const expected: UserLoginMigrationDO = userLoginMigrationDOFactory.buildWithId({ @@ -792,76 +803,6 @@ describe('UserLoginMigrationService', () => { }); }); - describe('restartMigration', () => { - describe('when migration restart was successfully', () => { - const setup = () => { - const schoolId: EntityId = new ObjectId().toHexString(); - - const targetSystemId: EntityId = new ObjectId().toHexString(); - - const userLoginMigrationDO: UserLoginMigrationDO = userLoginMigrationDOFactory.buildWithId({ - targetSystemId, - schoolId, - startedAt: mockedDate, - }); - userLoginMigrationRepo.findBySchoolId.mockResolvedValue(userLoginMigrationDO); - schoolMigrationService.unmarkOutdatedUsers.mockResolvedValue(); - userLoginMigrationRepo.save.mockResolvedValue(userLoginMigrationDO); - - return { - schoolId, - targetSystemId, - userLoginMigrationDO, - }; - }; - - it('should call save the user login migration', async () => { - const { schoolId, userLoginMigrationDO } = setup(); - - await service.restartMigration(schoolId); - - expect(userLoginMigrationRepo.save).toHaveBeenCalledWith(userLoginMigrationDO); - }); - - it('should call unmark the outdated users from this migration', async () => { - const { schoolId } = setup(); - - await service.restartMigration(schoolId); - - expect(schoolMigrationService.unmarkOutdatedUsers).toHaveBeenCalledWith(schoolId); - }); - }); - - describe('when migration could not be found', () => { - const setup = () => { - const schoolId: EntityId = new ObjectId().toHexString(); - - const targetSystemId: EntityId = new ObjectId().toHexString(); - - const userLoginMigrationDO: UserLoginMigrationDO = userLoginMigrationDOFactory.buildWithId({ - targetSystemId, - schoolId, - startedAt: mockedDate, - }); - userLoginMigrationRepo.findBySchoolId.mockResolvedValue(null); - - return { - schoolId, - targetSystemId, - userLoginMigrationDO, - }; - }; - - it('should throw ModifyUserLoginMigrationLoggableException ', async () => { - const { schoolId } = setup(); - - const func = async () => service.restartMigration(schoolId); - - await expect(func).rejects.toThrow(UserLoginMigrationNotFoundLoggableException); - }); - }); - }); - describe('deleteUserLoginMigration', () => { describe('when a userLoginMigration is given', () => { const setup = () => { @@ -1075,6 +1016,17 @@ describe('UserLoginMigrationService', () => { }; }; + it('should call schoolService.removeFeature', async () => { + const { schoolId } = setup(); + + await service.closeMigration(schoolId); + + expect(schoolService.removeFeature).toHaveBeenCalledWith( + schoolId, + SchoolFeatures.ENABLE_LDAP_SYNC_DURING_MIGRATION + ); + }); + it('should save the closed user login migration', async () => { const { schoolId, closedUserLoginMigration } = setup(); diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts index 2808775a653..1f48b814247 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts @@ -71,6 +71,11 @@ export class UserLoginMigrationService { const savedMigration: UserLoginMigrationDO = await this.userLoginMigrationRepo.save(userLoginMigration); + if (oauthMigrationFinished !== undefined) { + // this would throw an error when executed before the userLoginMigrationRepo.save method. + await this.schoolService.removeFeature(schoolId, SchoolFeatures.ENABLE_LDAP_SYNC_DURING_MIGRATION); + } + return savedMigration; } @@ -128,6 +133,8 @@ export class UserLoginMigrationService { throw new UserLoginMigrationNotFoundLoggableException(schoolId); } + await this.schoolService.removeFeature(schoolId, SchoolFeatures.ENABLE_LDAP_SYNC_DURING_MIGRATION); + const now: Date = new Date(); const gracePeriodDuration: number = Configuration.get('MIGRATION_END_GRACE_PERIOD_MS') as number;