Skip to content

Commit

Permalink
EW-1159: Fix RangeError for too many students in TSP Sync. (#5566)
Browse files Browse the repository at this point in the history
* EW-1159: Fix RangeError for too many students in TSP Sync.

* Add test.

---------

Co-authored-by: Simone Radtke <[email protected]>
  • Loading branch information
2 people authored and virgilchiriac committed Mar 6, 2025
1 parent 254f390 commit 7733840
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ describe(TspOauthDataMapper.name, () => {
});
});

describe('when handling large amounts', () => {
const setup = () => {
const system = systemFactory.build();

const school = schoolFactory.build({
externalId: faker.string.uuid(),
});

const lehrerUid = faker.string.uuid();

const tspTeachers = robjExportLehrerFactory.buildList(1000000, {
lehrerUid,
schuleNummer: school.externalId,
});

const tspClasses = [];

const tspStudents = robjExportSchuelerFactory.buildList(1000000);

return { system, school, tspTeachers, tspStudents, tspClasses };
};

it('should not throw RangeError', () => {
const { system, school, tspTeachers, tspStudents, tspClasses } = setup();

expect(() => sut.mapTspDataToOauthData(system, [school], tspTeachers, tspStudents, tspClasses)).not.toThrow(
RangeError
);
});
});

describe('when school has to externalId', () => {
const setup = () => {
const system = systemFactory.build();
Expand Down
29 changes: 16 additions & 13 deletions apps/server/src/infra/sync/strategy/tsp/tsp-oauth-data.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ export class TspOauthDataMapper {
const oauthDataDtos: OauthDataDto[] = [];
const usersOfClasses = new Map<string, TspUserInfo[]>();

oauthDataDtos.push(
...this.mapTspTeachersToOauthDataDtos(
tspTeachers,
systemDto,
externalSchools,
externalClasses,
teacherForClasses,
usersOfClasses
)
);
oauthDataDtos.push(
...this.mapTspStudentsToOauthDataDtos(tspStudents, systemDto, externalSchools, externalClasses, usersOfClasses)
);
this.mapTspTeachersToOauthDataDtos(
tspTeachers,
systemDto,
externalSchools,
externalClasses,
teacherForClasses,
usersOfClasses
).forEach((oauthDataDto) => oauthDataDtos.push(oauthDataDto));

this.mapTspStudentsToOauthDataDtos(
tspStudents,
systemDto,
externalSchools,
externalClasses,
usersOfClasses
).forEach((oauthDataDto) => oauthDataDtos.push(oauthDataDto));

return { oauthDataDtos, usersOfClasses };
}
Expand Down

0 comments on commit 7733840

Please sign in to comment.