@@ -18,8 +18,20 @@ type FormField = {
1818 othersRadioButton ?: boolean
1919}
2020
21+ // Adapted from https://github.com/opengovsg/FormSG/blob/82c5ba6fff7e9628b6c32449148e89c0224e9ff5/shared/types/form/form.ts#L96
22+ type PaymentProduct = {
23+ _id : string
24+ name : string
25+ description : string
26+ multi_qty : boolean
27+ min_qty : number
28+ max_qty : number
29+ amount_cents : number
30+ }
31+
2132export const MOCK_ATTACHMENT_FILE_PATH = `${ COMMON_S3_MOCK_FOLDER_PREFIX } plumber-logo.jpg`
2233const MOCK_NRIC = 'S1234568B'
34+ const MOCK_UEN = '201612345A'
2335
2436function generateVerifiedSubmitterInfoData (
2537 authType : string ,
@@ -41,10 +53,43 @@ function generateVerifiedSubmitterInfoData(
4153 uinFin : filteredNric ,
4254 } ,
4355 }
56+ case 'CP' :
57+ return {
58+ verifiedSubmitterInfo : {
59+ cpUid : filteredNric ,
60+ cpUen : MOCK_UEN ,
61+ } ,
62+ }
4463 }
4564 return { }
4665}
4766
67+ function generateMockPaymentData ( products : Partial < PaymentProduct > [ ] ) {
68+ // if there are no payment products, default to a mocked one
69+ const firstProduct : Partial < PaymentProduct > =
70+ products . length > 0
71+ ? products [ 0 ]
72+ : {
73+ name : 'Test Product' ,
74+ amount_cents : 123 ,
75+ }
76+
77+ // Only the amount and product service is ideally obtainable based on their form data
78+ return {
79+ paymentContent : {
80+ type : 'payment_charge' ,
81+ status : 'succeeded' ,
82+ 83+ url : 'https://form.gov.sg/api/v3/payments/abcde/12345/invoice/download' ,
84+ paymentIntent : 'pi_12345' ,
85+ amount : ( firstProduct . amount_cents / 100 ) . toFixed ( 2 ) ,
86+ productService : firstProduct . name ,
87+ dateTime : new Date ( ) . toISOString ( ) ,
88+ transactionFee : '0.05' ,
89+ } ,
90+ }
91+ }
92+
4893async function getMockData ( $ : IGlobalVariable ) {
4994 try {
5095 const { formId } = getFormDetailsFromGlobalVariable ( $ )
@@ -80,6 +125,10 @@ async function getMockData($: IGlobalVariable) {
80125 )
81126 }
82127
128+ if ( data . responses [ formFields [ i ] . _id ] . fieldType === 'email' ) {
129+ data . responses [ formFields [ i ] . _id ] . answer = $ . user . email
130+ }
131+
83132 data . responses [ formFields [ i ] . _id ] . order = i + 1
84133 data . responses [ formFields [ i ] . _id ] . id = undefined
85134 }
@@ -95,7 +144,10 @@ async function getMockData($: IGlobalVariable) {
95144 submissionId : await generateIdAsync ( ) ,
96145 submissionTime : DateTime . now ( ) . toISO ( ) ,
97146 formId,
98- ...generateVerifiedSubmitterInfoData ( formDetails . form . authType , $ ) ,
147+ ...( formDetails . form . isSubmitterIdCollectionEnabled &&
148+ generateVerifiedSubmitterInfoData ( formDetails . form . authType , $ ) ) ,
149+ ...( formDetails . form . payments_field . enabled &&
150+ generateMockPaymentData ( formDetails . form . payments_field . products ) ) ,
99151 }
100152 } catch ( e ) {
101153 throw new Error (
0 commit comments