Skip to content

Commit

Permalink
N21-2022 adds api test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns committed Jun 21, 2024
1 parent a13f04f commit 601ca75
Showing 1 changed file with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { ServerTestModule } from '@modules/server';
import { HttpStatus, INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { SchoolEntity, SystemEntity, User } from '@shared/domain/entity';
import { ImportUser, SchoolEntity, SystemEntity, User } from '@shared/domain/entity';
import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import {
cleanupCollections,
importUserFactory,
JwtTestFactory,
schoolEntityFactory,
systemEntityFactory,
Expand Down Expand Up @@ -1342,5 +1343,65 @@ describe('UserLoginMigrationController (API)', () => {
expect(response.body).toEqual({});
});
});

describe('when the migration wizard is also running', () => {
const setup = async () => {
const sourceSystem: SystemEntity = systemEntityFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' });
const targetSystem: SystemEntity = systemEntityFactory.withOauthConfig().buildWithId({ alias: 'SANIS' });
const school: SchoolEntity = schoolEntityFactory.buildWithId({
systems: [sourceSystem],
officialSchoolNumber: '12345',
inUserMigration: true,
inMaintenanceSince: new Date(2024, 1, 4),
});
const importUser = importUserFactory.build({ school });
const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({
school,
targetSystem,
sourceSystem,
startedAt: new Date(2023, 1, 4),
});

const migratedUser: User = userFactory.buildWithId({
lastLoginSystemChange: new Date(2023, 1, 5),
});

const { adminAccount, adminUser } = UserAndAccountTestFactory.buildAdmin({ school });

await em.persistAndFlush([
sourceSystem,
targetSystem,
school,
adminAccount,
adminUser,
userLoginMigration,
migratedUser,
importUser,
]);
em.clear();

const loggedInClient = await testApiClient.login(adminAccount);

return {
loggedInClient,
userLoginMigration,
adminUser,
};
};

it('should close migration wizard', async () => {
const { loggedInClient, adminUser } = await setup();

await loggedInClient.post('/close');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [entities, count] = await em.findAndCount(ImportUser, {});
expect(count).toEqual(0);

const school = await em.findOneOrFail(SchoolEntity, { id: adminUser.school.id });
expect(school.inUserMigration).toBe(undefined);
expect(school.inMaintenanceSince).toBe(undefined);
});
});
});
});

0 comments on commit 601ca75

Please sign in to comment.