Skip to content

Commit 2d153ae

Browse files
committed
chore: change checks to nullish just in case
1 parent 0c4aeec commit 2d153ae

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

packages/backend/src/apps/gathersg/__tests__/auth/schema.test.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describe, expect, it } from 'vitest'
2-
import type { SafeParseError } from 'zod'
32

43
import schema from '../../auth/schema'
54

@@ -96,12 +95,16 @@ describe('gathersg auth schema', () => {
9695
},
9796
})
9897
expect(result.success).toBe(false)
99-
if (!result.success) {
100-
const { issues } = (result as SafeParseError<unknown>).error
101-
expect(
102-
issues.some((i) => i.message.includes('createdBy.email is required')),
103-
).toBe(true)
104-
}
98+
})
99+
100+
it('rejects createdBy with email null when not FormSG', () => {
101+
const result = schema.safeParse({
102+
createdBy: {
103+
name: 'Regular User',
104+
email: null,
105+
},
106+
})
107+
expect(result.success).toBe(false)
105108
})
106109

107110
it('rejects when both updatedBy and createdBy exist but updatedBy has no email', () => {
@@ -117,6 +120,20 @@ describe('gathersg auth schema', () => {
117120
expect(result.success).toBe(false)
118121
})
119122

123+
it('rejects when both updatedBy and createdBy exist but updatedBy email is null', () => {
124+
const result = schema.safeParse({
125+
updatedBy: {
126+
name: 'Updater',
127+
email: null,
128+
},
129+
createdBy: {
130+
131+
name: 'Creator',
132+
},
133+
})
134+
expect(result.success).toBe(false)
135+
})
136+
120137
it('rejects empty object (neither updatedBy nor createdBy)', () => {
121138
const result = schema.safeParse({})
122139
expect(result.success).toBe(false)
@@ -156,6 +173,19 @@ describe('gathersg auth schema', () => {
156173
expect(result.success).toBe(false)
157174
})
158175

176+
it('rejects FormSG createdBy with submissionId null', () => {
177+
const result = schema.safeParse({
178+
createdBy: {
179+
name: 'FormSG',
180+
},
181+
formsg: {
182+
formId: 'form-123',
183+
submissionId: null,
184+
},
185+
})
186+
expect(result.success).toBe(false)
187+
})
188+
159189
it('rejects FormSG createdBy with empty formId', () => {
160190
const result = schema.safeParse({
161191
createdBy: {

packages/backend/src/apps/gathersg/auth/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const schema = z
1616
.nullish(),
1717
createdBy: z
1818
.object({
19-
email: z.string().min(1).optional(),
20-
name: z.string().min(1).optional(),
19+
email: z.string().min(1).nullish(),
20+
name: z.string().min(1).nullish(),
2121
})
2222
.nullish(),
2323
formsg: z

0 commit comments

Comments
 (0)