From 8bdb152985fe1944fd42d14d89ae41703d68cb92 Mon Sep 17 00:00:00 2001 From: Peter Lauck Date: Tue, 21 Nov 2023 16:53:51 +0000 Subject: [PATCH] fix test --- ...add-to-cart-notification.component.spec.ts | 2 +- .../add-to-cart-notification.reducer.spec.ts | 2 +- .../cart-items/cart-items.component.spec.ts | 2 +- .../cart-sidebar.component.spec.ts | 2 +- .../cart-summary-wrapper.component.spec.ts | 2 +- .../cart-totals/cart-totals.component.spec.ts | 2 +- .../components/cart/cart.component.spec.ts | 2 +- .../cart-view/cart-view.component.spec.ts | 2 +- .../effects/cart-resolver.effects.spec.ts | 2 +- .../checkout/effects/checkout.effects.spec.ts | 2 +- .../checkout-view.component.spec.ts | 2 +- .../pages/thank-you-view.component.spec.ts | 2 +- .../src/effects/authorize-net.effects.spec.ts | 2 +- .../outputs/cart-totals-transformer.spec.ts | 162 ++++-------------- .../transforms/outputs/cart.service.spec.ts | 49 +----- .../billing-address.guard.spec.ts | 4 +- .../payment-method.guard.spec.ts | 4 +- .../shipping-address.guard.spec.ts | 4 +- .../shipping-method.guard.spec.ts | 4 +- .../src/facades/cart/cart.facade.spec.ts | 18 +- .../cart-billing-address.reducer.spec.ts | 4 +- .../cart-item-entities.reducer.spec.ts | 30 ++-- .../cart-item/cart-item.reducer.spec.ts | 4 +- .../cart-payment-methods.reducer.spec.ts | 4 +- .../cart-payment/cart-payment.reducer.spec.ts | 4 +- .../cart-shipping-address.reducer.spec.ts | 4 +- .../cart-shipping-information.reducer.spec.ts | 4 +- .../cart-shipping-methods.reducer.spec.ts | 2 +- .../src/reducers/cart/cart.reducer.spec.ts | 4 +- .../cart-item-entities.selectors.spec.ts | 16 +- .../src/selectors/cart/cart.selector.spec.ts | 18 +- .../src/factories/cart.factory.spec.ts | 15 +- .../reducers/order/order.reducer.spec.ts | 2 +- 33 files changed, 126 insertions(+), 256 deletions(-) diff --git a/apps/demo/src/app/cart/components/add-to-cart-notification/components/add-to-cart-notification/add-to-cart-notification.component.spec.ts b/apps/demo/src/app/cart/components/add-to-cart-notification/components/add-to-cart-notification/add-to-cart-notification.component.spec.ts index e0a589dec8..41b143a589 100644 --- a/apps/demo/src/app/cart/components/add-to-cart-notification/components/add-to-cart-notification/add-to-cart-notification.component.spec.ts +++ b/apps/demo/src/app/cart/components/add-to-cart-notification/components/add-to-cart-notification/add-to-cart-notification.component.spec.ts @@ -61,7 +61,7 @@ describe('AddToCartNotificationComponent', () => { [DAFF_PRODUCT_STORE_FEATURE_KEY]: DaffProductReducersState; }>; const productFactory: DaffProductFactory = new DaffProductFactory(); - const cartFactory: DaffCartFactory = new DaffCartFactory(); + const cartFactory: DaffCartFactory = TestBed.inject(DaffCartFactory); let addToCartNotification: AddToCartNotificationComponent; let productAdded: MockProductAddedComponent; diff --git a/apps/demo/src/app/cart/components/add-to-cart-notification/reducers/add-to-cart-notification.reducer.spec.ts b/apps/demo/src/app/cart/components/add-to-cart-notification/reducers/add-to-cart-notification.reducer.spec.ts index fb7e16529b..23af068976 100644 --- a/apps/demo/src/app/cart/components/add-to-cart-notification/reducers/add-to-cart-notification.reducer.spec.ts +++ b/apps/demo/src/app/cart/components/add-to-cart-notification/reducers/add-to-cart-notification.reducer.spec.ts @@ -98,7 +98,7 @@ describe('Add To Cart Notification | Reducer', () => { describe('when AddToCartSuccess action is triggered', () => { let result; - const cartFactory = new DaffCartFactory(); + const cartFactory = TestBed.inject(DaffCartFactory); const stubCart: DaffCart = cartFactory.create(); beforeEach(() => { diff --git a/apps/demo/src/app/cart/components/cart-items/cart-items.component.spec.ts b/apps/demo/src/app/cart/components/cart-items/cart-items.component.spec.ts index 118d3496fd..53ccb88b49 100644 --- a/apps/demo/src/app/cart/components/cart-items/cart-items.component.spec.ts +++ b/apps/demo/src/app/cart/components/cart-items/cart-items.component.spec.ts @@ -36,7 +36,7 @@ describe('CartItemsComponent', () => { let cartItems; let cart: CartItemsComponent; - const cartFactory = new DaffCartFactory(); + const cartFactory = TestBed.inject(DaffCartFactory); const mockCart = cartFactory.create({ items: new DaffCartItemFactory().createMany(2), }); diff --git a/apps/demo/src/app/cart/components/cart-sidebar/cart-sidebar.component.spec.ts b/apps/demo/src/app/cart/components/cart-sidebar/cart-sidebar.component.spec.ts index e4e8786ac4..14679be1a1 100644 --- a/apps/demo/src/app/cart/components/cart-sidebar/cart-sidebar.component.spec.ts +++ b/apps/demo/src/app/cart/components/cart-sidebar/cart-sidebar.component.spec.ts @@ -51,7 +51,7 @@ describe('CartSidebar', () => { let summaryElement: DebugElement; - const cartFactory = new DaffCartFactory(); + const cartFactory = TestBed.inject(DaffCartFactory); const cart = cartFactory.create(); beforeEach(waitForAsync(() => { diff --git a/apps/demo/src/app/cart/components/cart-summary-wrapper/cart-summary-wrapper.component.spec.ts b/apps/demo/src/app/cart/components/cart-summary-wrapper/cart-summary-wrapper.component.spec.ts index 30e1d6388e..8832c6ef5c 100644 --- a/apps/demo/src/app/cart/components/cart-summary-wrapper/cart-summary-wrapper.component.spec.ts +++ b/apps/demo/src/app/cart/components/cart-summary-wrapper/cart-summary-wrapper.component.spec.ts @@ -22,7 +22,7 @@ import { DaffLoadingIconModule } from '@daffodil/design'; import { CartSummaryWrapperComponent } from './cart-summary-wrapper.component'; import { CartSummaryComponent } from '../cart-summary/cart-summary.component'; -const cartFactory = new DaffCartFactory(); +const cartFactory = TestBed.inject(DaffCartFactory); const cart = cartFactory.create(); const stubCartTitle = 'cartTitle'; diff --git a/apps/demo/src/app/cart/components/cart-totals/cart-totals.component.spec.ts b/apps/demo/src/app/cart/components/cart-totals/cart-totals.component.spec.ts index 5bad6ca0b0..f9c3f62b17 100644 --- a/apps/demo/src/app/cart/components/cart-totals/cart-totals.component.spec.ts +++ b/apps/demo/src/app/cart/components/cart-totals/cart-totals.component.spec.ts @@ -30,7 +30,7 @@ describe('CartTotalsComponent', () => { let cartTotalsComponent: CartTotalsComponent; let cartTotalsItemComponent: any; let currencyPipe; - const cartFactory = new DaffCartFactory(); + const cartFactory = TestBed.inject(DaffCartFactory); const cartItemFactory = new DaffCartItemFactory(); const mockCart = cartFactory.create({ diff --git a/apps/demo/src/app/cart/components/cart/cart.component.spec.ts b/apps/demo/src/app/cart/components/cart/cart.component.spec.ts index c5051a9393..c9d969f3db 100644 --- a/apps/demo/src/app/cart/components/cart/cart.component.spec.ts +++ b/apps/demo/src/app/cart/components/cart/cart.component.spec.ts @@ -66,7 +66,7 @@ describe('Cart', () => { let cartItemCountElement: DebugElement; let cartItemCountComponent: MockCartItemCountComponent; - const cartFactory = new DaffCartFactory(); + const cartFactory = TestBed.inject(DaffCartFactory); const cart = cartFactory.create(); beforeEach(waitForAsync(() => { diff --git a/apps/demo/src/app/cart/pages/cart-view/cart-view.component.spec.ts b/apps/demo/src/app/cart/pages/cart-view/cart-view.component.spec.ts index a0fd84b79a..d5941e1b5a 100644 --- a/apps/demo/src/app/cart/pages/cart-view/cart-view.component.spec.ts +++ b/apps/demo/src/app/cart/pages/cart-view/cart-view.component.spec.ts @@ -23,7 +23,7 @@ import { import { DemoCartViewComponent } from './cart-view.component'; -const cartFactory = new DaffCartFactory(); +const cartFactory = TestBed.inject(DaffCartFactory); const cart = cartFactory.create(); @Component({ diff --git a/apps/demo/src/app/cart/routing-resolvers/effects/cart-resolver.effects.spec.ts b/apps/demo/src/app/cart/routing-resolvers/effects/cart-resolver.effects.spec.ts index 757f4a7f05..9a091c444d 100644 --- a/apps/demo/src/app/cart/routing-resolvers/effects/cart-resolver.effects.spec.ts +++ b/apps/demo/src/app/cart/routing-resolvers/effects/cart-resolver.effects.spec.ts @@ -49,7 +49,7 @@ describe('CartResolverEffects', () => { provideMockActions(() => actions$), { provide: DaffCartDriver, - useValue: new DaffTestingCartService(new DaffCartFactory()), + useValue: new DaffTestingCartService(TestBed.inject(DaffCartFactory)), }, ], }); diff --git a/apps/demo/src/app/checkout/effects/checkout.effects.spec.ts b/apps/demo/src/app/checkout/effects/checkout.effects.spec.ts index 18461d8d36..83a69674ae 100644 --- a/apps/demo/src/app/checkout/effects/checkout.effects.spec.ts +++ b/apps/demo/src/app/checkout/effects/checkout.effects.spec.ts @@ -20,7 +20,7 @@ describe('CheckoutEffects', () => { let actions$: Observable; let effects: CheckoutEffects; let router: Router; - const cartFactory: DaffCartFactory = new DaffCartFactory(); + const cartFactory: DaffCartFactory = TestBed.inject(DaffCartFactory); let stubCart: DaffCart; beforeEach(() => { diff --git a/apps/demo/src/app/checkout/pages/checkout-view/checkout-view.component.spec.ts b/apps/demo/src/app/checkout/pages/checkout-view/checkout-view.component.spec.ts index ca060f857e..e95841db04 100644 --- a/apps/demo/src/app/checkout/pages/checkout-view/checkout-view.component.spec.ts +++ b/apps/demo/src/app/checkout/pages/checkout-view/checkout-view.component.spec.ts @@ -51,7 +51,7 @@ import * as fromDemoCheckout from '../../reducers/index'; const daffodilAddressFactory = new DaffAddressFactory(); const paymentFactory = new DaffPaymentFactory(); -const cartFactory = new DaffCartFactory(); +const cartFactory = TestBed.inject(DaffCartFactory); const cartItemFactory = new DaffCartItemFactory(); const stubShippingAddress = daffodilAddressFactory.create(); diff --git a/apps/demo/src/app/thank-you/pages/thank-you-view.component.spec.ts b/apps/demo/src/app/thank-you/pages/thank-you-view.component.spec.ts index b4054f64f1..8e36adc086 100644 --- a/apps/demo/src/app/thank-you/pages/thank-you-view.component.spec.ts +++ b/apps/demo/src/app/thank-you/pages/thank-you-view.component.spec.ts @@ -30,7 +30,7 @@ import { import { ThankYouViewComponent } from './thank-you-view.component'; -const cartFactory = new DaffCartFactory(); +const cartFactory = TestBed.inject(DaffCartFactory); const cartItemFactory = new DaffCartItemFactory(); const stubCart: DaffCart = cartFactory.create({ items: [cartItemFactory.create()]}); diff --git a/libs/authorizenet/state/src/effects/authorize-net.effects.spec.ts b/libs/authorizenet/state/src/effects/authorize-net.effects.spec.ts index 58ac2e8a3e..4d4dafaaa6 100644 --- a/libs/authorizenet/state/src/effects/authorize-net.effects.spec.ts +++ b/libs/authorizenet/state/src/effects/authorize-net.effects.spec.ts @@ -156,7 +156,7 @@ describe('DaffAuthorizeNetEffects', () => { describe('updatePaymentSuccessSubstream$', () => { it('should dispatch DaffAuthorizeNetUpdatePaymentSuccess when the cart payment method has been successfully updated', () => { - const stubCart = new DaffCartFactory().create(); + const stubCart = TestBed.inject(DaffCartFactory).create(); const authorizeNetUpdatePayment = new DaffAuthorizeNetUpdatePayment(paymentTokenRequest, stubAddress); const cartPaymentUpdateWithBillingSuccess = new DaffCartPaymentUpdateWithBillingSuccess(stubCart); const authorizeNetPaymentUpdateSuccess = new DaffAuthorizeNetUpdatePaymentSuccess(); diff --git a/libs/cart/driver/magento/src/transforms/outputs/cart-totals-transformer.spec.ts b/libs/cart/driver/magento/src/transforms/outputs/cart-totals-transformer.spec.ts index 3ffa84288a..c6e1a7e6c8 100644 --- a/libs/cart/driver/magento/src/transforms/outputs/cart-totals-transformer.spec.ts +++ b/libs/cart/driver/magento/src/transforms/outputs/cart-totals-transformer.spec.ts @@ -1,9 +1,6 @@ import { TestBed } from '@angular/core/testing'; -import { - DaffCart, - DaffCartTotalTypeEnum, -} from '@daffodil/cart'; +import { DaffCartTotalTypeEnum } from '@daffodil/cart'; import { MagentoCart } from '@daffodil/cart/driver/magento'; import { MagentoCartFactory } from '@daffodil/cart/driver/magento/testing'; import { daffAdd } from '@daffodil/core'; @@ -12,12 +9,11 @@ import { transformCartTotals } from './cart-totals-transformer'; describe('transformCartTotals', () => { let stubMagentoCart: MagentoCart; - let expectedTotals: {totals: DaffCart['totals']}; beforeEach(() => { TestBed.configureTestingModule({}); - stubMagentoCart = new MagentoCartFactory().create({ + stubMagentoCart = TestBed.inject(MagentoCartFactory).create({ shipping_addresses: [ { selected_shipping_method: { @@ -28,97 +24,22 @@ describe('transformCartTotals', () => { }, ], }); - const totalTax = stubMagentoCart.prices.applied_taxes.reduce((acc, tax) => (daffAdd(acc, tax.amount.value)), 0); - expectedTotals = { - totals: [ - { - name: DaffCartTotalTypeEnum.grandTotal, - label: 'Grand Total', - value: stubMagentoCart.prices.grand_total.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalExcludingTax, - label: 'Subtotal Excluding Tax', - value: stubMagentoCart.prices.subtotal_excluding_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalIncludingTax, - label: 'Subtotal Including Tax', - value: stubMagentoCart.prices.subtotal_including_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax, - label: 'Subtotal with Discount Excluding Tax', - value: stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax, - label: 'Subtotal with Discount Including Tax', - value: daffAdd(stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value, totalTax), - }, - { - name: DaffCartTotalTypeEnum.tax, - label: 'Tax', - value: totalTax, - }, - ...stubMagentoCart.prices.discounts.map(discount => ({ - name: DaffCartTotalTypeEnum.discount, - label: discount.label, - value: discount.amount.value, - })), - { - name: DaffCartTotalTypeEnum.shipping, - label: 'Shipping', - value: stubMagentoCart.shipping_addresses[0].selected_shipping_method.amount.value, - }, - ], - }; }); it('should transform cart totals', () => { - expect(transformCartTotals(stubMagentoCart)).toEqual(expectedTotals); + const totalTax = stubMagentoCart.prices.applied_taxes.reduce((acc, tax) => (daffAdd(acc, tax.amount.value)), 0); + const transformedTotals = transformCartTotals(stubMagentoCart).totals; + + expect(transformedTotals[DaffCartTotalTypeEnum.grandTotal].value).toEqual(stubMagentoCart.prices.grand_total.value); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalExcludingTax].value).toEqual(stubMagentoCart.prices.subtotal_excluding_tax.value); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalIncludingTax].value).toEqual(stubMagentoCart.prices.subtotal_including_tax.value); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value).toEqual(stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value).toEqual(daffAdd(stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value, totalTax)); + expect(transformedTotals[DaffCartTotalTypeEnum.tax].value).toEqual(totalTax); + expect(transformedTotals[DaffCartTotalTypeEnum.shipping].value).toEqual(stubMagentoCart.shipping_addresses[0].selected_shipping_method.amount.value); }); it('should transform cart totals when magento gives null/empty values', () => { - expectedTotals = { - totals: [ - { - name: DaffCartTotalTypeEnum.grandTotal, - label: 'Grand Total', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalExcludingTax, - label: 'Subtotal Excluding Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalIncludingTax, - label: 'Subtotal Including Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax, - label: 'Subtotal with Discount Excluding Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax, - label: 'Subtotal with Discount Including Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.tax, - label: 'Tax', - value: 0, - }, - { - name: DaffCartTotalTypeEnum.shipping, - label: 'Shipping', - value: null, - }, - ], - }; stubMagentoCart.prices.applied_taxes = []; stubMagentoCart.prices.discounts = []; stubMagentoCart.prices.grand_total.value = null; @@ -127,49 +48,18 @@ describe('transformCartTotals', () => { stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value = null; stubMagentoCart.shipping_addresses[0].selected_shipping_method.amount.value = null; - expect(transformCartTotals(stubMagentoCart)).toEqual(expectedTotals); + const transformedTotals = transformCartTotals(stubMagentoCart).totals; + + expect(transformedTotals[DaffCartTotalTypeEnum.grandTotal].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalExcludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalIncludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.tax].value).toEqual(0); + expect(transformedTotals[DaffCartTotalTypeEnum.shipping].value).toEqual(null); }); it('should transform cart totals when magento gives empty shipping addresses', () => { - expectedTotals = { - totals: [ - { - name: DaffCartTotalTypeEnum.grandTotal, - label: 'Grand Total', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalExcludingTax, - label: 'Subtotal Excluding Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalIncludingTax, - label: 'Subtotal Including Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax, - label: 'Subtotal with Discount Excluding Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax, - label: 'Subtotal with Discount Including Tax', - value: null, - }, - { - name: DaffCartTotalTypeEnum.tax, - label: 'Tax', - value: 0, - }, - { - name: DaffCartTotalTypeEnum.shipping, - label: 'Shipping', - value: null, - }, - ], - }; stubMagentoCart.prices.applied_taxes = []; stubMagentoCart.prices.discounts = []; stubMagentoCart.prices.grand_total.value = null; @@ -178,6 +68,14 @@ describe('transformCartTotals', () => { stubMagentoCart.prices.subtotal_with_discount_excluding_tax.value = null; stubMagentoCart.shipping_addresses = null; - expect(transformCartTotals(stubMagentoCart)).toEqual(expectedTotals); + const transformedTotals = transformCartTotals(stubMagentoCart).totals; + + expect(transformedTotals[DaffCartTotalTypeEnum.grandTotal].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalExcludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalIncludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value).toEqual(null); + expect(transformedTotals[DaffCartTotalTypeEnum.tax].value).toEqual(0); + expect(transformedTotals[DaffCartTotalTypeEnum.shipping].value).toEqual(null); }); }); diff --git a/libs/cart/driver/magento/src/transforms/outputs/cart.service.spec.ts b/libs/cart/driver/magento/src/transforms/outputs/cart.service.spec.ts index 91ecb307dc..dfc3ae0975 100644 --- a/libs/cart/driver/magento/src/transforms/outputs/cart.service.spec.ts +++ b/libs/cart/driver/magento/src/transforms/outputs/cart.service.spec.ts @@ -181,48 +181,13 @@ describe('@daffodil/cart/driver/magento | MagentoCart', () => { it('should return the expected cart totals', () => { const totalTax = mockMagentoCart.prices.applied_taxes.reduce((acc, tax) => (daffAdd(acc, tax.amount.value)), 0); - expect(transformedCart.totals).toEqual([ - { - name: DaffCartTotalTypeEnum.grandTotal, - label: 'Grand Total', - value: mockMagentoCart.prices.grand_total.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalExcludingTax, - label: 'Subtotal Excluding Tax', - value: mockMagentoCart.prices.subtotal_excluding_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalIncludingTax, - label: 'Subtotal Including Tax', - value: mockMagentoCart.prices.subtotal_including_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax, - label: 'Subtotal with Discount Excluding Tax', - value: mockMagentoCart.prices.subtotal_with_discount_excluding_tax.value, - }, - { - name: DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax, - label: 'Subtotal with Discount Including Tax', - value: daffAdd(mockMagentoCart.prices.subtotal_with_discount_excluding_tax.value, totalTax), - }, - { - name: DaffCartTotalTypeEnum.tax, - label: 'Tax', - value: totalTax, - }, - ...mockMagentoCart.prices.discounts.map(discount => ({ - name: DaffCartTotalTypeEnum.discount, - label: discount.label, - value: discount.amount.value, - })), - { - name: DaffCartTotalTypeEnum.shipping, - label: 'Shipping', - value: mockMagentoCart.shipping_addresses[0].selected_shipping_method.amount.value, - }, - ]); + expect(transformedCart.totals[DaffCartTotalTypeEnum.grandTotal].value).toEqual(mockMagentoCart.prices.grand_total.value); + expect(transformedCart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax].value).toEqual(mockMagentoCart.prices.subtotal_excluding_tax.value); + expect(transformedCart.totals[DaffCartTotalTypeEnum.subtotalIncludingTax].value).toEqual(mockMagentoCart.prices.subtotal_including_tax.value); + expect(transformedCart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value).toEqual(mockMagentoCart.prices.subtotal_with_discount_excluding_tax.value); + expect(transformedCart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value).toEqual(daffAdd(mockMagentoCart.prices.subtotal_with_discount_excluding_tax.value, totalTax)); + expect(transformedCart.totals[DaffCartTotalTypeEnum.tax].value).toEqual(totalTax); + expect(transformedCart.totals[DaffCartTotalTypeEnum.shipping].value).toEqual(mockMagentoCart.shipping_addresses[0].selected_shipping_method.amount.value); }); it('should call the shipping information transformer with the shipping method', () => { diff --git a/libs/cart/routing/src/guards/billing-address/billing-address.guard.spec.ts b/libs/cart/routing/src/guards/billing-address/billing-address.guard.spec.ts index 17033d1ae6..b58e5648b7 100644 --- a/libs/cart/routing/src/guards/billing-address/billing-address.guard.spec.ts +++ b/libs/cart/routing/src/guards/billing-address/billing-address.guard.spec.ts @@ -52,7 +52,7 @@ describe('Cart | State | Guards | DaffBillingAddressGuard', () => { describe('canActivate', () => { it('should allow activation when there is a billing address', () => { - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ billing_address: new DaffCartAddressFactory().create(), }); store.dispatch(new DaffCartLoadSuccess(cart)); @@ -65,7 +65,7 @@ describe('Cart | State | Guards | DaffBillingAddressGuard', () => { beforeEach(() => { spyOn(router, 'navigateByUrl'); - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ billing_address: null, }); store.dispatch(new DaffCartLoadSuccess(cart)); diff --git a/libs/cart/routing/src/guards/payment-method/payment-method.guard.spec.ts b/libs/cart/routing/src/guards/payment-method/payment-method.guard.spec.ts index 332a0c5998..8f911840bc 100644 --- a/libs/cart/routing/src/guards/payment-method/payment-method.guard.spec.ts +++ b/libs/cart/routing/src/guards/payment-method/payment-method.guard.spec.ts @@ -52,7 +52,7 @@ describe('Cart | State | Guards | DaffPaymentMethodGuard', () => { describe('canActivate', () => { it('should allow activation when there is a payment method', () => { - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ payment: new DaffCartPaymentFactory().create(), }); store.dispatch(new DaffCartLoadSuccess(cart)); @@ -65,7 +65,7 @@ describe('Cart | State | Guards | DaffPaymentMethodGuard', () => { beforeEach(() => { spyOn(router, 'navigateByUrl'); - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ payment: null, }); store.dispatch(new DaffCartLoadSuccess(cart)); diff --git a/libs/cart/routing/src/guards/shipping-address/shipping-address.guard.spec.ts b/libs/cart/routing/src/guards/shipping-address/shipping-address.guard.spec.ts index c0ff5fd7bf..8a17cc9018 100644 --- a/libs/cart/routing/src/guards/shipping-address/shipping-address.guard.spec.ts +++ b/libs/cart/routing/src/guards/shipping-address/shipping-address.guard.spec.ts @@ -52,7 +52,7 @@ describe('Cart | State | Guards | DaffShippingAddressGuard', () => { describe('canActivate', () => { it('should allow activation when there is a shipping address', () => { - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ shipping_address: new DaffCartAddressFactory().create(), }); store.dispatch(new DaffCartLoadSuccess(cart)); @@ -65,7 +65,7 @@ describe('Cart | State | Guards | DaffShippingAddressGuard', () => { beforeEach(() => { spyOn(router, 'navigateByUrl'); - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ shipping_address: null, }); store.dispatch(new DaffCartLoadSuccess(cart)); diff --git a/libs/cart/routing/src/guards/shipping-method/shipping-method.guard.spec.ts b/libs/cart/routing/src/guards/shipping-method/shipping-method.guard.spec.ts index 78748d96f9..682e262245 100644 --- a/libs/cart/routing/src/guards/shipping-method/shipping-method.guard.spec.ts +++ b/libs/cart/routing/src/guards/shipping-method/shipping-method.guard.spec.ts @@ -52,7 +52,7 @@ describe('Cart | State | Guards | DaffShippingMethodGuard', () => { describe('canActivate', () => { it('should allow activation when there is a shipping method', () => { - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ shipping_information: new DaffCartShippingRateFactory().create(), }); store.dispatch(new DaffCartLoadSuccess(cart)); @@ -65,7 +65,7 @@ describe('Cart | State | Guards | DaffShippingMethodGuard', () => { beforeEach(() => { spyOn(router, 'navigateByUrl'); - const cart: DaffCart = new DaffCartFactory().create({ + const cart: DaffCart = TestBed.inject(DaffCartFactory).create({ shipping_information: null, }); store.dispatch(new DaffCartLoadSuccess(cart)); diff --git a/libs/cart/state/src/facades/cart/cart.facade.spec.ts b/libs/cart/state/src/facades/cart/cart.facade.spec.ts index dab0af86b7..99e421fc00 100644 --- a/libs/cart/state/src/facades/cart/cart.facade.spec.ts +++ b/libs/cart/state/src/facades/cart/cart.facade.spec.ts @@ -957,7 +957,7 @@ describe('DaffCartFacade', () => { it('should be the cart subtotal upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.subtotal$).toBeObservable(expected); }); @@ -971,7 +971,7 @@ describe('DaffCartFacade', () => { it('should be the cart grand total upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.grandTotal).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.grandTotal].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.grandTotal$).toBeObservable(expected); }); @@ -981,7 +981,7 @@ describe('DaffCartFacade', () => { it('should be the cart subtotal excluding tax upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.subtotalExcludingTax$).toBeObservable(expected); }); @@ -991,7 +991,7 @@ describe('DaffCartFacade', () => { it('should be the cart subtotal including tax upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalIncludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalIncludingTax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.subtotalIncludingTax$).toBeObservable(expected); }); @@ -1001,7 +1001,7 @@ describe('DaffCartFacade', () => { it('should be the cart subtotal with discounts excluding tax upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.subtotalWithDiscountExcludingTax$).toBeObservable(expected); }); @@ -1011,7 +1011,7 @@ describe('DaffCartFacade', () => { it('should be the cart subtotal with discounts including tax upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.subtotalWithDiscountIncludingTax$).toBeObservable(expected); }); @@ -1021,7 +1021,7 @@ describe('DaffCartFacade', () => { it('should be the cart discount totals upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.filter(total => total.name === DaffCartTotalTypeEnum.discount) }); + const expected = cold('a', { a: [cart.totals[DaffCartTotalTypeEnum.discount]]}); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.discountTotals$).toBeObservable(expected); }); @@ -1031,7 +1031,7 @@ describe('DaffCartFacade', () => { it('should be the cart tax total upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.tax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.tax].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.totalTax$).toBeObservable(expected); }); @@ -1041,7 +1041,7 @@ describe('DaffCartFacade', () => { it('should be the cart shipping total upon a successful cart load', () => { const cart = cartFactory.create(); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.shipping).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.shipping].value }); facade.dispatch(new DaffCartLoadSuccess(cart)); expect(facade.shippingTotal$).toBeObservable(expected); }); diff --git a/libs/cart/state/src/reducers/cart-billing-address/cart-billing-address.reducer.spec.ts b/libs/cart/state/src/reducers/cart-billing-address/cart-billing-address.reducer.spec.ts index 832c7a5b57..5684751350 100644 --- a/libs/cart/state/src/reducers/cart-billing-address/cart-billing-address.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-billing-address/cart-billing-address.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart } from '@daffodil/cart'; import { DaffCartBillingAddressLoad, @@ -26,7 +28,7 @@ describe('Cart | Reducer | Cart Billing Address', () => { let cart: DaffCart; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cart = cartFactory.create(); }); diff --git a/libs/cart/state/src/reducers/cart-item-entities/cart-item-entities.reducer.spec.ts b/libs/cart/state/src/reducers/cart-item-entities/cart-item-entities.reducer.spec.ts index dab291088d..e5408e486d 100644 --- a/libs/cart/state/src/reducers/cart-item-entities/cart-item-entities.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-item-entities/cart-item-entities.reducer.spec.ts @@ -37,10 +37,12 @@ import { daffCartItemEntitiesReducer } from './cart-item-entities.reducer'; describe('Cart | Cart Item Entities Reducer', () => { let error: DaffStateError; let statefulCartItemFactory: DaffStatefulCartItemFactory; + let cartFactory: DaffCartFactory; const initialState = daffCartItemEntitiesAdapter().getInitialState(); beforeEach(() => { statefulCartItemFactory = TestBed.inject(DaffStatefulCartItemFactory); + cartFactory = TestBed.inject(DaffCartFactory); error = { code: 'code', @@ -100,7 +102,7 @@ describe('Cart | Cart Item Entities Reducer', () => { }); it('should retain the existing daffState when a CartItemDeleteSuccessAction is triggered', () => { - const cartItemDeleteSuccess = new DaffCartItemDeleteSuccess(new DaffCartFactory().create({ + const cartItemDeleteSuccess = new DaffCartItemDeleteSuccess(cartFactory.create({ items: [new DaffCartItemFactory().create({ id: stubStatefulCartItem.id })], })); @@ -109,7 +111,7 @@ describe('Cart | Cart Item Entities Reducer', () => { }); it('should retain the existing daffState when a CartLoadSuccessAction is triggered', () => { - const cartLoadSuccess = new DaffCartLoadSuccess(new DaffCartFactory().create({ + const cartLoadSuccess = new DaffCartLoadSuccess(cartFactory.create({ items: [new DaffCartItemFactory().create({ id: stubStatefulCartItem.id })], })); @@ -118,7 +120,7 @@ describe('Cart | Cart Item Entities Reducer', () => { }); it('should retain the existing daffState when a CartClearSuccessAction is triggered', () => { - const cartClearSuccess = new DaffCartClearSuccess(new DaffCartFactory().create({ + const cartClearSuccess = new DaffCartClearSuccess(cartFactory.create({ items: [new DaffCartItemFactory().create({ id: stubStatefulCartItem.id })], })); @@ -128,7 +130,7 @@ describe('Cart | Cart Item Entities Reducer', () => { it('should retain the existing daffState when a CartItemUpdateSuccessAction is triggered', () => { const cartItem = new DaffCartItemFactory().create(); - const cartItemUpdateSuccess = new DaffCartItemUpdateSuccess(new DaffCartFactory().create({ + const cartItemUpdateSuccess = new DaffCartItemUpdateSuccess(cartFactory.create({ items: [ stubStatefulCartItem, cartItem, @@ -196,7 +198,7 @@ describe('Cart | Cart Item Entities Reducer', () => { cartItems = statefulCartItemFactory.createMany(2, { daffErrors: [error], }); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const cartItemUpdateSuccess = new DaffCartItemUpdateSuccess(cart, cartItems[0].id); @@ -231,7 +233,7 @@ describe('Cart | Cart Item Entities Reducer', () => { statefulCartItem = statefulCartItemFactory.create({ daffErrors: [error], }); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: [statefulCartItem], }); const cartItemAddSuccess = new DaffCartItemAddSuccess(cart); @@ -266,7 +268,7 @@ describe('Cart | Cart Item Entities Reducer', () => { statefulCartItem = statefulCartItemFactory.create({ daffErrors: [error], }); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: [statefulCartItem], }); const cartItemAddSuccess = new DaffCartItemAddSuccess({ @@ -302,7 +304,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const cartItemDeleteSuccess = new DaffCartItemDeleteSuccess(cart); @@ -327,7 +329,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const cartItemDeleteOutOfStockSuccess = new DaffCartItemDeleteOutOfStockSuccess(cart); @@ -352,7 +354,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const cartLoadSuccess = new DaffCartLoadSuccess(cart); @@ -381,7 +383,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const resolveCartSuccess = new DaffResolveCartSuccess(cart); @@ -410,7 +412,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const resolveCartPartialSuccess = new DaffResolveCartPartialSuccess(cart, []); @@ -439,7 +441,7 @@ describe('Cart | Cart Item Entities Reducer', () => { beforeEach(() => { cartItems = statefulCartItemFactory.createMany(2); - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: cartItems, }); const cartLoadPartialSuccess = new DaffCartLoadPartialSuccess(cart, []); @@ -466,7 +468,7 @@ describe('Cart | Cart Item Entities Reducer', () => { let result: EntityState; beforeEach(() => { - cart = new DaffCartFactory().create({ + cart = cartFactory.create({ items: [], }); const cartItemAddSuccess = new DaffCartClearSuccess(cart); diff --git a/libs/cart/state/src/reducers/cart-item/cart-item.reducer.spec.ts b/libs/cart/state/src/reducers/cart-item/cart-item.reducer.spec.ts index 30e60ea21f..e33dbfb99d 100644 --- a/libs/cart/state/src/reducers/cart-item/cart-item.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-item/cart-item.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart, DaffCartItemInputType, @@ -46,7 +48,7 @@ describe('@daffodil/cart/state | cartItemReducer', () => { let result: DaffCartReducerState; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); statefulCartItemFactory = new DaffStatefulCartItemFactory(); cart = cartFactory.create(); diff --git a/libs/cart/state/src/reducers/cart-payment-methods/cart-payment-methods.reducer.spec.ts b/libs/cart/state/src/reducers/cart-payment-methods/cart-payment-methods.reducer.spec.ts index 32d912fd7d..be4bf5e9ed 100644 --- a/libs/cart/state/src/reducers/cart-payment-methods/cart-payment-methods.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-payment-methods/cart-payment-methods.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart } from '@daffodil/cart'; import { DaffCartPaymentMethodsLoad, @@ -20,7 +22,7 @@ describe('Cart | Reducer | Cart Payment Methods', () => { let cart: DaffCart; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cart = cartFactory.create(); }); diff --git a/libs/cart/state/src/reducers/cart-payment/cart-payment.reducer.spec.ts b/libs/cart/state/src/reducers/cart-payment/cart-payment.reducer.spec.ts index 33a951665d..cec196c362 100644 --- a/libs/cart/state/src/reducers/cart-payment/cart-payment.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-payment/cart-payment.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart } from '@daffodil/cart'; import { DaffCartPaymentLoad, @@ -30,7 +32,7 @@ describe('Cart | Reducer | Cart Payment', () => { let cart: DaffCart; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cart = cartFactory.create(); }); diff --git a/libs/cart/state/src/reducers/cart-shipping-address/cart-shipping-address.reducer.spec.ts b/libs/cart/state/src/reducers/cart-shipping-address/cart-shipping-address.reducer.spec.ts index 6a3af03abb..9e50132b3f 100644 --- a/libs/cart/state/src/reducers/cart-shipping-address/cart-shipping-address.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-shipping-address/cart-shipping-address.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart } from '@daffodil/cart'; import { DaffCartShippingAddressLoad, @@ -26,7 +28,7 @@ describe('Cart | Reducer | Cart Shipping Address', () => { let cart: DaffCart; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cart = cartFactory.create(); }); diff --git a/libs/cart/state/src/reducers/cart-shipping-information/cart-shipping-information.reducer.spec.ts b/libs/cart/state/src/reducers/cart-shipping-information/cart-shipping-information.reducer.spec.ts index a72fc1ce88..b256ca3a90 100644 --- a/libs/cart/state/src/reducers/cart-shipping-information/cart-shipping-information.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-shipping-information/cart-shipping-information.reducer.spec.ts @@ -1,3 +1,5 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart, DaffCartShippingInformation, @@ -34,7 +36,7 @@ describe('Cart | Reducer | Cart Shipping Information', () => { let mockCartShippingInformation: DaffCartShippingInformation; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cartShippingInformationFactory = new DaffCartShippingRateFactory(); cart = cartFactory.create(); diff --git a/libs/cart/state/src/reducers/cart-shipping-methods/cart-shipping-methods.reducer.spec.ts b/libs/cart/state/src/reducers/cart-shipping-methods/cart-shipping-methods.reducer.spec.ts index a1cf173eac..46c67df7cf 100644 --- a/libs/cart/state/src/reducers/cart-shipping-methods/cart-shipping-methods.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart-shipping-methods/cart-shipping-methods.reducer.spec.ts @@ -31,7 +31,7 @@ describe('Cart | Reducer | Cart Shipping Methods', () => { let mockCartShippingRate: DaffCartShippingRate; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cartShippingRateFactory = TestBed.inject(DaffCartShippingRateFactory); cart = cartFactory.create(); diff --git a/libs/cart/state/src/reducers/cart/cart.reducer.spec.ts b/libs/cart/state/src/reducers/cart/cart.reducer.spec.ts index 2f5400a9db..b5df74d9bf 100644 --- a/libs/cart/state/src/reducers/cart/cart.reducer.spec.ts +++ b/libs/cart/state/src/reducers/cart/cart.reducer.spec.ts @@ -1,4 +1,6 @@ +import { TestBed } from '@angular/core/testing'; + import { DaffCart } from '@daffodil/cart'; import { DaffCartLoad, @@ -40,7 +42,7 @@ describe('@daffodil/cart/state | cartReducer', () => { let cart: DaffCart; beforeEach(() => { - cartFactory = new DaffCartFactory(); + cartFactory = TestBed.inject(DaffCartFactory); cart = cartFactory.create(); error = { diff --git a/libs/cart/state/src/selectors/cart-item-entities/cart-item-entities.selectors.spec.ts b/libs/cart/state/src/selectors/cart-item-entities/cart-item-entities.selectors.spec.ts index 784063a7b9..1f4676b0f5 100644 --- a/libs/cart/state/src/selectors/cart-item-entities/cart-item-entities.selectors.spec.ts +++ b/libs/cart/state/src/selectors/cart-item-entities/cart-item-entities.selectors.spec.ts @@ -31,12 +31,11 @@ import { getDaffCartItemEntitiesSelectors } from './cart-item-entities.selectors import { DaffCartItemUpdateFailure } from '../../actions/public_api'; describe('@daffodil/cart/state | selectCartItemEntitiesState', () => { - let store: Store; - const cartFactory: DaffCartFactory = new DaffCartFactory(); - const statefulCartItemFactory: DaffStatefulCartItemFactory = new DaffStatefulCartItemFactory(); - const statefulConfigurableCartItemFactory: DaffStatefulConfigurableCartItemFactory = new DaffStatefulConfigurableCartItemFactory(); - const statefulCompositeCartItemFactory: DaffStatefulCompositeCartItemFactory = new DaffStatefulCompositeCartItemFactory(); + let cartFactory: DaffCartFactory; + let statefulCartItemFactory: DaffStatefulCartItemFactory; + let statefulConfigurableCartItemFactory: DaffStatefulConfigurableCartItemFactory; + let statefulCompositeCartItemFactory: DaffStatefulCompositeCartItemFactory; let mockCart: DaffCart; let mockCartItems: DaffStatefulCartItem[]; let mockStatefulConfigurableCartItems: DaffStatefulConfigurableCartItem[]; @@ -72,11 +71,16 @@ describe('@daffodil/cart/state | selectCartItemEntitiesState', () => { ], }); + store = TestBed.inject(Store); + cartFactory = TestBed.inject(DaffCartFactory); + statefulCartItemFactory = new DaffStatefulCartItemFactory(); + statefulConfigurableCartItemFactory = new DaffStatefulConfigurableCartItemFactory(); + statefulCompositeCartItemFactory = new DaffStatefulCompositeCartItemFactory(); + mockCart = cartFactory.create(); mockCartItems = statefulCartItemFactory.createMany(2); mockStatefulConfigurableCartItems = statefulConfigurableCartItemFactory.createMany(2); mockStatefulCompositeCartItems = statefulCompositeCartItemFactory.createMany(2); - store = TestBed.inject(Store); store.dispatch(new DaffCartItemListSuccess(mockCartItems)); }); diff --git a/libs/cart/state/src/selectors/cart/cart.selector.spec.ts b/libs/cart/state/src/selectors/cart/cart.selector.spec.ts index 07016684bd..c09e2203d7 100644 --- a/libs/cart/state/src/selectors/cart/cart.selector.spec.ts +++ b/libs/cart/state/src/selectors/cart/cart.selector.spec.ts @@ -1339,7 +1339,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartSubtotal', () => { it('returns cart subtotal', () => { const selector = store.pipe(select(selectCartSubtotal)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax].value }); expect(selector).toBeObservable(expected); }); @@ -1348,7 +1348,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartGrandTotal', () => { it('returns cart grand total', () => { const selector = store.pipe(select(selectCartGrandTotal)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.grandTotal).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.grandTotal].value }); expect(selector).toBeObservable(expected); }); @@ -1357,7 +1357,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartSubtotalExcludingTax', () => { it('returns cart subtotal excluding tax', () => { const selector = store.pipe(select(selectCartSubtotalExcludingTax)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax].value }); expect(selector).toBeObservable(expected); }); @@ -1366,7 +1366,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartSubtotalIncludingTax', () => { it('returns cart subtotal including tax', () => { const selector = store.pipe(select(selectCartSubtotalIncludingTax)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalIncludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalIncludingTax].value }); expect(selector).toBeObservable(expected); }); @@ -1375,7 +1375,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartSubtotalWithDiscountExcludingTax', () => { it('returns cart subtotal with discount excluding tax', () => { const selector = store.pipe(select(selectCartSubtotalWithDiscountExcludingTax)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax].value }); expect(selector).toBeObservable(expected); }); @@ -1384,7 +1384,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartSubtotalWithDiscountIncludingTax', () => { it('returns cart subtotal with discount including tax', () => { const selector = store.pipe(select(selectCartSubtotalWithDiscountIncludingTax)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax].value }); expect(selector).toBeObservable(expected); }); @@ -1393,7 +1393,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartTotalTax', () => { it('returns cart total tax', () => { const selector = store.pipe(select(selectCartTotalTax)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.tax).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.tax].value }); expect(selector).toBeObservable(expected); }); @@ -1402,7 +1402,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartDiscountTotals', () => { it('returns cart discount totals', () => { const selector = store.pipe(select(selectCartDiscountTotals)); - const expected = cold('a', { a: cart.totals.filter(total => total.name === DaffCartTotalTypeEnum.discount) }); + const expected = cold('a', { a: [cart.totals[DaffCartTotalTypeEnum.discount]]}); expect(selector).toBeObservable(expected); }); @@ -1411,7 +1411,7 @@ describe('Cart | Selector | Cart', () => { describe('selectCartShippingTotal', () => { it('returns cart shipping total', () => { const selector = store.pipe(select(selectCartShippingTotal)); - const expected = cold('a', { a: cart.totals.find(total => total.name === DaffCartTotalTypeEnum.shipping).value }); + const expected = cold('a', { a: cart.totals[DaffCartTotalTypeEnum.shipping].value }); expect(selector).toBeObservable(expected); }); diff --git a/libs/cart/testing/src/factories/cart.factory.spec.ts b/libs/cart/testing/src/factories/cart.factory.spec.ts index 9d254b1ba7..08b8114471 100644 --- a/libs/cart/testing/src/factories/cart.factory.spec.ts +++ b/libs/cart/testing/src/factories/cart.factory.spec.ts @@ -51,21 +51,8 @@ describe('Cart | Testing | Factories | DaffCartFactory', () => { }); it('should have cart totals', () => { - expect(result.totals).toBeGreaterThan(0); + expect(result.totals).toBeDefined(); }); - }); - }); - }); - - describe('createMany', () => { - let result: DaffCart[]; - - it('should create as many carts as desired', () => { - result = cartFactory.createMany(2); - expect(result.length).toEqual(2); - - result = cartFactory.createMany(3); - expect(result.length).toEqual(3); }); }); }); diff --git a/libs/checkout/src/order/reducers/order/order.reducer.spec.ts b/libs/checkout/src/order/reducers/order/order.reducer.spec.ts index 428c4db580..8485343031 100644 --- a/libs/checkout/src/order/reducers/order/order.reducer.spec.ts +++ b/libs/checkout/src/order/reducers/order/order.reducer.spec.ts @@ -22,7 +22,7 @@ describe('Order | Order Reducer', () => { beforeEach(() => { orderFactory = new DaffOrderFactory(); - stubCart = new DaffCartFactory().create(); + stubCart = TestBed.inject(DaffCartFactory).create(); stubOrder = orderFactory.create(); });