Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should accumulate AddProductToBasket to a single AddItemsToBasket action', () => {
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU1', packingUnit: 'pcs.' } as Product }));
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU2', packingUnit: 'pcs.' } as Product }));
const action1 = new basketActions.AddProductToBasket({ sku: 'SKU1', quantity: 1 });
const action2 = new basketActions.AddProductToBasket({ sku: 'SKU2', quantity: 1 });
const completion = new basketActions.AddItemsToBasket({
items: [{ sku: 'SKU2', quantity: 2, unit: 'pcs.' }, { sku: 'SKU1', quantity: 2, unit: 'pcs.' }],
});
actions$ = hot(' -b-a-b-a--|', { a: action1, b: action2 });
const expected$ = cold('----------(c|)', { c: completion });
expect(effects.addProductToBasket$).toBeObservable(expected$);
});
});
it('should map invalid request to action of type LoadCategoryFail', () => {
const categoryId = 'invalid';
const action = new fromActions.LoadCategory({ categoryId });
const completion = new fromActions.LoadCategoryFail({ error: { message: 'invalid category' } as HttpError });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadCategory$).toBeObservable(expected$);
});
});
it('should throw error for deleteQuoteRequest', () => {
expect(quoteRequestService.deleteQuoteRequest(undefined)).toBeObservable(
cold('#', undefined, { message: 'not logged in' })
);
});
it('should not fire when selected category is available but not completely loaded', () => {
store$.dispatch(
new fromActions.LoadCategorySuccess({ categories: categoryTree([{ uniqueId: 'A' }] as Category[]) })
);
store$.dispatch(new fromActions.SelectCategory({ categoryId: 'A' }));
actions$ = of(new fromActions.SelectCategory({ categoryId: 'A' }));
expect(effects.selectedCategoryAvailable$).toBeObservable(cold('-----'));
});
it("should throw error if 'setQuoteRequestItems' is called with unsubmitted quote request", () => {
expect(
quoteRequestService.createQuoteRequestFromQuoteRequest({ submitted: false, items: [] } as QuoteRequest)
).toBeObservable(
cold('#', undefined, { message: 'createQuoteRequestFromQuoteRequest() called with unsubmitted quote request' })
);
});
it('should do nothing if no category is selected', () => {
const action = new ChangeSortBy({ sorting: 'name-desc' });
actions$ = hot('-a-a-a', { a: action });
expect(effects.changeSortBy$).toBeObservable(cold('-'));
});
it('should not trigger SelectOrderAfterRedirect action if checkout payment/receipt page is called with query param "redirect" and there is no logged in user and no order', () => {
const action = new RouteNavigation({
path: 'checkout/receipt',
queryParams: { redirect: 'success', param1: 123, orderId: order.id },
});
actions$ = hot('-a', { a: action });
expect(effects.returnFromRedirectAfterOrderCreation$).toBeObservable(cold('-'));
});
it('should not die when encountering an error', () => {
when(cmsServiceMock.getContentPage('dummy')).thenReturn(throwError({ message: 'ERROR' }));
actions$ = hot('a-a-a-a', { a: new LoadContentPage({ contentPageId: 'dummy' }) });
expect(effects.loadContentPage$).toBeObservable(
cold('a-a-a-a', { a: new LoadContentPageFail({ error: { message: 'ERROR' } as HttpError }) })
);
});
});
it('should load all countries on effects init and dispatch a LoadCountriesSuccess action', () => {
const action = { type: CountryActionTypes.LoadCountries } as Action;
const expected = new LoadCountriesSuccess({ countries });
actions$ = hot('-a-------', { a: action });
expect(effects.loadCountries$).toBeObservable(cold('-b-------', { b: expected }));
});
it('should accumulate AddProductToBasket to a single AddItemsToBasket action', () => {
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU1', packingUnit: 'pcs.' } as Product }));
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU2', packingUnit: 'pcs.' } as Product }));
const action1 = new basketActions.AddProductToBasket({ sku: 'SKU1', quantity: 1 });
const action2 = new basketActions.AddProductToBasket({ sku: 'SKU2', quantity: 1 });
const completion = new basketActions.AddItemsToBasket({
items: [{ sku: 'SKU2', quantity: 2, unit: 'pcs.' }, { sku: 'SKU1', quantity: 2, unit: 'pcs.' }],
});
actions$ = hot(' -b-a-b-a--|', { a: action1, b: action2 });
const expected$ = cold('----------(c|)', { c: completion });
expect(effects.addProductToBasket$).toBeObservable(expected$);
});
});