@@ -353,6 +353,40 @@ describe('support', () => {
353353 } )
354354 ) . rejects . toEqual ( AppError . missingRequestParameter ( 'email' ) ) ;
355355 } ) ;
356+
357+ it ( 'should submit a ticket with a valid brand_id' , async ( ) => {
358+ config . subscriptions . enabled = true ;
359+ nock ( `https://${ SUBDOMAIN } .zendesk.com` )
360+ . post ( '/api/v2/requests.json' )
361+ . reply ( 201 , MOCK_CREATE_REPLY ) ;
362+ nock ( `https://${ SUBDOMAIN } .zendesk.com` )
363+ . get ( `/api/v2/users/${ REQUESTER_ID } .json` )
364+ . reply ( 200 , MOCK_EXISTING_SHOW_REPLY ) ;
365+ const spy = sinon . spy ( zendeskClient . requests , 'create' ) ;
366+ const res = await runTest ( '/support/ticket' , {
367+ ...requestOptions ,
368+ payload : { ...requestOptions . payload , brand_id : 12345 } ,
369+ } ) ;
370+ const zendeskReq = spy . firstCall . args [ 0 ] . request ;
371+ expect ( zendeskReq . brand_id ) . toBe ( 12345 ) ;
372+ expect ( res ) . toEqual ( { success : true , ticket : 91 } ) ;
373+ nock . isDone ( ) ;
374+ spy . restore ( ) ;
375+ } ) ;
376+
377+ it ( 'should reject a ticket with a non-integer brand_id' , async ( ) => {
378+ config . subscriptions . enabled = true ;
379+ const route = getRoute (
380+ supportRoutes ( log , db , config , customs , zendeskClient ) ,
381+ '/support/ticket' ,
382+ 'POST'
383+ ) ;
384+ const result = route . options . validate . payload . validate ( {
385+ ...requestOptions . payload ,
386+ brand_id : 12.5 ,
387+ } ) ;
388+ expect ( result . error ) . toBeTruthy ( ) ;
389+ } ) ;
356390 } ) ;
357391 } ) ;
358392} ) ;
0 commit comments