|
| 1 | +import { Cart } from '@bigcommerce/checkout-sdk/payment-integration-api'; |
| 2 | + |
| 3 | +import { getCart } from '../carts.mock'; |
| 4 | + |
| 5 | +import mapToCart from './map-to-cart'; |
| 6 | +import { getHeadlessCartResponse } from './mocks/headless-cart.mock'; |
| 7 | + |
| 8 | +describe('mapToCart', () => { |
| 9 | + let headlessCartResponse: Cart | undefined; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + headlessCartResponse = mapToCart(getHeadlessCartResponse().data.site); |
| 13 | + }); |
| 14 | + |
| 15 | + it('maps to internal cart', () => { |
| 16 | + const cart = getCart(); |
| 17 | + |
| 18 | + // TODO:: data is not yet fully compatible due to lack of information |
| 19 | + expect(headlessCartResponse).toEqual( |
| 20 | + expect.objectContaining({ |
| 21 | + id: cart.id, |
| 22 | + isTaxIncluded: cart.isTaxIncluded, |
| 23 | + discountAmount: cart.discountAmount, |
| 24 | + baseAmount: cart.baseAmount, |
| 25 | + cartAmount: cart.cartAmount, |
| 26 | + createdTime: cart.createdTime, |
| 27 | + updatedTime: cart.updatedTime, |
| 28 | + coupons: cart.coupons.map((item) => |
| 29 | + expect.objectContaining({ |
| 30 | + id: item.id, |
| 31 | + code: item.code, |
| 32 | + couponType: item.couponType, |
| 33 | + discountedAmount: item.discountedAmount, |
| 34 | + }), |
| 35 | + ), |
| 36 | + lineItems: expect.objectContaining({ |
| 37 | + physicalItems: cart.lineItems.physicalItems.map((item) => |
| 38 | + expect.objectContaining({ |
| 39 | + id: item.id, |
| 40 | + variantId: item.variantId, |
| 41 | + productId: item.productId, |
| 42 | + sku: item.sku, |
| 43 | + name: item.name, |
| 44 | + url: item.url, |
| 45 | + quantity: item.quantity, |
| 46 | + brand: item.brand, |
| 47 | + isTaxable: item.isTaxable, |
| 48 | + imageUrl: item.imageUrl, |
| 49 | + discounts: item.discounts, |
| 50 | + discountAmount: item.discountAmount, |
| 51 | + couponAmount: item.couponAmount, |
| 52 | + listPrice: item.listPrice, |
| 53 | + salePrice: item.salePrice, |
| 54 | + extendedListPrice: item.extendedListPrice, |
| 55 | + extendedSalePrice: item.extendedSalePrice, |
| 56 | + isShippingRequired: item.isShippingRequired, |
| 57 | + options: expect.arrayContaining(item.options || []), |
| 58 | + // retailPrice, comparisonPrice, extendedComparisonPrice, addedByPromotion are not exist |
| 59 | + }), |
| 60 | + ), |
| 61 | + }), |
| 62 | + discounts: cart.discounts, |
| 63 | + currency: cart.currency, |
| 64 | + // customerId is not exist |
| 65 | + // email is not exist |
| 66 | + }), |
| 67 | + ); |
| 68 | + }); |
| 69 | +}); |
0 commit comments