diff --git a/apps/api/src/instrument-records/__tests__/instrument-records.service.spec.ts b/apps/api/src/instrument-records/__tests__/instrument-records.service.spec.ts index 6974ccade..fbf409bd9 100644 --- a/apps/api/src/instrument-records/__tests__/instrument-records.service.spec.ts +++ b/apps/api/src/instrument-records/__tests__/instrument-records.service.spec.ts @@ -240,8 +240,6 @@ describe('InstrumentRecordsService', () => { expect(sessionsService.create).toHaveBeenCalledWith(expect.objectContaining({ username: undefined })); }); - // `pending` is intentionally not written on create; the find-side OR filter treats missing and - // false `pending` alike (see the 'find' describe block), so records stay query-visible without it. it('should create records via createMany with the processed record data', async () => { await instrumentRecordsService.upload({ ...baseUploadData }); @@ -249,6 +247,24 @@ describe('InstrumentRecordsService', () => { data: [expect.objectContaining({ instrumentId: 'instrument-1', subjectId: 'subject-1' })] }); }); + + it('should settle a form instrument record, since an upload carries its data in full', async () => { + await instrumentRecordsService.upload({ ...baseUploadData }); + + expect(instrumentRecordModel.createMany).toHaveBeenCalledWith({ + data: [expect.objectContaining({ pending: false })] + }); + }); + + it('should leave a file instrument record pending, so its files can still be attached', async () => { + instrumentsService.findById.mockResolvedValue({ ...mockInstrument, kind: 'FILE' } as any); + + await instrumentRecordsService.upload({ ...baseUploadData }); + + expect(instrumentRecordModel.createMany).toHaveBeenCalledWith({ + data: [expect.objectContaining({ pending: true })] + }); + }); }); describe('find', () => { diff --git a/apps/api/src/instrument-records/instrument-records.service.ts b/apps/api/src/instrument-records/instrument-records.service.ts index e3fc2b682..188a9def6 100644 --- a/apps/api/src/instrument-records/instrument-records.service.ts +++ b/apps/api/src/instrument-records/instrument-records.service.ts @@ -445,7 +445,7 @@ export class InstrumentRecordsService { date, groupId, instrumentId, - pending: false, + pending: instrument.kind === 'FILE', sessionId: session.id, subjectId };