11import { describe , expect , it } from 'vitest'
2- import type { SafeParseError } from 'zod'
32
43import 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 : {
0 commit comments