Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1236 toggle ldap sync extension #4373

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export class UserLoginMigrationService {

const savedMigration: UserLoginMigrationDO = await this.userLoginMigrationRepo.save(userLoginMigration);

// userLoginMigration throws an error when saved, if this codeblock runs before the userLoginMigrationRepo.save method.
IgorCapCoder marked this conversation as resolved.
Show resolved Hide resolved
if (oauthMigrationFinished !== undefined) {
await this.schoolService.removeFeature(schoolId, SchoolFeatures.ENABLE_LDAP_SYNC_DURING_MIGRATION);
}

return savedMigration;
}

Expand Down Expand Up @@ -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;

Expand Down
Loading