Skip to content

Commit 1a555d6

Browse files
committed
feat: store last test submission date for frontend rendering
1 parent 997e1da commit 1a555d6

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

packages/backend/src/apps/formsg/__tests__/triggers/new-submission.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,25 @@ describe('new submission trigger', () => {
100100
raw: mockData,
101101
meta: {
102102
internalId: '',
103+
isMock: true,
104+
lastTestSubmissionDate: undefined,
103105
},
104-
isMock: true,
105106
})
106107
})
107108

108109
it('should use mock data if preferMock is true even though there is past submission', async () => {
109-
getLastExecutionStepMock.mockResolvedValue({ dataOut: actualData })
110+
getLastExecutionStepMock.mockResolvedValue({
111+
dataOut: actualData,
112+
createdAt: '2025-06-16 07:06:30.155+00',
113+
})
110114
await trigger.testRun($, { preferMock: true })
111115
expect(pushTriggerItemMock).toHaveBeenCalledWith({
112116
raw: mockData,
113117
meta: {
114118
internalId: '',
119+
isMock: true,
120+
lastTestSubmissionDate: '2025-06-16 07:06:30.155+00',
115121
},
116-
isMock: true,
117122
})
118123
})
119124

@@ -124,32 +129,41 @@ describe('new submission trigger', () => {
124129
raw: mockData,
125130
meta: {
126131
internalId: '',
132+
isMock: true,
133+
lastTestSubmissionDate: undefined,
127134
},
128-
isMock: true,
129135
})
130136
})
131137

132138
it('should use last test submission if testRunMetadata is undefined and there is past submission', async () => {
133-
getLastExecutionStepMock.mockResolvedValue({ dataOut: actualData })
139+
getLastExecutionStepMock.mockResolvedValue({
140+
dataOut: actualData,
141+
createdAt: '2025-06-16 07:06:30.155+00',
142+
})
134143
await trigger.testRun($, undefined)
135144
expect(pushTriggerItemMock).toHaveBeenCalledWith({
136145
raw: actualData,
137146
meta: {
138147
internalId: '',
148+
isMock: false,
149+
lastTestSubmissionDate: '2025-06-16 07:06:30.155+00',
139150
},
140-
isMock: false,
141151
})
142152
})
143153

144154
it('should use last test submission if preferMock is false and there is past submission', async () => {
145-
getLastExecutionStepMock.mockResolvedValue({ dataOut: actualData })
155+
getLastExecutionStepMock.mockResolvedValue({
156+
dataOut: actualData,
157+
createdAt: '2025-06-16 07:06:30.155+00',
158+
})
146159
await trigger.testRun($, { preferMock: false })
147160
expect(pushTriggerItemMock).toHaveBeenCalledWith({
148161
raw: actualData,
149162
meta: {
150163
internalId: '',
164+
isMock: false,
165+
lastTestSubmissionDate: '2025-06-16 07:06:30.155+00',
151166
},
152-
isMock: false,
153167
})
154168
})
155169

@@ -160,8 +174,9 @@ describe('new submission trigger', () => {
160174
raw: mockData,
161175
meta: {
162176
internalId: '',
177+
isMock: true,
178+
lastTestSubmissionDate: undefined,
163179
},
164-
isMock: true,
165180
})
166181
})
167182
})

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ type ExecutionStep {
320320

321321
type ExecutionStepMetadata {
322322
isMock: Boolean
323+
lastTestSubmissionDate: String
323324
}
324325

325326
type Field {

packages/backend/src/models/execution-step.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class ExecutionStep extends Base {
4141
isMock: {
4242
type: 'boolean',
4343
},
44+
// this is purely used to tell frontend that there is a past test submission
45+
lastTestSubmissionDate: {
46+
type: 'string',
47+
},
4448
},
4549
},
4650
},

packages/backend/src/services/trigger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export const processTrigger = async (options: ProcessTriggerOptions) => {
7979
...(error && { status: 'failure' }),
8080
})
8181

82+
// We store all metadata except internalId
83+
const { internalId: _, ...metadataToStore } = triggerItem?.meta ?? {}
84+
8285
const executionStep = await execution
8386
.$relatedQuery('executionSteps')
8487
.insertAndFetch({
@@ -88,7 +91,7 @@ export const processTrigger = async (options: ProcessTriggerOptions) => {
8891
dataOut: !error ? triggerItem?.raw : null,
8992
errorDetails: error,
9093
appKey: step.appKey,
91-
metadata: triggerItem?.isMock ? { isMock: true } : {},
94+
metadata: metadataToStore ?? {},
9295
})
9396

9497
return {

packages/types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface IExecutionStep {
121121

122122
export interface IExecutionStepMetadata {
123123
isMock?: boolean
124+
lastTestSubmissionDate?: string
124125
}
125126

126127
export interface IExecution {
@@ -627,8 +628,8 @@ export interface ITriggerItem {
627628
raw: IJSONObject
628629
meta: {
629630
internalId: string
631+
[key: string]: unknown
630632
}
631-
isMock?: boolean
632633
}
633634

634635
export type ITriggerInstructions = Partial<{

0 commit comments

Comments
 (0)