Skip to content

Commit

Permalink
Merge branch 'EW-1053' into EW-1083
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap committed Jan 20, 2025
2 parents 6e6e1e5 + 0f06801 commit f5efcaa
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 193 deletions.
134 changes: 70 additions & 64 deletions apps/server/src/infra/sync/strategy/tsp/tsp-oauth-data.mapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { faker } from '@faker-js/faker';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import {
ExternalClassDto,
ExternalSchoolDto,
ExternalUserDto,
OauthDataDto,
ProvisioningSystemDto,
} from '@modules/provisioning';
import { robjExportKlasseFactory, robjExportLehrerFactory, robjExportSchuelerFactory } from '@infra/tsp-client/testing';
import { ProvisioningSystemDto } from '@modules/provisioning';
import { BadDataLoggableException } from '@modules/provisioning/loggable';
import {
externalClassDtoFactory,
externalSchoolDtoFactory,
externalUserDtoFactory,
oauthDataDtoFactory,
provisioningSystemDtoFactory,
} from '@modules/provisioning/testing/';
import { schoolFactory } from '@modules/school/testing';
import { systemFactory } from '@modules/system/testing';
import { Test, TestingModule } from '@nestjs/testing';
import { RoleName } from '@shared/domain/interface';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import { Logger } from '@src/core/logger';
import { RobjExportKlasse, RobjExportLehrer, RobjExportSchueler } from '../../../tsp-client';
import { TspMissingExternalIdLoggable } from './loggable/tsp-missing-external-id.loggable';
import { TspOauthDataMapper } from './tsp-oauth-data.mapper';

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 externalClass = new ExternalClassDto({
externalId: 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 expected: OauthDataDto[] = [
new OauthDataDto({
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 = [
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
30 changes: 14 additions & 16 deletions apps/server/src/infra/sync/strategy/tsp/tsp-sync.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import {
RobjExportSchuelerMigration,
RobjExportSchule,
} from '@infra/tsp-client';
import { robjExportSchuleFactory } from '@infra/tsp-client/testing';
import { Account } from '@modules/account';
import { ExternalUserDto, OauthDataDto, ProvisioningService, ProvisioningSystemDto } from '@modules/provisioning';
import { OauthDataDto, ProvisioningService } from '@modules/provisioning';
import {
externalUserDtoFactory,
oauthDataDtoFactory,
provisioningSystemDtoFactory,
} from '@modules/provisioning/testing';
import { School } from '@modules/school';
import { schoolFactory } from '@modules/school/testing';
import { System } from '@modules/system';
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 '@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 '@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 '@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 '@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 '@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 '@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,6 +1,5 @@
import { externalSchoolDtoFactory } from '@testing/factory/external-school-dto.factory';
import { externalGroupDtoFactory, externalSchoolDtoFactory } from '@modules/provisioning/testing';
import { ExternalGroupDto, ExternalSchoolDto } from '../dto';
import { externalGroupDtoFactory } from '../testing';
import { SchoolForGroupNotFoundLoggable } from './school-for-group-not-found.loggable';

describe('SchoolForGroupNotFoundLoggable', () => {
Expand Down
Loading

0 comments on commit f5efcaa

Please sign in to comment.