@@ -330,4 +330,166 @@ describe('Payment API test', () => {
330330 expect ( res . body ) . toHaveProperty ( 'message' ) ;
331331 expect ( res . body . message ) . toBe ( 'OK' ) ;
332332 } ) ;
333+
334+ test ( 'Stripe Session CCS Cloud Session ID Missing' , async ( ) => {
335+ const res = await agent
336+ . post ( '/api/payment/sessionRegister' )
337+ . send ( { sessionId : '' } ) ;
338+
339+ expect ( res . status ) . toBe ( 500 ) ;
340+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
341+ expect ( res . body . message [ 0 ] . msg ) . toBe ( 'Session ID is required' ) ;
342+ } ) ;
343+
344+ test ( 'Stripe Session CCS Cloud Post Contact Fail' , async ( ) => {
345+ jest . spyOn ( apiCall , 'getStripeSessionData' ) . mockImplementationOnce (
346+ ( ) => {
347+ return {
348+ status : 'complete' ,
349+ custom_fields : [
350+ { key : 'uhID' , numeric : { value : 1234567 } } ,
351+ { key : 'shirtSize' , dropdown : { value : 'M' } } ,
352+ ] ,
353+ metadata : { tenure : 'semester' } ,
354+ } ;
355+ }
356+ ) ;
357+
358+ jest . spyOn ( apiCall , 'getStripeCustomerData' ) . mockImplementationOnce (
359+ ( ) => {
360+ return {
361+ name : 'John Doe' ,
362+ 363+ phone : '123-456-7890' ,
364+ } ;
365+ }
366+ ) ;
367+
368+ jest . spyOn ( apiCall , 'sendEmail' ) . mockImplementationOnce ( ( ) => true ) ;
369+
370+ jest . spyOn ( apiCall , 'postContact' ) . mockImplementationOnce ( ( ) => {
371+ throw new Error ( ) ;
372+ } ) ;
373+
374+ const res = await agent . post ( '/api/payment/sessionRegister' ) . send ( {
375+ sessionId :
376+ 'cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u' ,
377+ } ) ;
378+
379+ expect ( res . status ) . toBe ( 500 ) ;
380+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
381+ expect ( res . body . message ) . toBe ( 'Failed to write to DB' ) ;
382+ } ) ;
383+
384+ test ( 'Stripe Session CCS Cloud Post Contact' , async ( ) => {
385+ jest . spyOn ( apiCall , 'getStripeSessionData' ) . mockImplementationOnce (
386+ ( ) => {
387+ return {
388+ status : 'complete' ,
389+ custom_fields : [
390+ { key : 'uhID' , numeric : { value : 1234567 } } ,
391+ { key : 'shirtSize' , dropdown : { value : 'M' } } ,
392+ ] ,
393+ metadata : { tenure : 'semester' } ,
394+ } ;
395+ }
396+ ) ;
397+
398+ jest . spyOn ( apiCall , 'getStripeCustomerData' ) . mockImplementationOnce (
399+ ( ) => {
400+ return {
401+ name : 'John Doe' ,
402+ 403+ phone : '123-456-7890' ,
404+ } ;
405+ }
406+ ) ;
407+
408+ jest . spyOn ( apiCall , 'postContact' ) . mockImplementationOnce ( ( ) => true ) ;
409+
410+ const res = await agent . post ( '/api/payment/sessionRegister' ) . send ( {
411+ sessionId :
412+ 'cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u' ,
413+ } ) ;
414+
415+ expect ( res . status ) . toBe ( 200 ) ;
416+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
417+ expect ( res . body . message ) . toBe ( 'OK' ) ;
418+ } ) ;
419+
420+ test ( 'Stripe Session CCS Cloud Get Session Fail' , async ( ) => {
421+ jest . spyOn ( apiCall , 'getStripeSessionData' ) . mockImplementationOnce (
422+ ( ) => {
423+ throw new Error ( ) ;
424+ }
425+ ) ;
426+
427+ jest . spyOn ( apiCall , 'sendEmail' ) . mockImplementationOnce ( ( ) => true ) ;
428+
429+ const res = await agent . post ( '/api/payment/sessionRegister' ) . send ( {
430+ sessionId :
431+ 'cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u' ,
432+ } ) ;
433+
434+ expect ( res . status ) . toBe ( 500 ) ;
435+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
436+ expect ( res . body . message ) . toBe ( 'Failed to retrieve session' ) ;
437+ } ) ;
438+
439+ test ( 'Stripe Session CCS Cloud Invalid Session' , async ( ) => {
440+ jest . spyOn ( apiCall , 'getStripeSessionData' ) . mockImplementationOnce (
441+ ( ) => null
442+ ) ;
443+
444+ jest . spyOn ( apiCall , 'getStripeCustomerData' ) . mockImplementationOnce (
445+ ( ) => null
446+ ) ;
447+
448+ jest . spyOn ( apiCall , 'postContact' ) . mockImplementationOnce ( ( ) => true ) ;
449+
450+ jest . spyOn ( apiCall , 'sendEmail' ) . mockImplementationOnce ( ( ) => true ) ;
451+
452+ const res = await agent . post ( '/api/payment/sessionRegister' ) . send ( {
453+ sessionId :
454+ 'cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u' ,
455+ } ) ;
456+
457+ expect ( res . status ) . toBe ( 500 ) ;
458+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
459+ expect ( res . body . message ) . toBe ( 'Payment incomplete or invalid.' ) ;
460+ } ) ;
461+
462+ test ( 'Stripe Session CCS Cloud Invalid Customer' , async ( ) => {
463+ jest . spyOn ( apiCall , 'getStripeSessionData' ) . mockImplementationOnce (
464+ ( ) => {
465+ return {
466+ status : 'complete' ,
467+ custom_fields : [
468+ { key : 'uhID' , numeric : { value : 1234567 } } ,
469+ { key : 'shirtSize' , dropdown : { value : 'M' } } ,
470+ ] ,
471+ metadata : { tenure : 'semester' } ,
472+ } ;
473+ }
474+ ) ;
475+
476+ jest . spyOn ( apiCall , 'getStripeCustomerData' ) . mockImplementationOnce (
477+ ( ) => {
478+ return null ;
479+ }
480+ ) ;
481+
482+ jest . spyOn ( apiCall , 'sendEmail' ) . mockImplementationOnce ( ( ) => true ) ;
483+
484+ jest . spyOn ( apiCall , 'postContact' ) . mockImplementationOnce ( ( ) => true ) ;
485+
486+ const res = await agent . post ( '/api/payment/sessionRegister' ) . send ( {
487+ sessionId :
488+ 'cs_test_a11YYufWQzNY63zpQ6QSNRQhkUpVph4WRmzW0zWJO2znZKdVujZ0N0S22u' ,
489+ } ) ;
490+
491+ expect ( res . status ) . toBe ( 500 ) ;
492+ expect ( res . body ) . toHaveProperty ( 'message' ) ;
493+ expect ( res . body . message ) . toBe ( 'Failed to retrieve customer' ) ;
494+ } ) ;
333495} ) ;
0 commit comments