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

EW-1053 Add and use Test Factories For TSP #5369

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f840ab4
Add and use Test Factories
MajedAlaitwniCap Nov 29, 2024
2676f20
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 2, 2024
6184e18
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 2, 2024
4e0f4e2
revert ExternalSchoolDto changes
MajedAlaitwniCap Dec 2, 2024
22b41cb
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 3, 2024
6e3a643
add and use factories for robj export models
MajedAlaitwniCap Dec 4, 2024
02cb706
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 4, 2024
e4aa8a3
add robj-export-schueler-migration factory
MajedAlaitwniCap Dec 4, 2024
2fcee4c
add new factories to index
MajedAlaitwniCap Dec 4, 2024
45a4b6a
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 5, 2024
c71904b
revert adding new factories to index file
MajedAlaitwniCap Dec 5, 2024
87874ac
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 6, 2024
662310c
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 9, 2024
ee42f8e
Merge branch 'main' into EW-1053
MajedAlaitwniCap Dec 10, 2024
feda809
Merge branch 'main' of https://github.com/hpi-schul-cloud/schulcloud-…
MajedAlaitwniCap Dec 18, 2024
2d49b6b
modify externalUserDtoFactory
MajedAlaitwniCap Dec 18, 2024
4e6c0f6
reorder test factories to main modules
MajedAlaitwniCap Dec 19, 2024
ab87bfc
Merge branch 'main' into EW-1053
mkreuzkam-cap Jan 7, 2025
102ff37
fix nest lint.
mkreuzkam-cap Jan 7, 2025
45d1206
orgabize imports
MajedAlaitwniCap Jan 13, 2025
16c01f9
Merge branch 'main' into EW-1053
MajedAlaitwniCap Jan 13, 2025
0f06801
Merge branch 'main' into EW-1053
MajedAlaitwniCap Jan 15, 2025
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
132 changes: 69 additions & 63 deletions apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { faker } from '@faker-js/faker';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ProvisioningSystemDto } from '@modules/provisioning';
import {
ExternalClassDto,
ExternalSchoolDto,
ExternalUserDto,
OauthDataDto,
ProvisioningSystemDto,
} from '@modules/provisioning';
externalUserDtoFactory,
oauthDataDtoFactory,
externalClassDtoFactory,
provisioningSystemDtoFactory,
externalSchoolDtoFactory,
} from '@modules/provisioning/testing';
import { Test, TestingModule } from '@nestjs/testing';
import { RoleName } from '@shared/domain/interface';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import { robjExportSchuelerFactory, robjExportLehrerFactory, robjExportKlasseFactory } from '@infra/tsp-client/testing';
import { Logger } from '@src/core/logger';
import { RobjExportKlasse, RobjExportLehrer, RobjExportSchueler } from '@src/infra/tsp-client';
import { BadDataLoggableException } from '@src/modules/provisioning/loggable';
import { schoolFactory } from '@src/modules/school/testing';
import { systemFactory } from '@src/modules/system/testing';
Expand Down Expand Up @@ -64,71 +65,76 @@ describe(TspOauthDataMapper.name, () => {

const lehrerUid = faker.string.alpha();

const tspTeachers: RobjExportLehrer[] = [
{
lehrerUid,
lehrerNachname: faker.string.alpha(),
lehrerVorname: faker.string.alpha(),
schuleNummer: school.externalId,
},
];
const tspTeacher = robjExportLehrerFactory.build({
lehrerUid,
schuleNummer: school.externalId,
});
const tspTeachers = [tspTeacher];

const klasseId = faker.string.alpha();

const tspClasses: RobjExportKlasse[] = [
{
klasseId,
klasseName: faker.string.alpha(),
lehrerUid,
},
];

const tspStudents: RobjExportSchueler[] = [
{
schuelerUid: faker.string.alpha(),
schuelerNachname: faker.string.alpha(),
schuelerVorname: faker.string.alpha(),
schuleNummer: school.externalId,
klasseId,
},
];
const tspClass = robjExportKlasseFactory.build({
klasseId,
lehrerUid,
});
const tspClasses = [tspClass];

const tspStudent = robjExportSchuelerFactory.build({
schuelerUid: faker.string.alpha(),
schuelerNachname: faker.string.alpha(),
schuelerVorname: faker.string.alpha(),
schuleNummer: school.externalId,
klasseId,
});
const tspStudents = [tspStudent];

const provisioningSystemDto = new ProvisioningSystemDto({
const provisioningSystemDto: ProvisioningSystemDto = provisioningSystemDtoFactory.build({
systemId: system.id,
provisioningStrategy: SystemProvisioningStrategy.TSP,
});

const externalSchool = new ExternalSchoolDto({
externalId: school.externalId ?? '',
const externalClassDto = externalClassDtoFactory.build({
externalId: tspClasses[0].klasseId ?? '',
name: tspClasses[0].klasseName,
});

const externalTeacherUserDto = externalUserDtoFactory.build({
externalId: tspTeachers[0].lehrerUid ?? '',
firstName: tspTeachers[0].lehrerVorname,
lastName: tspTeachers[0].lehrerNachname,
roles: [RoleName.TEACHER],
email: undefined,
birthday: undefined,
});

const externalClass = new ExternalClassDto({
externalId: klasseId,
name: tspClasses[0].klasseName,
const externalStudentUserDto = externalUserDtoFactory.build({
externalId: tspStudents[0].schuelerUid ?? '',
firstName: tspStudents[0].schuelerVorname,
lastName: tspStudents[0].schuelerNachname,
roles: [RoleName.STUDENT],
email: undefined,
birthday: undefined,
});

const externalSchoolDto = externalSchoolDtoFactory.build({
externalId: school.externalId,
name: school.name,
officialSchoolNumber: undefined,
location: undefined,
});

const expected: OauthDataDto[] = [
new OauthDataDto({
const expected = [
oauthDataDtoFactory.build({
system: provisioningSystemDto,
externalUser: new ExternalUserDto({
externalId: tspTeachers[0].lehrerUid ?? '',
firstName: tspTeachers[0].lehrerVorname,
lastName: tspTeachers[0].lehrerNachname,
roles: [RoleName.TEACHER],
}),
externalSchool,
externalClasses: [externalClass],
externalUser: externalTeacherUserDto,
externalClasses: [externalClassDto],
externalSchool: externalSchoolDto,
}),
new OauthDataDto({
oauthDataDtoFactory.build({
system: provisioningSystemDto,
externalUser: new ExternalUserDto({
externalId: tspStudents[0].schuelerUid ?? '',
firstName: tspStudents[0].schuelerVorname,
lastName: tspStudents[0].schuelerNachname,
roles: [RoleName.STUDENT],
}),
externalSchool,
externalClasses: [externalClass],
externalUser: externalStudentUserDto,
externalClasses: [externalClassDto],
externalSchool: externalSchoolDto,
}),
];

Expand Down Expand Up @@ -165,9 +171,9 @@ describe(TspOauthDataMapper.name, () => {
const setup = () => {
const system = systemFactory.build();

const tspClass: RobjExportKlasse = {
const tspClass = robjExportKlasseFactory.build({
klasseId: undefined,
};
});

return { system, tspClass };
};
Expand All @@ -185,9 +191,9 @@ describe(TspOauthDataMapper.name, () => {
const setup = () => {
const system = systemFactory.build();

const tspTeacher: RobjExportLehrer = {
const tspTeacher = robjExportLehrerFactory.build({
lehrerUid: undefined,
};
});

return { system, tspTeacher };
};
Expand All @@ -205,9 +211,9 @@ describe(TspOauthDataMapper.name, () => {
const setup = () => {
const system = systemFactory.build();

const tspStudent: RobjExportSchueler = {
const tspStudent = robjExportSchuelerFactory.build({
schuelerUid: undefined,
};
});

return { system, tspStudent };
};
Expand Down
34 changes: 16 additions & 18 deletions apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ import { Test, TestingModule } from '@nestjs/testing';
import { UserDO } from '@shared/domain/domainobject';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import { Logger } from '@src/core/logger';
import { Account } from '@src/modules/account';
import { ExternalUserDto, OauthDataDto, ProvisioningService, ProvisioningSystemDto } from '@src/modules/provisioning';
import { robjExportSchuleFactory } from '@infra/tsp-client/testing';
import { Account } from '@modules/account';
import { OauthDataDto, ProvisioningService } from '@modules/provisioning';
import {
externalUserDtoFactory,
oauthDataDtoFactory,
provisioningSystemDtoFactory,
} from '@modules/provisioning/testing';
import { School } from '@src/modules/school';
import { schoolFactory } from '@src/modules/school/testing';
import { System } from '@src/modules/system';
Expand All @@ -23,10 +29,10 @@ import { SyncStrategyTarget } from '../sync-strategy.types';
import { TspFetchService } from './tsp-fetch.service';
import { TspLegacyMigrationService } from './tsp-legacy-migration.service';
import { TspOauthDataMapper } from './tsp-oauth-data.mapper';
import { TspSyncMigrationService } from './tsp-sync-migration.service';
import { TspSyncConfig } from './tsp-sync.config';
import { TspSyncService } from './tsp-sync.service';
import { TspSyncStrategy } from './tsp-sync.strategy';
import { TspSyncMigrationService } from './tsp-sync-migration.service';

describe(TspSyncStrategy.name, () => {
let module: TestingModule;
Expand Down Expand Up @@ -161,12 +167,12 @@ describe(TspSyncStrategy.name, () => {
describe('sync', () => {
describe('when sync is called', () => {
const setup = () => {
const oauthDataDto = new OauthDataDto({
system: new ProvisioningSystemDto({
const oauthDataDto = oauthDataDtoFactory.build({
system: provisioningSystemDtoFactory.build({
systemId: faker.string.alpha(),
provisioningStrategy: SystemProvisioningStrategy.TSP,
}),
externalUser: new ExternalUserDto({
externalUser: externalUserDtoFactory.build({
externalId: faker.string.alpha(),
roles: [],
}),
Expand Down Expand Up @@ -278,10 +284,7 @@ describe(TspSyncStrategy.name, () => {

describe('when school does not exist', () => {
const setup = () => {
const tspSchool: RobjExportSchule = {
schuleNummer: faker.string.alpha(),
schuleName: faker.string.alpha(),
};
const tspSchool = robjExportSchuleFactory.build();
const tspSchools = [tspSchool];

setupMockServices({
Expand All @@ -301,10 +304,7 @@ describe(TspSyncStrategy.name, () => {

describe('when school does exist', () => {
const setup = () => {
const tspSchool: RobjExportSchule = {
schuleNummer: faker.string.alpha(),
schuleName: faker.string.alpha(),
};
const tspSchool = robjExportSchuleFactory.build();
const tspSchools = [tspSchool];
const school = schoolFactory.build();

Expand All @@ -326,10 +326,8 @@ describe(TspSyncStrategy.name, () => {

describe('when tsp school does not have a schulnummer', () => {
const setup = () => {
const tspSchool: RobjExportSchule = {
schuleNummer: undefined,
schuleName: faker.string.alpha(),
};
const tspSchool = robjExportSchuleFactory.build();
tspSchool.schuleNummer = undefined;
const tspSchools = [tspSchool];

setupMockServices({
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/infra/tsp-client/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { robjExportSchuleFactory } from './robj-export-schule.factory';
export { robjExportKlasseFactory } from './robj-export-klasse.factory';
export { robjExportLehrerFactory } from './robj-export-lehrer.factory';
export { robjExportSchuelerFactory } from './robj-export-schueler.factory';
export { robjExportLehrerMigrationFactory } from './robj-export-lehrer-migration.factory';
export { robjExportSchuelerMigrationFactory } from './robj-export-schueler-migration.factory';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { RobjExportKlasse } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportKlasseFactory = Factory.define<RobjExportKlasse, RobjExportKlasse>(({ sequence }) => {
return {
id: new ObjectId().toHexString(),
version: `version ${sequence}`,
klasseName: `klasseName ${sequence}`,
schuleNummer: `schuleNummer ${sequence}`,
klasseId: `klasseId ${sequence}`,
lehrerUid: `lehrerUid ${sequence}`,
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { RobjExportLehrerMigration } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportLehrerMigrationFactory = Factory.define<RobjExportLehrerMigration, RobjExportLehrerMigration>(
() => {
return {
lehrerUidAlt: new ObjectId().toHexString(),
lehrerUidNeu: new ObjectId().toHexString(),
};
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { RobjExportLehrer } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportLehrerFactory = Factory.define<RobjExportLehrer, RobjExportLehrer>(({ sequence }) => {
return {
lehrerUid: new ObjectId().toHexString(),
lehrerTitel: `lehrerTitel ${sequence}`,
lehrerVorname: `lehrerVorname ${sequence}`,
lehrerNachname: `lehrerNachname ${sequence}`,
schuleNummer: `schuleNummer ${sequence}`,
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { RobjExportSchuelerMigration } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportSchuelerMigrationFactory = Factory.define<
RobjExportSchuelerMigration,
RobjExportSchuelerMigration
>(() => {
return {
schuelerUidAlt: new ObjectId().toHexString(),
schuelerUidNeu: new ObjectId().toHexString(),
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { RobjExportSchueler } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportSchuelerFactory = Factory.define<RobjExportSchueler, RobjExportSchueler>(({ sequence }) => {
return {
schuelerUid: new ObjectId().toHexString(),
schuelerVorname: `schuelerVorname ${sequence}`,
schuelerNachname: `schuelerNachname ${sequence}`,
schuleNummer: `schuleNummer ${sequence}`,
klasseId: `klasseId ${sequence}`,
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RobjExportSchule } from '@src/infra/tsp-client';
import { Factory } from 'fishery';

export const robjExportSchuleFactory = Factory.define<RobjExportSchule, RobjExportSchule>(({ sequence }) => {
return {
schuleName: `schuleName ${sequence}`,
schuleNummer: `schuleNummer ${sequence}`,
};
});
14 changes: 7 additions & 7 deletions apps/server/src/modules/provisioning/dto/provisioning.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class ProvisioningDto {
externalUserId: string;

constructor(provisioningDto: ProvisioningDto) {
this.externalUserId = provisioningDto.externalUserId;
}
}
export class ProvisioningDto {
public externalUserId: string;
constructor(provisioningDto: ProvisioningDto) {
this.externalUserId = provisioningDto.externalUserId;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { externalSchoolDtoFactory } from '@shared/testing';
import { externalGroupDtoFactory } from '@shared/testing/factory/external-group-dto.factory';
import { externalGroupDtoFactory, externalSchoolDtoFactory } from '@modules/provisioning/testing';
import { ExternalGroupDto, ExternalSchoolDto } from '../dto';
import { SchoolForGroupNotFoundLoggable } from './school-for-group-not-found.loggable';

Expand Down
Loading
Loading