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 delete an item if called', () => {
when(checkoutFacadeMock.deleteBasketItem(anyString())).thenReturn(undefined);
component.deleteItem('4713');
verify(checkoutFacadeMock.deleteBasketItem('4713')).once();
});
});
it('should map to action of type LoadQuotes if SubmitQuoteRequestSuccess action triggered', () => {
const action = new SubmitQuoteRequestSuccess(anyString());
const completion = new quoteActions.LoadQuotes();
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadQuotesAfterChangeSuccess$).toBeObservable(expected$);
});
it('should map invalid request to action of type AddItemsToBasketFail', () => {
when(basketServiceMock.addItemsToBasket(anyString(), anything())).thenReturn(throwError({ message: 'invalid' }));
store$.dispatch(
new basketActions.LoadBasketSuccess({
basket: {
id: 'BID',
lineItems: [],
} as Basket,
})
);
const items = [{ sku: 'invalid', quantity: 1, unit: 'pcs.' }];
const action = new basketActions.AddItemsToBasket({ items });
const completion = new basketActions.AddItemsToBasketFail({ error: { message: 'invalid' } as HttpError });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
it('should submit when email or username is specified', fakeAsync(() => {
const env = new TestEnvironment();
when(env.mockedIdentityService.forgotPassword(anything())).thenResolve(true);
env.fixture.detectChanges();
env.setInputValue(env.userInput, 'user');
env.clickSubmitButton();
verify(env.mockedIdentityService.forgotPassword(deepEqual('user'))).once();
verify(env.mockedNoticeService.show(anyString())).once();
expect().nothing();
flush();
}));
it('should dispatch a LoadOrderFail action if a load error occurs', () => {
when(orderServiceMock.getOrderByToken(anyString(), anyString())).thenReturn(throwError({ message: 'error' }));
const action = new orderActions.LoadOrderByAPIToken({ apiToken: 'dummy', orderId: order.id });
const completion = new orderActions.LoadOrderFail({ error: { message: 'error' } as HttpError });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadOrderByAPIToken$).toBeObservable(expected$);
});
});
it("should update the business customer when 'updateCustomer' is called with type 'SMBCustomer'", done => {
when(apiServiceMock.put(anyString(), anything())).thenReturn(of({}));
const customer = {
customerNo: '4711',
companyName: 'xyz',
type: 'SMBCustomer',
isBusinessCustomer: true,
} as Customer;
userService.updateCustomer(customer).subscribe(() => {
verify(apiServiceMock.put('customers/-', anything())).once();
done();
});
});
});
it('should map invalid request to action of type AddPromotionCodeToBasketFail', () => {
when(basketServiceMock.addPromotionCodeToBasket(anyString(), anyString())).thenReturn(
throwError({ message: 'invalid' })
);
const code = 'CODE';
const action = new basketActions.AddPromotionCodeToBasket({ code });
const completion = new basketActions.AddPromotionCodeToBasketFail({ error: { message: 'invalid' } as HttpError });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.addPromotionCodeToBasket$).toBeObservable(expected$);
});
});
beforeEach(() => {
store$.dispatch(new LoginUserSuccess({ customer }));
store$.dispatch(new LoadCompanyUserSuccess({ user: { email: 'test' } as User }));
store$.dispatch(
new quoteRequestActions.LoadQuoteRequestsSuccess({ quoteRequests: [{ id: 'QRID' } as QuoteRequestData] })
);
store$.dispatch(new quoteRequestActions.SelectQuoteRequest({ id: 'QRID' }));
when(quoteRequestServiceMock.removeItemFromQuoteRequest(anyString(), anyString())).thenReturn(of('QRID'));
});
basket: {
id: 'BID',
lineItems: [
{
id: 'BIID',
name: 'NAME',
position: 1,
quantity: { value: 1 },
productSKU: 'SKU',
} as LineItem,
],
payment: undefined,
} as Basket,
})
);
when(quoteRequestServiceMock.addProductToQuoteRequest(anyString(), anything())).thenReturn(of('QRID'));
});