diff --git a/server/src/db/entities/AttendanceCleanupRule.entity.ts b/server/src/db/entities/AttendanceCleanupRule.entity.ts index e9f6dc33..15d6789f 100644 --- a/server/src/db/entities/AttendanceCleanupRule.entity.ts +++ b/server/src/db/entities/AttendanceCleanupRule.entity.ts @@ -19,7 +19,10 @@ import { StringType, NumberType } from '@shared/utils/entity/class-transformer'; import { CreatedAtColumn, UpdatedAtColumn } from '@shared/utils/entity/column-types.util'; import { Lesson } from './Lesson.entity'; import { Klass } from './Klass.entity'; +import { KlassType } from './KlassType.entity'; +import { Teacher } from './Teacher.entity'; import { User } from './User.entity'; +import { LessonKlassName } from '../view-entities/LessonKlassName.entity'; /** * A recurring attendance-cleanup rule: on `dayOfWeek`, delete att_reports for @@ -46,7 +49,7 @@ export class AttendanceCleanupRule implements IHasUserId { async fillFields() { let dataSource: DataSource; try { - dataSource = await getDataSource([Lesson, Klass, User]); + dataSource = await getDataSource([Lesson, Klass, KlassType, Teacher, User, LessonKlassName]); this.lessonId = await findOneAndAssignKey(dataSource, Lesson, this.userId, this.lessonReferenceId, this.lessonId); this.klassId = await findOneAndAssignKey(dataSource, Klass, this.userId, this.klassReferenceId, this.klassId); diff --git a/server/src/jobs/__tests__/attendance-cleanup-rule.entity.datasource.spec.ts b/server/src/jobs/__tests__/attendance-cleanup-rule.entity.datasource.spec.ts new file mode 100644 index 00000000..d44d6fbe --- /dev/null +++ b/server/src/jobs/__tests__/attendance-cleanup-rule.entity.datasource.spec.ts @@ -0,0 +1,14 @@ +import { AttendanceCleanupRule } from 'src/db/entities/AttendanceCleanupRule.entity'; + +// Unlike attendance-cleanup-rule.entity.spec.ts, getDataSource here is NOT mocked - +// this exercises the real TypeORM metadata build (against Jest's sqlite in-memory +// databaseConfig) so an entity closure that's missing a relation target (as happened +// in production - Klass#klassType) fails this test instead of only failing at runtime. +describe('AttendanceCleanupRule.fillFields (real DataSource)', () => { + it('builds TypeORM metadata for the full entity set without throwing', async () => { + const rule = new AttendanceCleanupRule(); + rule.userId = 1; + + await rule.fillFields(); + }); +});