Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/src/db/entities/AttendanceCleanupRule.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
Comment thread
buzz-code marked this conversation as resolved.
Resolved

this.lessonId = await findOneAndAssignKey(dataSource, Lesson, this.userId, this.lessonReferenceId, this.lessonId);
this.klassId = await findOneAndAssignKey(dataSource, Klass, this.userId, this.klassReferenceId, this.klassId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
});
Loading