@@ -82,6 +82,8 @@ const checkoutProviderData = {
8282} satisfies TabbyCheckoutData ;
8383const checkoutHistoryOrder = checkoutProviderData . order_history [ 0 ] ;
8484if ( ! checkoutHistoryOrder ) throw new Error ( "checkout history fixture is missing" ) ;
85+ const checkoutShippingAddress = baseCheckout . shippingAddress ;
86+ if ( ! checkoutShippingAddress ) throw new Error ( "checkout shipping fixture is missing" ) ;
8587describe ( "toTabbyBuyer" , ( ) => {
8688 it ( "preserves a provided buyer name after trimming" , ( ) => {
8789 expect (
@@ -117,8 +119,10 @@ describe("toTabbyCheckoutRequest", () => {
117119 expect ( req . payment . amount ) . toBe ( "500.00" ) ;
118120 expect ( req . payment . currency ) . toBe ( "AED" ) ;
119121 expect ( req . payment . buyer . name ) . toBe ( "Ali Dhamen" ) ;
120- expect ( req . payment . shipping_address . address ) . toBe ( "Sheikh Zayed Rd" ) ;
121- expect ( req . payment . shipping_address . city ) . toBe ( "Dubai" ) ;
122+ expect ( req . payment . shipping_address ) . toMatchObject ( {
123+ address : "Sheikh Zayed Rd" ,
124+ city : "Dubai" ,
125+ } ) ;
122126 expect ( req . payment . order . reference_id ) . toBe ( "ord-1" ) ;
123127 expect ( req . payment . order . items [ 0 ] ?. title ) . toBe ( "Keyboard" ) ;
124128 expect ( req . payment . order . items [ 0 ] ?. unit_price ) . toBe ( "500.00" ) ;
@@ -141,11 +145,11 @@ describe("toTabbyCheckoutRequest", () => {
141145 const req = toTabbyCheckoutRequest (
142146 {
143147 ...baseCheckout ,
144- shippingAddress : { ...baseCheckout . shippingAddress , line2 : "Floor 5" } ,
148+ shippingAddress : { ...checkoutShippingAddress , line2 : "Floor 5" } ,
145149 } ,
146150 { merchantCode : "M" } ,
147151 ) ;
148- expect ( req . payment . shipping_address . address ) . toBe ( "Sheikh Zayed Rd, Floor 5" ) ;
152+ expect ( req . payment . shipping_address ? .address ) . toBe ( "Sheikh Zayed Rd, Floor 5" ) ;
149153 } ) ;
150154 it ( "validates and maps trusted checkout provider data to Tabby's payment fields" , ( ) => {
151155 const req = toTabbyCheckoutRequest (
@@ -165,6 +169,23 @@ describe("toTabbyCheckoutRequest", () => {
165169 content_type : "application/vnd.tabby.v1+json" ,
166170 } ) ;
167171 } ) ;
172+ it ( "accepts order history without shipping_address and omits the key" , ( ) => {
173+ const { shipping_address : _shippingAddress , ...historyWithoutShipping } = checkoutHistoryOrder ;
174+ const { shippingAddress : _checkoutShippingAddress , ...checkoutWithoutShipping } = baseCheckout ;
175+ const req = toTabbyCheckoutRequest (
176+ {
177+ ...checkoutWithoutShipping ,
178+ providerData : {
179+ ...checkoutProviderData ,
180+ order_history : [ historyWithoutShipping ] ,
181+ } ,
182+ } ,
183+ { merchantCode : "M" } ,
184+ ) ;
185+
186+ expect ( req . payment . order_history ?. [ 0 ] ) . not . toHaveProperty ( "shipping_address" ) ;
187+ expect ( JSON . stringify ( req ) ) . not . toContain ( '"shipping_address"' ) ;
188+ } ) ;
168189 it ( "preserves the previous payment shape when checkout provider data is absent" , ( ) => {
169190 const req = toTabbyCheckoutRequest ( baseCheckout , { merchantCode : "M" } ) ;
170191 expect ( req . payment ) . not . toHaveProperty ( "buyer_history" ) ;
0 commit comments