From f840ab4f0fa89226320f58b3ef4c92458510eaff Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Fri, 29 Nov 2024 16:17:03 +0100 Subject: [PATCH 1/8] Add and use Test Factories --- .../sync/tsp/tsp-oauth-data.mapper.spec.ts | 68 +++++++------- .../service/provisioning.service.spec.ts | 13 +-- .../service/tsp-provisioning.service.spec.ts | 89 ++++++++----------- .../factory/external-class-dto.factory.ts | 11 +++ .../factory/external-school-dto.factory.ts | 15 ++-- .../factory/external-user-dto.factory.ts | 13 +++ .../testing/factory/oauth-data-dto.factory.ts | 15 ++++ .../factory/provisioning-dto.factory.ts | 10 +++ .../provisioning-system-dto.factory.ts | 12 +++ 9 files changed, 149 insertions(+), 97 deletions(-) create mode 100644 apps/server/src/shared/testing/factory/external-class-dto.factory.ts create mode 100644 apps/server/src/shared/testing/factory/external-user-dto.factory.ts create mode 100644 apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts create mode 100644 apps/server/src/shared/testing/factory/provisioning-dto.factory.ts create mode 100644 apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index fda468415cb..c0f83f20820 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -1,15 +1,14 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { - ExternalClassDto, - ExternalSchoolDto, - ExternalUserDto, - OauthDataDto, - ProvisioningSystemDto, -} from '@modules/provisioning'; +import { ExternalClassDto, ExternalSchoolDto, ProvisioningSystemDto } from '@modules/provisioning'; import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; +import { externalSchoolDtoFactory } from '@shared/testing'; +import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; import { Logger } from '@src/core/logger'; import { RobjExportKlasse, RobjExportLehrer, RobjExportSchueler } from '@src/infra/tsp-client'; import { BadDataLoggableException } from '@src/modules/provisioning/loggable'; @@ -93,42 +92,49 @@ describe(TspOauthDataMapper.name, () => { }, ]; - const provisioningSystemDto = new ProvisioningSystemDto({ + const provisioningSystemDto: ProvisioningSystemDto = provisioningSystemDtoFactory.build({ systemId: system.id, provisioningStrategy: SystemProvisioningStrategy.TSP, }); - const externalSchool = new ExternalSchoolDto({ - externalId: school.externalId ?? '', + const externalSchoolDto: ExternalSchoolDto = externalSchoolDtoFactory.build({ + externalId: school.externalId, + name: undefined, }); - const externalClass = new ExternalClassDto({ - externalId: klasseId, + const externalClassDto: ExternalClassDto = externalClassDtoFactory.build({ + externalId: tspClasses[0].klasseId ?? '', name: tspClasses[0].klasseName, }); - const expected: OauthDataDto[] = [ - new OauthDataDto({ + const externalTeacherUserDto = externalUserDtoFactory.build({ + externalId: tspTeachers[0].lehrerUid ?? '', + firstName: tspTeachers[0].lehrerVorname, + lastName: tspTeachers[0].lehrerNachname, + roles: [RoleName.TEACHER], + email: undefined, + }); + + const externalStudentUserDto = externalUserDtoFactory.build({ + externalId: tspStudents[0].schuelerUid ?? '', + firstName: tspStudents[0].schuelerVorname, + lastName: tspStudents[0].schuelerNachname, + roles: [RoleName.STUDENT], + email: 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, + externalSchool: externalSchoolDto, + externalClasses: [externalClassDto], }), - 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, + externalSchool: externalSchoolDto, + externalClasses: [externalClassDto], }), ]; diff --git a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts index 37790f6cadd..79894dd1514 100644 --- a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts @@ -1,9 +1,12 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { System, SystemService } from '@modules/system'; -import { systemFactory } from '@modules/system/testing'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningDtoFactory } from '@shared/testing/factory/provisioning-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { systemFactory } from '@src/modules/system/testing'; import { ExternalUserDto, OauthDataDto, @@ -12,8 +15,8 @@ import { ProvisioningSystemDto, } from '../dto'; import { IservProvisioningStrategy, OidcMockProvisioningStrategy, SanisProvisioningStrategy } from '../strategy'; -import { ProvisioningService } from './provisioning.service'; import { TspProvisioningStrategy } from '../strategy/tsp/tsp.strategy'; +import { ProvisioningService } from './provisioning.service'; describe('ProvisioningService', () => { let module: TestingModule; @@ -83,18 +86,18 @@ describe('ProvisioningService', () => { provisioningUrl: 'https://api.moin.schule/', provisioningStrategy: SystemProvisioningStrategy.SANIS, }); - const provisioningSystemDto: ProvisioningSystemDto = new ProvisioningSystemDto({ + const provisioningSystemDto: ProvisioningSystemDto = provisioningSystemDtoFactory.build({ systemId: system.id, provisioningUrl: 'https://api.moin.schule/', provisioningStrategy: SystemProvisioningStrategy.SANIS, }); - const oauthDataDto: OauthDataDto = new OauthDataDto({ + const oauthDataDto: OauthDataDto = oauthDataDtoFactory.build({ system: provisioningSystemDto, externalUser: new ExternalUserDto({ externalId: 'externalUserId', }), }); - const provisioningDto: ProvisioningDto = new ProvisioningDto({ + const provisioningDto: ProvisioningDto = provisioningDtoFactory.build({ externalUserId: 'externalUserId', }); diff --git a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts index da637580400..c2ed303cd63 100644 --- a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts @@ -3,8 +3,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { RoleName } from '@shared/domain/interface'; -import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; +import { externalSchoolDtoFactory, roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; +import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; import { AccountService } from '@src/modules/account'; import { ClassService } from '@src/modules/class'; import { classFactory } from '@src/modules/class/domain/testing'; @@ -12,7 +15,6 @@ import { RoleService } from '@src/modules/role'; import { SchoolService } from '@src/modules/school'; import { schoolFactory } from '@src/modules/school/testing'; import { UserService } from '@src/modules/user'; -import { ExternalClassDto, ExternalSchoolDto, ExternalUserDto, OauthDataDto, ProvisioningSystemDto } from '../dto'; import { BadDataLoggableException } from '../loggable'; import { TspProvisioningService } from './tsp-provisioning.service'; @@ -25,27 +27,6 @@ describe('TspProvisioningService', () => { let userServiceMock: DeepMocked; let accountServiceMock: DeepMocked; - const setupExternalSystem = (props?: Partial) => { - const baseProps = { systemId: faker.string.uuid(), provisioningStrategy: SystemProvisioningStrategy.TSP }; - - return new ProvisioningSystemDto({ ...baseProps, ...props }); - }; - const setupExternalSchool = (props?: Partial) => { - const baseProps = { externalId: faker.string.uuid(), name: faker.string.sample() }; - - return new ExternalSchoolDto({ ...baseProps, ...props }); - }; - const setupExternalClass = (props?: Partial) => { - const baseProps = { externalId: faker.string.uuid(), name: faker.string.sample() }; - - return new ExternalClassDto({ ...baseProps, ...props }); - }; - const setupExternalUser = (props?: Partial) => { - const baseProps = { externalId: faker.string.uuid(), username: faker.internet.userName() }; - - return new ExternalUserDto({ ...baseProps, ...props }); - }; - beforeAll(async () => { module = await Test.createTestingModule({ providers: [ @@ -96,8 +77,8 @@ describe('TspProvisioningService', () => { describe('findSchoolOrFail', () => { describe('when school is found', () => { const setup = () => { - const system = setupExternalSystem(); - const externalSchool = setupExternalSchool(); + const system = provisioningSystemDtoFactory.build(); + const externalSchool = externalSchoolDtoFactory.build(); const school = schoolFactory.build(); schoolServiceMock.getSchools.mockResolvedValueOnce([school]); @@ -116,8 +97,8 @@ describe('TspProvisioningService', () => { describe('when school is not found', () => { const setup = () => { - const system = setupExternalSystem(); - const externalSchool = setupExternalSchool(); + const system = provisioningSystemDtoFactory.build(); + const externalSchool = externalSchoolDtoFactory.build(); schoolServiceMock.getSchools.mockResolvedValueOnce([]); @@ -136,7 +117,7 @@ describe('TspProvisioningService', () => { describe('when user ID is missing', () => { const setup = () => { const school = schoolFactory.build(); - const classes = [setupExternalClass()]; + const classes = [externalClassDtoFactory.build()]; const user = userDoFactory.build(); return { school, classes, user }; @@ -152,7 +133,7 @@ describe('TspProvisioningService', () => { describe('when class exists', () => { const setup = () => { const school = schoolFactory.build(); - const classes = [setupExternalClass()]; + const classes = [externalClassDtoFactory.build()]; const clazz = classFactory.build(); const user = userDoFactory.buildWithId({ roles: [roleFactory.build({ name: RoleName.TEACHER }), roleFactory.build({ name: RoleName.STUDENT })], @@ -175,7 +156,7 @@ describe('TspProvisioningService', () => { describe('when class does not exist', () => { const setup = () => { const school = schoolFactory.build(); - const classes = [setupExternalClass()]; + const classes = [externalClassDtoFactory.build()]; const user = userDoFactory.buildWithId({ roles: [roleFactory.build({ name: RoleName.TEACHER }), roleFactory.build({ name: RoleName.STUDENT })], }); @@ -198,9 +179,9 @@ describe('TspProvisioningService', () => { describe('provisionUser', () => { describe('when external school is missing', () => { const setup = () => { - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser(), + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalSchool: undefined, }); const school = schoolFactory.build(); @@ -217,10 +198,10 @@ describe('TspProvisioningService', () => { describe('when user exists and school is the same', () => { const setup = () => { const school = schoolFactory.build(); - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser(), - externalSchool: setupExternalSchool({ + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalUser: externalUserDtoFactory.build(), + externalSchool: externalSchoolDtoFactory.build({ externalId: school.externalId, }), }); @@ -246,10 +227,10 @@ describe('TspProvisioningService', () => { describe('when user exists and school is different', () => { const setup = () => { const school = schoolFactory.build(); - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser(), - externalSchool: setupExternalSchool(), + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalUser: externalUserDtoFactory.build(), + externalSchool: externalSchoolDtoFactory.build(), }); const user = userDoFactory.build({ id: faker.string.uuid() }); const roles = [ @@ -278,14 +259,14 @@ describe('TspProvisioningService', () => { describe('when user does not exist and has no firstname, lastname and email', () => { const setup = (withFirstname: boolean, withLastname: boolean, withEmail: boolean) => { const school = schoolFactory.build(); - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser({ + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalUser: externalUserDtoFactory.build({ firstName: withFirstname ? faker.person.firstName() : undefined, lastName: withLastname ? faker.person.lastName() : undefined, email: withEmail ? faker.internet.email() : undefined, }), - externalSchool: setupExternalSchool(), + externalSchool: externalSchoolDtoFactory.build(), }); userServiceMock.findByExternalId.mockResolvedValue(null); @@ -311,14 +292,14 @@ describe('TspProvisioningService', () => { describe('when user does not exist', () => { const setup = () => { const school = schoolFactory.build(); - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser({ + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalUser: externalUserDtoFactory.build({ firstName: faker.person.firstName(), lastName: faker.person.lastName(), email: faker.internet.email(), }), - externalSchool: setupExternalSchool(), + externalSchool: externalSchoolDtoFactory.build(), }); const user = userDoFactory.build({ id: faker.string.uuid(), roles: [] }); @@ -343,14 +324,14 @@ describe('TspProvisioningService', () => { describe('when user id is not set after create', () => { const setup = () => { const school = schoolFactory.build(); - const data = new OauthDataDto({ - system: setupExternalSystem(), - externalUser: setupExternalUser({ + const data = oauthDataDtoFactory.build({ + system: provisioningSystemDtoFactory.build(), + externalUser: externalUserDtoFactory.build({ firstName: faker.person.firstName(), lastName: faker.person.lastName(), email: faker.internet.email(), }), - externalSchool: setupExternalSchool(), + externalSchool: externalSchoolDtoFactory.build(), }); const user = userDoFactory.build({ id: undefined, roles: [] }); diff --git a/apps/server/src/shared/testing/factory/external-class-dto.factory.ts b/apps/server/src/shared/testing/factory/external-class-dto.factory.ts new file mode 100644 index 00000000000..7bc8d9f3f55 --- /dev/null +++ b/apps/server/src/shared/testing/factory/external-class-dto.factory.ts @@ -0,0 +1,11 @@ +import { ExternalClassDto } from '@modules/provisioning'; +import { ObjectId } from '@mikro-orm/mongodb'; +import { Factory } from 'fishery'; + +export const externalClassDtoFactory = Factory.define( + ({ sequence }) => + new ExternalClassDto({ + externalId: new ObjectId().toHexString(), + name: `external Class ${sequence}`, + }) +); diff --git a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts index e56e64d9243..f559e5613f4 100644 --- a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts +++ b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts @@ -1,10 +1,11 @@ -import { ExternalSchoolDto } from '@modules/provisioning/dto'; +import { ExternalSchoolDto } from '@modules/provisioning'; import { ObjectId } from '@mikro-orm/mongodb'; import { Factory } from 'fishery'; -export const externalSchoolDtoFactory = Factory.define(({ sequence }) => { - return { - externalId: new ObjectId().toHexString(), - name: `External School ${sequence}`, - }; -}); +export const externalSchoolDtoFactory = Factory.define( + ({ sequence }) => + new ExternalSchoolDto({ + externalId: new ObjectId().toHexString(), + name: `External School ${sequence}`, + }) +); diff --git a/apps/server/src/shared/testing/factory/external-user-dto.factory.ts b/apps/server/src/shared/testing/factory/external-user-dto.factory.ts new file mode 100644 index 00000000000..19ea7fb2119 --- /dev/null +++ b/apps/server/src/shared/testing/factory/external-user-dto.factory.ts @@ -0,0 +1,13 @@ +import { ExternalUserDto } from '@src/modules/provisioning'; +import { ObjectId } from '@mikro-orm/mongodb'; +import { Factory } from 'fishery'; + +export const externalUserDtoFactory = Factory.define( + ({ sequence }) => + new ExternalUserDto({ + externalId: new ObjectId().toHexString(), + firstName: `Firstname ${sequence}`, + lastName: `Lastname ${sequence}`, + email: `Email ${sequence}`, + }) +); diff --git a/apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts b/apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts new file mode 100644 index 00000000000..b8a11d639f7 --- /dev/null +++ b/apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts @@ -0,0 +1,15 @@ +import { OauthDataDto } from '@modules/provisioning'; +import { Factory } from 'fishery'; +import { externalUserDtoFactory } from './external-user-dto.factory'; +import { provisioningSystemDtoFactory } from './provisioning-system-dto.factory'; + +export const oauthDataDtoFactory = Factory.define(() => { + const system = provisioningSystemDtoFactory.build(); + const externalUser = externalUserDtoFactory.build(); + const oauthDataDto = new OauthDataDto({ + system, + externalUser, + }); + + return oauthDataDto; +}); diff --git a/apps/server/src/shared/testing/factory/provisioning-dto.factory.ts b/apps/server/src/shared/testing/factory/provisioning-dto.factory.ts new file mode 100644 index 00000000000..5262232bfa9 --- /dev/null +++ b/apps/server/src/shared/testing/factory/provisioning-dto.factory.ts @@ -0,0 +1,10 @@ +import { ProvisioningDto } from '@modules/provisioning'; +import { ObjectId } from '@mikro-orm/mongodb'; +import { Factory } from 'fishery'; + +export const provisioningDtoFactory = Factory.define( + () => + new ProvisioningDto({ + externalUserId: new ObjectId().toHexString(), + }) +); diff --git a/apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts b/apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts new file mode 100644 index 00000000000..131c5c72364 --- /dev/null +++ b/apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts @@ -0,0 +1,12 @@ +import { ProvisioningSystemDto } from '@modules/provisioning'; +import { ObjectId } from '@mikro-orm/mongodb'; +import { Factory } from 'fishery'; +import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; + +export const provisioningSystemDtoFactory = Factory.define( + () => + new ProvisioningSystemDto({ + systemId: new ObjectId().toHexString(), + provisioningStrategy: SystemProvisioningStrategy.TSP, + }) +); From 4e0f4e297360fa41b6522d55fe40b5f5a66be7f3 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Mon, 2 Dec 2024 15:02:43 +0100 Subject: [PATCH 2/8] revert ExternalSchoolDto changes --- .../infra/sync/tsp/tsp-oauth-data.mapper.spec.ts | 14 +++----------- .../factory/external-school-dto.factory.ts | 15 +++++++-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index c0f83f20820..8dca6da47d1 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -1,10 +1,9 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { ExternalClassDto, ExternalSchoolDto, ProvisioningSystemDto } from '@modules/provisioning'; +import { ExternalClassDto, ProvisioningSystemDto } from '@modules/provisioning'; import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { externalSchoolDtoFactory } from '@shared/testing'; import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; @@ -97,11 +96,6 @@ describe(TspOauthDataMapper.name, () => { provisioningStrategy: SystemProvisioningStrategy.TSP, }); - const externalSchoolDto: ExternalSchoolDto = externalSchoolDtoFactory.build({ - externalId: school.externalId, - name: undefined, - }); - const externalClassDto: ExternalClassDto = externalClassDtoFactory.build({ externalId: tspClasses[0].klasseId ?? '', name: tspClasses[0].klasseName, @@ -127,13 +121,11 @@ describe(TspOauthDataMapper.name, () => { oauthDataDtoFactory.build({ system: provisioningSystemDto, externalUser: externalTeacherUserDto, - externalSchool: externalSchoolDto, externalClasses: [externalClassDto], }), oauthDataDtoFactory.build({ system: provisioningSystemDto, externalUser: externalStudentUserDto, - externalSchool: externalSchoolDto, externalClasses: [externalClassDto], }), ]; @@ -142,9 +134,9 @@ describe(TspOauthDataMapper.name, () => { }; it('should return an array of oauth data dtos', () => { - const { system, school, tspTeachers, tspStudents, tspClasses, expected } = setup(); + const { system, tspTeachers, tspStudents, tspClasses, expected } = setup(); - const result = sut.mapTspDataToOauthData(system, [school], tspTeachers, tspStudents, tspClasses); + const result = sut.mapTspDataToOauthData(system, [], tspTeachers, tspStudents, tspClasses); expect(result).toStrictEqual(expected); }); diff --git a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts index f559e5613f4..e56e64d9243 100644 --- a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts +++ b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts @@ -1,11 +1,10 @@ -import { ExternalSchoolDto } from '@modules/provisioning'; +import { ExternalSchoolDto } from '@modules/provisioning/dto'; import { ObjectId } from '@mikro-orm/mongodb'; import { Factory } from 'fishery'; -export const externalSchoolDtoFactory = Factory.define( - ({ sequence }) => - new ExternalSchoolDto({ - externalId: new ObjectId().toHexString(), - name: `External School ${sequence}`, - }) -); +export const externalSchoolDtoFactory = Factory.define(({ sequence }) => { + return { + externalId: new ObjectId().toHexString(), + name: `External School ${sequence}`, + }; +}); From 6e3a643fa9bb29007ff40e2d6f234560ca83d33c Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 4 Dec 2024 11:17:37 +0100 Subject: [PATCH 3/8] add and use factories for robj export models --- .../sync/tsp/tsp-oauth-data.mapper.spec.ts | 64 +++++++++---------- .../infra/sync/tsp/tsp-sync.strategy.spec.ts | 51 +++++++-------- .../factory/robj-export-klasse.factory.ts | 14 ++++ .../robj-export-lehrer-migration.factory.ts | 12 ++++ .../factory/robj-export-lehrer.factory.ts | 13 ++++ .../factory/robj-export-schueler.factory.ts | 13 ++++ .../factory/robj-export-schule.factory.ts | 9 +++ 7 files changed, 115 insertions(+), 61 deletions(-) create mode 100644 apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts create mode 100644 apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts create mode 100644 apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts create mode 100644 apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts create mode 100644 apps/server/src/shared/testing/factory/robj-export-schule.factory.ts diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index 8dca6da47d1..7b25d5c2ba7 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -1,6 +1,6 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { ExternalClassDto, ProvisioningSystemDto } from '@modules/provisioning'; +import { ProvisioningSystemDto } from '@modules/provisioning'; import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; @@ -8,8 +8,10 @@ import { externalClassDtoFactory } from '@shared/testing/factory/external-class- import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { robjExportKlasseFactory } from '@shared/testing/factory/robj-export-klasse.factory'; +import { robjExportLehrerFactory } from '@shared/testing/factory/robj-export-lehrer.factory'; +import { robjExportSchuelerFactory } from '@shared/testing/factory/robj-export-schueler.factory'; 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'; @@ -62,41 +64,35 @@ 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: ProvisioningSystemDto = provisioningSystemDtoFactory.build({ systemId: system.id, provisioningStrategy: SystemProvisioningStrategy.TSP, }); - const externalClassDto: ExternalClassDto = externalClassDtoFactory.build({ + const externalClassDto = externalClassDtoFactory.build({ externalId: tspClasses[0].klasseId ?? '', name: tspClasses[0].klasseName, }); @@ -163,9 +159,9 @@ describe(TspOauthDataMapper.name, () => { const setup = () => { const system = systemFactory.build(); - const tspClass: RobjExportKlasse = { + const tspClass = robjExportKlasseFactory.build({ klasseId: undefined, - }; + }); return { system, tspClass }; }; @@ -183,9 +179,9 @@ describe(TspOauthDataMapper.name, () => { const setup = () => { const system = systemFactory.build(); - const tspTeacher: RobjExportLehrer = { + const tspTeacher = robjExportLehrerFactory.build({ lehrerUid: undefined, - }; + }); return { system, tspTeacher }; }; @@ -203,9 +199,9 @@ describe(TspOauthDataMapper.name, () => { const setup = () => { const system = systemFactory.build(); - const tspStudent: RobjExportSchueler = { + const tspStudent = robjExportSchuelerFactory.build({ schuelerUid: undefined, - }; + }); return { system, tspStudent }; }; diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts index b4d8a3b8a52..835aa126b6e 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts @@ -13,17 +13,22 @@ import { Test, TestingModule } from '@nestjs/testing'; import { UserDO } from '@shared/domain/domainobject'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { userDoFactory } from '@shared/testing'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; +import { robjExportLehrerMigrationFactory } from '@shared/testing/factory/robj-export-lehrer-migration.factory'; import { Logger } from '@src/core/logger'; import { Account } from '@src/modules/account'; import { accountDoFactory } from '@src/modules/account/testing'; -import { ExternalUserDto, OauthDataDto, ProvisioningService, ProvisioningSystemDto } from '@src/modules/provisioning'; +import { OauthDataDto, ProvisioningService } from '@src/modules/provisioning'; import { School } from '@src/modules/school'; import { schoolFactory } from '@src/modules/school/testing'; import { System } from '@src/modules/system'; import { systemFactory } from '@src/modules/system/testing'; import { SyncStrategyTarget } from '../sync-strategy.types'; -import { TspLegacyMigrationService } from './tsp-legacy-migration.service'; import { TspFetchService } from './tsp-fetch.service'; +import { TspLegacyMigrationService } from './tsp-legacy-migration.service'; import { TspOauthDataMapper } from './tsp-oauth-data.mapper'; import { TspSyncConfig } from './tsp-sync.config'; import { TspSyncService } from './tsp-sync.service'; @@ -164,12 +169,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(), }), }); @@ -301,10 +306,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({ @@ -323,10 +325,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(); @@ -347,10 +346,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({ @@ -371,14 +368,14 @@ describe(TspSyncStrategy.name, () => { describe('when UidAlt or UidNeu is missing during migration', () => { const setup = () => { - const tspTeacher: RobjExportLehrerMigration = { + const tspTeacher = robjExportLehrerMigrationFactory.build({ lehrerUidAlt: undefined, lehrerUidNeu: faker.string.alpha(), - }; - const tspStudent: RobjExportSchuelerMigration = { - schuelerUidAlt: faker.string.alpha(), - schuelerUidNeu: undefined, - }; + }); + const tspStudent = robjExportLehrerMigrationFactory.build({ + lehrerUidAlt: faker.string.alpha(), + lehrerUidNeu: undefined, + }) as RobjExportSchuelerMigration; setupMockServices({ fetchedStudentMigrations: [tspStudent], @@ -397,10 +394,10 @@ describe(TspSyncStrategy.name, () => { describe('when no user is found during migration', () => { const setup = () => { - const tspTeacher: RobjExportLehrerMigration = { + const tspTeacher = robjExportLehrerMigrationFactory.build({ lehrerUidAlt: faker.string.alpha(), lehrerUidNeu: faker.string.alpha(), - }; + }); setupMockServices({ fetchedTeacherMigrations: [tspTeacher], @@ -421,10 +418,10 @@ describe(TspSyncStrategy.name, () => { describe('when no account is found during migration', () => { const setup = () => { - const tspTeacher: RobjExportLehrerMigration = { + const tspTeacher = robjExportLehrerMigrationFactory.build({ lehrerUidAlt: faker.string.alpha(), lehrerUidNeu: faker.string.alpha(), - }; + }); setupMockServices({ fetchedTeacherMigrations: [tspTeacher], diff --git a/apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts b/apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts new file mode 100644 index 00000000000..cbdff111a16 --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts @@ -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(({ sequence }) => { + return { + id: new ObjectId().toHexString(), + version: `version ${sequence}`, + klasseName: `klasseName ${sequence}`, + schuleNummer: `schuleNummer ${sequence}`, + klasseId: `klasseId ${sequence}`, + lehrerUid: `lehrerUid ${sequence}`, + }; +}); diff --git a/apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts b/apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts new file mode 100644 index 00000000000..60c92b94d50 --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts @@ -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( + () => { + return { + lehrerUidAlt: new ObjectId().toHexString(), + lehrerUidNeu: new ObjectId().toHexString(), + }; + } +); diff --git a/apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts b/apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts new file mode 100644 index 00000000000..4dffa58a85c --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts @@ -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(({ sequence }) => { + return { + lehrerUid: new ObjectId().toHexString(), + lehrerTitel: `lehrerTitel ${sequence}`, + lehrerVorname: `lehrerVorname ${sequence}`, + lehrerNachname: `lehrerNachname ${sequence}`, + schuleNummer: `schuleNummer ${sequence}`, + }; +}); diff --git a/apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts b/apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts new file mode 100644 index 00000000000..4dd5a4e7ac6 --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts @@ -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(({ sequence }) => { + return { + schuelerUid: new ObjectId().toHexString(), + schuelerVorname: `schuelerVorname ${sequence}`, + schuelerNachname: `schuelerNachname ${sequence}`, + schuleNummer: `schuleNummer ${sequence}`, + klasseId: `klasseId ${sequence}`, + }; +}); diff --git a/apps/server/src/shared/testing/factory/robj-export-schule.factory.ts b/apps/server/src/shared/testing/factory/robj-export-schule.factory.ts new file mode 100644 index 00000000000..460fdf6ea5e --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-schule.factory.ts @@ -0,0 +1,9 @@ +import { RobjExportSchule } from '@src/infra/tsp-client'; +import { Factory } from 'fishery'; + +export const robjExportSchuleFactory = Factory.define(({ sequence }) => { + return { + schuleName: `schuleName ${sequence}`, + schuleNummer: `schuleNummer ${sequence}`, + }; +}); From e4aa8a3ad6b2242d6862a99f81843da0c8daadb3 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 4 Dec 2024 13:18:54 +0100 Subject: [PATCH 4/8] add robj-export-schueler-migration factory --- .../src/infra/sync/tsp/tsp-sync.strategy.spec.ts | 11 ++++++----- .../robj-export-schueler-migration.factory.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts index 835aa126b6e..bab633afa90 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts @@ -16,8 +16,9 @@ import { userDoFactory } from '@shared/testing'; import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; -import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; import { robjExportLehrerMigrationFactory } from '@shared/testing/factory/robj-export-lehrer-migration.factory'; +import { robjExportSchuelerMigrationFactory } from '@shared/testing/factory/robj-export-schueler-migration.factory'; +import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; import { Logger } from '@src/core/logger'; import { Account } from '@src/modules/account'; import { accountDoFactory } from '@src/modules/account/testing'; @@ -372,10 +373,10 @@ describe(TspSyncStrategy.name, () => { lehrerUidAlt: undefined, lehrerUidNeu: faker.string.alpha(), }); - const tspStudent = robjExportLehrerMigrationFactory.build({ - lehrerUidAlt: faker.string.alpha(), - lehrerUidNeu: undefined, - }) as RobjExportSchuelerMigration; + const tspStudent = robjExportSchuelerMigrationFactory.build({ + schuelerUidAlt: faker.string.alpha(), + schuelerUidNeu: undefined, + }); setupMockServices({ fetchedStudentMigrations: [tspStudent], diff --git a/apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts b/apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts new file mode 100644 index 00000000000..52c509f40df --- /dev/null +++ b/apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts @@ -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(), + }; +}); From 2fcee4cf16eada0ad6f43c5b53bc2cf5443d1337 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 4 Dec 2024 15:27:17 +0100 Subject: [PATCH 5/8] add new factories to index --- .../sync/tsp/tsp-oauth-data.mapper.spec.ts | 30 +++++++++++++------ .../infra/sync/tsp/tsp-sync.strategy.spec.ts | 16 +++++----- .../service/provisioning.service.spec.ts | 4 +-- .../service/tsp-provisioning.service.spec.ts | 15 ++++++---- .../factory/external-school-dto.factory.ts | 8 +++-- .../src/shared/testing/factory/index.ts | 11 +++++++ 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index 7b25d5c2ba7..caddda43118 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -4,13 +4,16 @@ import { ProvisioningSystemDto } from '@modules/provisioning'; import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; -import { robjExportKlasseFactory } from '@shared/testing/factory/robj-export-klasse.factory'; -import { robjExportLehrerFactory } from '@shared/testing/factory/robj-export-lehrer.factory'; -import { robjExportSchuelerFactory } from '@shared/testing/factory/robj-export-schueler.factory'; +import { + externalClassDtoFactory, + externalSchoolDtoFactory, + externalUserDtoFactory, + oauthDataDtoFactory, + provisioningSystemDtoFactory, + robjExportKlasseFactory, + robjExportLehrerFactory, + robjExportSchuelerFactory, +} from '@shared/testing/factory'; import { Logger } from '@src/core/logger'; import { BadDataLoggableException } from '@src/modules/provisioning/loggable'; import { schoolFactory } from '@src/modules/school/testing'; @@ -113,16 +116,25 @@ describe(TspOauthDataMapper.name, () => { email: undefined, }); + const externalSchoolDto = externalSchoolDtoFactory.build({ + externalId: school.externalId, + name: school.name, + officialSchoolNumber: undefined, + location: undefined, + }); + const expected = [ oauthDataDtoFactory.build({ system: provisioningSystemDto, externalUser: externalTeacherUserDto, externalClasses: [externalClassDto], + externalSchool: externalSchoolDto, }), oauthDataDtoFactory.build({ system: provisioningSystemDto, externalUser: externalStudentUserDto, externalClasses: [externalClassDto], + externalSchool: externalSchoolDto, }), ]; @@ -130,9 +142,9 @@ describe(TspOauthDataMapper.name, () => { }; it('should return an array of oauth data dtos', () => { - const { system, tspTeachers, tspStudents, tspClasses, expected } = setup(); + const { system, school, tspTeachers, tspStudents, tspClasses, expected } = setup(); - const result = sut.mapTspDataToOauthData(system, [], tspTeachers, tspStudents, tspClasses); + const result = sut.mapTspDataToOauthData(system, [school], tspTeachers, tspStudents, tspClasses); expect(result).toStrictEqual(expected); }); diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts index bab633afa90..345a4cac0ec 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts @@ -12,13 +12,15 @@ import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { UserDO } from '@shared/domain/domainobject'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { userDoFactory } from '@shared/testing'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; -import { robjExportLehrerMigrationFactory } from '@shared/testing/factory/robj-export-lehrer-migration.factory'; -import { robjExportSchuelerMigrationFactory } from '@shared/testing/factory/robj-export-schueler-migration.factory'; -import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; +import { + externalUserDtoFactory, + oauthDataDtoFactory, + provisioningSystemDtoFactory, + robjExportLehrerMigrationFactory, + robjExportSchuelerMigrationFactory, + robjExportSchuleFactory, + userDoFactory, +} from '@shared/testing/factory'; import { Logger } from '@src/core/logger'; import { Account } from '@src/modules/account'; import { accountDoFactory } from '@src/modules/account/testing'; diff --git a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts index 79894dd1514..d601a016563 100644 --- a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts @@ -3,9 +3,7 @@ import { System, SystemService } from '@modules/system'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningDtoFactory } from '@shared/testing/factory/provisioning-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { oauthDataDtoFactory, provisioningDtoFactory, provisioningSystemDtoFactory } from '@shared/testing/factory'; import { systemFactory } from '@src/modules/system/testing'; import { ExternalUserDto, diff --git a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts index c2ed303cd63..1f2ee5bc09d 100644 --- a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts @@ -3,11 +3,16 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { RoleName } from '@shared/domain/interface'; -import { externalSchoolDtoFactory, roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; -import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { + externalClassDtoFactory, + externalSchoolDtoFactory, + externalUserDtoFactory, + oauthDataDtoFactory, + provisioningSystemDtoFactory, + roleDtoFactory, + roleFactory, + userDoFactory, +} from '@shared/testing/factory'; import { AccountService } from '@src/modules/account'; import { ClassService } from '@src/modules/class'; import { classFactory } from '@src/modules/class/domain/testing'; diff --git a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts index e56e64d9243..21f35cf0f03 100644 --- a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts +++ b/apps/server/src/shared/testing/factory/external-school-dto.factory.ts @@ -1,8 +1,10 @@ -import { ExternalSchoolDto } from '@modules/provisioning/dto'; import { ObjectId } from '@mikro-orm/mongodb'; -import { Factory } from 'fishery'; +import { ExternalSchoolDto } from '@modules/provisioning/dto'; +import { BaseFactory } from './base.factory'; + +class ExternalSchoolDtoFactory extends BaseFactory> {} -export const externalSchoolDtoFactory = Factory.define(({ sequence }) => { +export const externalSchoolDtoFactory = ExternalSchoolDtoFactory.define(ExternalSchoolDto, ({ sequence }) => { return { externalId: new ObjectId().toHexString(), name: `External School ${sequence}`, diff --git a/apps/server/src/shared/testing/factory/index.ts b/apps/server/src/shared/testing/factory/index.ts index d0d2e9568d9..8820070172d 100644 --- a/apps/server/src/shared/testing/factory/index.ts +++ b/apps/server/src/shared/testing/factory/index.ts @@ -41,3 +41,14 @@ export * from './user-and-account.test.factory'; export * from './user-login-migration.factory'; export * from './user.do.factory'; export * from './user.factory'; +export * from './external-class-dto.factory'; +export * from './oauth-data-dto.factory'; +export * from './provisioning-dto.factory'; +export * from './provisioning-system-dto.factory'; +export * from './external-user-dto.factory'; +export * from './robj-export-schule.factory'; +export * from './robj-export-klasse.factory'; +export * from './robj-export-lehrer.factory'; +export * from './robj-export-schueler.factory'; +export * from './robj-export-lehrer-migration.factory'; +export * from './robj-export-schueler-migration.factory'; From c71904b52abefe4e7b5afcbfbc8a3668bf73ebc0 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Thu, 5 Dec 2024 15:27:07 +0100 Subject: [PATCH 6/8] revert adding new factories to index file --- .../sync/tsp/tsp-oauth-data.mapper.spec.ts | 18 ++++++++---------- .../infra/sync/tsp/tsp-sync.strategy.spec.ts | 16 +++++++--------- .../service/provisioning.service.spec.ts | 4 +++- .../service/tsp-provisioning.service.spec.ts | 15 +++++---------- .../server/src/shared/testing/factory/index.ts | 11 ----------- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index caddda43118..a8d4e6772c4 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -4,16 +4,14 @@ import { ProvisioningSystemDto } from '@modules/provisioning'; import { Test, TestingModule } from '@nestjs/testing'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { - externalClassDtoFactory, - externalSchoolDtoFactory, - externalUserDtoFactory, - oauthDataDtoFactory, - provisioningSystemDtoFactory, - robjExportKlasseFactory, - robjExportLehrerFactory, - robjExportSchuelerFactory, -} from '@shared/testing/factory'; +import { externalSchoolDtoFactory } from '@shared/testing'; +import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { robjExportKlasseFactory } from '@shared/testing/factory/robj-export-klasse.factory'; +import { robjExportLehrerFactory } from '@shared/testing/factory/robj-export-lehrer.factory'; +import { robjExportSchuelerFactory } from '@shared/testing/factory/robj-export-schueler.factory'; import { Logger } from '@src/core/logger'; import { BadDataLoggableException } from '@src/modules/provisioning/loggable'; import { schoolFactory } from '@src/modules/school/testing'; diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts index 345a4cac0ec..bab633afa90 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts @@ -12,15 +12,13 @@ import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { UserDO } from '@shared/domain/domainobject'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { - externalUserDtoFactory, - oauthDataDtoFactory, - provisioningSystemDtoFactory, - robjExportLehrerMigrationFactory, - robjExportSchuelerMigrationFactory, - robjExportSchuleFactory, - userDoFactory, -} from '@shared/testing/factory'; +import { userDoFactory } from '@shared/testing'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { robjExportLehrerMigrationFactory } from '@shared/testing/factory/robj-export-lehrer-migration.factory'; +import { robjExportSchuelerMigrationFactory } from '@shared/testing/factory/robj-export-schueler-migration.factory'; +import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; import { Logger } from '@src/core/logger'; import { Account } from '@src/modules/account'; import { accountDoFactory } from '@src/modules/account/testing'; diff --git a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts index d601a016563..79894dd1514 100644 --- a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts @@ -3,7 +3,9 @@ import { System, SystemService } from '@modules/system'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { oauthDataDtoFactory, provisioningDtoFactory, provisioningSystemDtoFactory } from '@shared/testing/factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningDtoFactory } from '@shared/testing/factory/provisioning-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; import { systemFactory } from '@src/modules/system/testing'; import { ExternalUserDto, diff --git a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts index 1f2ee5bc09d..c2ed303cd63 100644 --- a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts @@ -3,16 +3,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { RoleName } from '@shared/domain/interface'; -import { - externalClassDtoFactory, - externalSchoolDtoFactory, - externalUserDtoFactory, - oauthDataDtoFactory, - provisioningSystemDtoFactory, - roleDtoFactory, - roleFactory, - userDoFactory, -} from '@shared/testing/factory'; +import { externalSchoolDtoFactory, roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; +import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; +import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; +import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; +import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; import { AccountService } from '@src/modules/account'; import { ClassService } from '@src/modules/class'; import { classFactory } from '@src/modules/class/domain/testing'; diff --git a/apps/server/src/shared/testing/factory/index.ts b/apps/server/src/shared/testing/factory/index.ts index 8820070172d..d0d2e9568d9 100644 --- a/apps/server/src/shared/testing/factory/index.ts +++ b/apps/server/src/shared/testing/factory/index.ts @@ -41,14 +41,3 @@ export * from './user-and-account.test.factory'; export * from './user-login-migration.factory'; export * from './user.do.factory'; export * from './user.factory'; -export * from './external-class-dto.factory'; -export * from './oauth-data-dto.factory'; -export * from './provisioning-dto.factory'; -export * from './provisioning-system-dto.factory'; -export * from './external-user-dto.factory'; -export * from './robj-export-schule.factory'; -export * from './robj-export-klasse.factory'; -export * from './robj-export-lehrer.factory'; -export * from './robj-export-schueler.factory'; -export * from './robj-export-lehrer-migration.factory'; -export * from './robj-export-schueler-migration.factory'; From 2d49b6b57debbb3e44831e0caf52ad14334562a1 Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Wed, 18 Dec 2024 15:18:12 +0100 Subject: [PATCH 7/8] modify externalUserDtoFactory --- .../src/shared/testing/factory/external-user-dto.factory.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/server/src/shared/testing/factory/external-user-dto.factory.ts b/apps/server/src/shared/testing/factory/external-user-dto.factory.ts index 19ea7fb2119..f6e887439d1 100644 --- a/apps/server/src/shared/testing/factory/external-user-dto.factory.ts +++ b/apps/server/src/shared/testing/factory/external-user-dto.factory.ts @@ -1,5 +1,6 @@ -import { ExternalUserDto } from '@src/modules/provisioning'; import { ObjectId } from '@mikro-orm/mongodb'; +import { RoleName } from '@shared/domain/interface'; +import { ExternalUserDto } from '@src/modules/provisioning'; import { Factory } from 'fishery'; export const externalUserDtoFactory = Factory.define( @@ -9,5 +10,6 @@ export const externalUserDtoFactory = Factory.define Date: Thu, 19 Dec 2024 14:59:49 +0100 Subject: [PATCH 8/8] reorder test factories to main modules --- .../sync/tsp/tsp-oauth-data.mapper.spec.ts | 22 ++++++++++------ .../infra/sync/tsp/tsp-sync.strategy.spec.ts | 17 ++++++++----- .../src/infra/tsp-client/testing/index.ts | 6 +++++ .../testing}/robj-export-klasse.factory.ts | 0 .../robj-export-lehrer-migration.factory.ts | 0 .../testing}/robj-export-lehrer.factory.ts | 0 .../robj-export-schueler-migration.factory.ts | 0 .../testing}/robj-export-schueler.factory.ts | 0 .../testing}/robj-export-schule.factory.ts | 0 .../provisioning/dto/provisioning.dto.ts | 14 +++++------ ...chool-for-group-not-found.loggable.spec.ts | 3 +-- .../service/provisioning.service.spec.ts | 5 ++-- .../service/tsp-provisioning.service.spec.ts | 13 ++++++---- .../schulconnex/schulconnex.strategy.spec.ts | 10 ++------ ...lconnex-group-provisioning.service.spec.ts | 11 ++------ .../testing}/external-class-dto.factory.ts | 0 .../testing}/external-school-dto.factory.ts | 2 +- .../src/modules/provisioning/testing/index.ts | 5 ++++ .../testing}/oauth-data-dto.factory.ts | 0 .../testing}/provisioning-dto.factory.ts | 0 .../provisioning-system-dto.factory.ts | 0 .../factory/external-group-dto.factory.ts | 25 ------------------- .../factory/external-user-dto.factory.ts | 15 ----------- .../src/shared/testing/factory/index.ts | 2 -- 24 files changed, 59 insertions(+), 91 deletions(-) create mode 100644 apps/server/src/infra/tsp-client/testing/index.ts rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-klasse.factory.ts (100%) rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-lehrer-migration.factory.ts (100%) rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-lehrer.factory.ts (100%) rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-schueler-migration.factory.ts (100%) rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-schueler.factory.ts (100%) rename apps/server/src/{shared/testing/factory => infra/tsp-client/testing}/robj-export-schule.factory.ts (100%) rename apps/server/src/{shared/testing/factory => modules/provisioning/testing}/external-class-dto.factory.ts (100%) rename apps/server/src/{shared/testing/factory => modules/provisioning/testing}/external-school-dto.factory.ts (84%) rename apps/server/src/{shared/testing/factory => modules/provisioning/testing}/oauth-data-dto.factory.ts (100%) rename apps/server/src/{shared/testing/factory => modules/provisioning/testing}/provisioning-dto.factory.ts (100%) rename apps/server/src/{shared/testing/factory => modules/provisioning/testing}/provisioning-system-dto.factory.ts (100%) delete mode 100644 apps/server/src/shared/testing/factory/external-group-dto.factory.ts delete mode 100644 apps/server/src/shared/testing/factory/external-user-dto.factory.ts diff --git a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts index a8d4e6772c4..4b7dd9d571d 100644 --- a/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.spec.ts @@ -1,17 +1,21 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ProvisioningSystemDto } from '@modules/provisioning'; +import { + 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 { externalSchoolDtoFactory } from '@shared/testing'; -import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; -import { robjExportKlasseFactory } from '@shared/testing/factory/robj-export-klasse.factory'; -import { robjExportLehrerFactory } from '@shared/testing/factory/robj-export-lehrer.factory'; -import { robjExportSchuelerFactory } from '@shared/testing/factory/robj-export-schueler.factory'; +import { + robjExportSchuelerFactory, + robjExportLehrerFactory, + robjExportKlasseFactory, +} from '@src/infra/tsp-client/testing'; import { Logger } from '@src/core/logger'; import { BadDataLoggableException } from '@src/modules/provisioning/loggable'; import { schoolFactory } from '@src/modules/school/testing'; @@ -104,6 +108,7 @@ describe(TspOauthDataMapper.name, () => { lastName: tspTeachers[0].lehrerNachname, roles: [RoleName.TEACHER], email: undefined, + birthday: undefined, }); const externalStudentUserDto = externalUserDtoFactory.build({ @@ -112,6 +117,7 @@ describe(TspOauthDataMapper.name, () => { lastName: tspStudents[0].schuelerNachname, roles: [RoleName.STUDENT], email: undefined, + birthday: undefined, }); const externalSchoolDto = externalSchoolDtoFactory.build({ diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts index 1585a7fea7d..38f97f56db9 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts @@ -13,12 +13,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { UserDO } from '@shared/domain/domainobject'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { userDoFactory } from '@shared/testing'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; -import { robjExportLehrerMigrationFactory } from '@shared/testing/factory/robj-export-lehrer-migration.factory'; -import { robjExportSchuelerMigrationFactory } from '@shared/testing/factory/robj-export-schueler-migration.factory'; -import { robjExportSchuleFactory } from '@shared/testing/factory/robj-export-schule.factory'; + +import { + externalUserDtoFactory, + oauthDataDtoFactory, + provisioningSystemDtoFactory, +} from '@src/modules/provisioning/testing'; +import { + robjExportSchuleFactory, + robjExportLehrerMigrationFactory, + robjExportSchuelerMigrationFactory, +} from '@src/infra/tsp-client/testing'; import { Logger } from '@src/core/logger'; import { Account } from '@src/modules/account'; import { accountDoFactory } from '@src/modules/account/testing'; diff --git a/apps/server/src/infra/tsp-client/testing/index.ts b/apps/server/src/infra/tsp-client/testing/index.ts new file mode 100644 index 00000000000..84d95f3ceaa --- /dev/null +++ b/apps/server/src/infra/tsp-client/testing/index.ts @@ -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'; diff --git a/apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-klasse.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-klasse.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-klasse.factory.ts diff --git a/apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-lehrer-migration.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-lehrer-migration.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-lehrer-migration.factory.ts diff --git a/apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-lehrer.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-lehrer.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-lehrer.factory.ts diff --git a/apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-schueler-migration.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-schueler-migration.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-schueler-migration.factory.ts diff --git a/apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-schueler.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-schueler.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-schueler.factory.ts diff --git a/apps/server/src/shared/testing/factory/robj-export-schule.factory.ts b/apps/server/src/infra/tsp-client/testing/robj-export-schule.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/robj-export-schule.factory.ts rename to apps/server/src/infra/tsp-client/testing/robj-export-schule.factory.ts diff --git a/apps/server/src/modules/provisioning/dto/provisioning.dto.ts b/apps/server/src/modules/provisioning/dto/provisioning.dto.ts index 0c9bf53867b..f35fbc311d4 100644 --- a/apps/server/src/modules/provisioning/dto/provisioning.dto.ts +++ b/apps/server/src/modules/provisioning/dto/provisioning.dto.ts @@ -1,7 +1,7 @@ -export class ProvisioningDto { - externalUserId: string; - - constructor(provisioningDto: ProvisioningDto) { - this.externalUserId = provisioningDto.externalUserId; - } -} +export class ProvisioningDto { + externalUserId: string; + + constructor(provisioningDto: ProvisioningDto) { + this.externalUserId = provisioningDto.externalUserId; + } +} diff --git a/apps/server/src/modules/provisioning/loggable/school-for-group-not-found.loggable.spec.ts b/apps/server/src/modules/provisioning/loggable/school-for-group-not-found.loggable.spec.ts index 888a6a58514..1526b21dfba 100644 --- a/apps/server/src/modules/provisioning/loggable/school-for-group-not-found.loggable.spec.ts +++ b/apps/server/src/modules/provisioning/loggable/school-for-group-not-found.loggable.spec.ts @@ -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'; diff --git a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts index b86324b50ec..3a62d5cea50 100644 --- a/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/provisioning.service.spec.ts @@ -3,9 +3,8 @@ import { System, SystemService } from '@modules/system'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningDtoFactory } from '@shared/testing/factory/provisioning-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { provisioningDtoFactory, oauthDataDtoFactory } from '@modules/provisioning/testing'; +import { provisioningSystemDtoFactory } from '@src/modules/provisioning/testing/provisioning-system-dto.factory'; import { systemFactory } from '@src/modules/system/testing'; import { OauthDataDto, OauthDataStrategyInputDto, ProvisioningDto, ProvisioningSystemDto } from '../dto'; import { IservProvisioningStrategy, OidcMockProvisioningStrategy, SanisProvisioningStrategy } from '../strategy'; diff --git a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts index c2ed303cd63..d8e9963db7d 100644 --- a/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/service/tsp-provisioning.service.spec.ts @@ -3,11 +3,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { RoleName } from '@shared/domain/interface'; -import { externalSchoolDtoFactory, roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; -import { externalClassDtoFactory } from '@shared/testing/factory/external-class-dto.factory'; -import { externalUserDtoFactory } from '@shared/testing/factory/external-user-dto.factory'; -import { oauthDataDtoFactory } from '@shared/testing/factory/oauth-data-dto.factory'; -import { provisioningSystemDtoFactory } from '@shared/testing/factory/provisioning-system-dto.factory'; +import { roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; import { AccountService } from '@src/modules/account'; import { ClassService } from '@src/modules/class'; import { classFactory } from '@src/modules/class/domain/testing'; @@ -17,6 +13,13 @@ import { schoolFactory } from '@src/modules/school/testing'; import { UserService } from '@src/modules/user'; import { BadDataLoggableException } from '../loggable'; import { TspProvisioningService } from './tsp-provisioning.service'; +import { + provisioningSystemDtoFactory, + externalClassDtoFactory, + oauthDataDtoFactory, + externalUserDtoFactory, + externalSchoolDtoFactory, +} from '../testing'; describe('TspProvisioningService', () => { let module: TestingModule; diff --git a/apps/server/src/modules/provisioning/strategy/schulconnex/schulconnex.strategy.spec.ts b/apps/server/src/modules/provisioning/strategy/schulconnex/schulconnex.strategy.spec.ts index f86346d37eb..8bbde69d3fe 100644 --- a/apps/server/src/modules/provisioning/strategy/schulconnex/schulconnex.strategy.spec.ts +++ b/apps/server/src/modules/provisioning/strategy/schulconnex/schulconnex.strategy.spec.ts @@ -7,13 +7,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { LegacySchoolDo, UserDO } from '@shared/domain/domainobject'; import { RoleName } from '@shared/domain/interface'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { - externalGroupDtoFactory, - externalSchoolDtoFactory, - groupFactory, - legacySchoolDoFactory, - userDoFactory, -} from '@shared/testing'; +import { groupFactory, legacySchoolDoFactory, userDoFactory } from '@shared/testing'; import { Logger } from '@src/core/logger'; import { ExternalGroupDto, @@ -24,7 +18,7 @@ import { ProvisioningSystemDto, } from '../../dto'; import { ProvisioningConfig } from '../../provisioning.config'; -import { externalUserDtoFactory } from '../../testing'; +import { externalGroupDtoFactory, externalSchoolDtoFactory, externalUserDtoFactory } from '../../testing'; import { SchulconnexProvisioningStrategy } from './schulconnex.strategy'; import { SchulconnexCourseSyncService, diff --git a/apps/server/src/modules/provisioning/strategy/schulconnex/service/schulconnex-group-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/strategy/schulconnex/service/schulconnex-group-provisioning.service.spec.ts index f5d48e48d4f..e005b01873b 100644 --- a/apps/server/src/modules/provisioning/strategy/schulconnex/service/schulconnex-group-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/strategy/schulconnex/service/schulconnex-group-provisioning.service.spec.ts @@ -16,16 +16,9 @@ import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { ExternalSource, LegacySchoolDo, Page, RoleReference, UserDO } from '@shared/domain/domainobject'; import { RoleName } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { - externalGroupDtoFactory, - externalSchoolDtoFactory, - groupFactory, - legacySchoolDoFactory, - roleDtoFactory, - roleFactory, - userDoFactory, -} from '@shared/testing'; +import { groupFactory, legacySchoolDoFactory, roleDtoFactory, roleFactory, userDoFactory } from '@shared/testing'; import { Logger } from '@src/core/logger'; +import { externalGroupDtoFactory, externalSchoolDtoFactory } from '@modules/provisioning/testing'; import { ExternalGroupDto, ExternalSchoolDto } from '../../../dto'; import { SchoolForGroupNotFoundLoggable, UserForGroupNotFoundLoggable } from '../../../loggable'; import { SchulconnexGroupProvisioningService } from './schulconnex-group-provisioning.service'; diff --git a/apps/server/src/shared/testing/factory/external-class-dto.factory.ts b/apps/server/src/modules/provisioning/testing/external-class-dto.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/external-class-dto.factory.ts rename to apps/server/src/modules/provisioning/testing/external-class-dto.factory.ts diff --git a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts b/apps/server/src/modules/provisioning/testing/external-school-dto.factory.ts similarity index 84% rename from apps/server/src/shared/testing/factory/external-school-dto.factory.ts rename to apps/server/src/modules/provisioning/testing/external-school-dto.factory.ts index 21f35cf0f03..31d93c4924e 100644 --- a/apps/server/src/shared/testing/factory/external-school-dto.factory.ts +++ b/apps/server/src/modules/provisioning/testing/external-school-dto.factory.ts @@ -1,6 +1,6 @@ import { ObjectId } from '@mikro-orm/mongodb'; import { ExternalSchoolDto } from '@modules/provisioning/dto'; -import { BaseFactory } from './base.factory'; +import { BaseFactory } from '../../../shared/testing/factory/base.factory'; class ExternalSchoolDtoFactory extends BaseFactory> {} diff --git a/apps/server/src/modules/provisioning/testing/index.ts b/apps/server/src/modules/provisioning/testing/index.ts index 32854894142..4d180c58f64 100644 --- a/apps/server/src/modules/provisioning/testing/index.ts +++ b/apps/server/src/modules/provisioning/testing/index.ts @@ -1,3 +1,8 @@ export { externalUserDtoFactory } from './external-user-dto.factory'; export { externalGroupDtoFactory } from './external-group-dto.factory'; export { externalGroupUserDtoFactory } from './external-group-user-dto.factory'; +export { oauthDataDtoFactory } from './oauth-data-dto.factory'; +export { externalClassDtoFactory } from './external-class-dto.factory'; +export { externalSchoolDtoFactory } from './external-school-dto.factory'; +export { provisioningSystemDtoFactory } from './provisioning-system-dto.factory'; +export { provisioningDtoFactory } from './provisioning-dto.factory'; diff --git a/apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts b/apps/server/src/modules/provisioning/testing/oauth-data-dto.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/oauth-data-dto.factory.ts rename to apps/server/src/modules/provisioning/testing/oauth-data-dto.factory.ts diff --git a/apps/server/src/shared/testing/factory/provisioning-dto.factory.ts b/apps/server/src/modules/provisioning/testing/provisioning-dto.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/provisioning-dto.factory.ts rename to apps/server/src/modules/provisioning/testing/provisioning-dto.factory.ts diff --git a/apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts b/apps/server/src/modules/provisioning/testing/provisioning-system-dto.factory.ts similarity index 100% rename from apps/server/src/shared/testing/factory/provisioning-system-dto.factory.ts rename to apps/server/src/modules/provisioning/testing/provisioning-system-dto.factory.ts diff --git a/apps/server/src/shared/testing/factory/external-group-dto.factory.ts b/apps/server/src/shared/testing/factory/external-group-dto.factory.ts deleted file mode 100644 index a6172ff6acf..00000000000 --- a/apps/server/src/shared/testing/factory/external-group-dto.factory.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { GroupTypes } from '@modules/group'; -import { ExternalGroupDto } from '@modules/provisioning/dto'; -import { RoleName } from '@shared/domain/interface'; -import { ObjectId } from '@mikro-orm/mongodb'; -import { Factory } from 'fishery'; - -export const externalGroupDtoFactory = Factory.define(({ sequence }) => { - return { - externalId: new ObjectId().toHexString(), - name: `Group ${sequence}`, - type: GroupTypes.CLASS, - user: { - externalUserId: new ObjectId().toHexString(), - roleName: RoleName.TEACHER, - }, - otherUsers: [ - { - externalUserId: new ObjectId().toHexString(), - roleName: RoleName.STUDENT, - }, - ], - from: new Date(2023, 1), - until: new Date(2023, 6), - }; -}); diff --git a/apps/server/src/shared/testing/factory/external-user-dto.factory.ts b/apps/server/src/shared/testing/factory/external-user-dto.factory.ts deleted file mode 100644 index f6e887439d1..00000000000 --- a/apps/server/src/shared/testing/factory/external-user-dto.factory.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ObjectId } from '@mikro-orm/mongodb'; -import { RoleName } from '@shared/domain/interface'; -import { ExternalUserDto } from '@src/modules/provisioning'; -import { Factory } from 'fishery'; - -export const externalUserDtoFactory = Factory.define( - ({ sequence }) => - new ExternalUserDto({ - externalId: new ObjectId().toHexString(), - firstName: `Firstname ${sequence}`, - lastName: `Lastname ${sequence}`, - email: `Email ${sequence}`, - roles: [RoleName.STUDENT], - }) -); diff --git a/apps/server/src/shared/testing/factory/index.ts b/apps/server/src/shared/testing/factory/index.ts index d0d2e9568d9..9a6500b12c5 100644 --- a/apps/server/src/shared/testing/factory/index.ts +++ b/apps/server/src/shared/testing/factory/index.ts @@ -10,8 +10,6 @@ export * from './coursegroup.factory'; export * from './currentuser.factory'; export * from './domainobject'; export * from './entity.factory'; -export * from './external-group-dto.factory'; -export { externalSchoolDtoFactory } from './external-school-dto.factory'; export * from './external-tool-pseudonym.factory'; export * from './federal-state.factory'; export * from './filerecord.factory';