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 only redirect on browser side', fakeAsync(() => {
httpStatusCodeService.setStatusAndRedirect(404);
tick(500);
verify(resSpy.status(anyNumber())).never();
expect(location.path()).toEqual('/error');
}));
});
return throwError({ message: `error loading category ${uniqueId}` });
}
});
const countryServiceMock = mock(CountryService);
when(countryServiceMock.getCountries()).thenReturn(EMPTY);
productsServiceMock = mock(ProductsService);
when(productsServiceMock.getProduct(anyString())).thenCall(sku => {
if (['P1', 'P2'].find(x => x === sku)) {
return of({ sku });
} else {
return throwError({ message: `error loading product ${sku}` });
}
});
when(productsServiceMock.getCategoryProducts('A.123.456', anyNumber(), anything())).thenReturn(
of({
sortKeys: [],
products: [{ sku: 'P1' }, { sku: 'P2' }] as Product[],
total: 2,
})
);
when(productsServiceMock.searchProducts('something', anyNumber(), anything())).thenReturn(
of({ products: [{ sku: 'P2' } as Product], sortKeys: [], total: 1 })
);
promotionsServiceMock = mock(PromotionsService);
when(promotionsServiceMock.getPromotion(anything())).thenReturn(of(promotion));
suggestServiceMock = mock(SuggestService);
when(suggestServiceMock.search('some')).thenReturn(of([{ term: 'something' }]));
beforeEach(() => {
suggestServiceMock = mock(SuggestService);
const result = [{ type: undefined, term: 'Goods' }];
when(suggestServiceMock.search(anyString())).thenReturn(of(result));
productsServiceMock = mock(ProductsService);
const skus = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
when(productsServiceMock.searchProducts(anyString(), anyNumber(), anything())).thenCall(
(searchTerm: string, page: number, itemsPerPage: number) => {
if (!searchTerm) {
return throwError({ message: 'ERROR' });
} else {
const currentSlice = skus.slice(page * itemsPerPage, page * itemsPerPage + itemsPerPage);
return of({
products: currentSlice.map(sku => ({ sku })),
sortKeys: [],
total: skus.length,
});
}
}
);
});
productsServiceMock = mock(ProductsService);
when(productsServiceMock.getProduct(anyString())).thenCall(sku => {
if (['P1', 'P2'].find(x => x === sku)) {
return of({ sku });
} else {
return throwError({ message: `error loading product ${sku}` });
}
});
when(productsServiceMock.getCategoryProducts('A.123.456', anyNumber(), anything())).thenReturn(
of({
sortKeys: [],
products: [{ sku: 'P1' }, { sku: 'P2' }] as Product[],
total: 2,
})
);
when(productsServiceMock.searchProducts('something', anyNumber(), anything())).thenReturn(
of({ products: [{ sku: 'P2' } as Product], sortKeys: [], total: 1 })
);
promotionsServiceMock = mock(PromotionsService);
when(promotionsServiceMock.getPromotion(anything())).thenReturn(of(promotion));
suggestServiceMock = mock(SuggestService);
when(suggestServiceMock.search('some')).thenReturn(of([{ term: 'something' }]));
filterServiceMock = mock(FilterService);
when(filterServiceMock.getFilterForSearch(anything())).thenReturn(of({} as FilterNavigation));
when(filterServiceMock.getFilterForCategory(anything())).thenReturn(of({} as FilterNavigation));
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
if (sku === 'invalid') {
return throwError({ message: 'invalid' });
} else {
return of({ sku } as Product);
}
});
when(productsServiceMock.getProductBundles(anything())).thenCall((sku: string) => {
if (!sku) {
return throwError({ message: 'invalid' });
} else {
return of({ product: { sku }, stubs: [] });
}
});
when(productsServiceMock.getCategoryProducts('123', anyNumber(), anything())).thenReturn(
of({
sortKeys: ['name-asc', 'name-desc'],
products: [{ sku: 'P222' }, { sku: 'P333' }] as Product[],
total: 2,
})
);
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
RouterTestingModule.withRoutes([{ path: 'error', component: DummyComponent }]),
ngrxTesting({
reducers: {
shopping: combineReducers(shoppingReducers),
locale: localeReducer,
},
const promotion = {
id: 'PROMO_UUID',
name: 'MyPromotion',
couponCodeRequired: false,
currency: 'EUR',
promotionType: 'MyPromotionType',
description: 'MyPromotionDescription',
legalContentMessage: 'MyPromotionContentMessage',
longTitle: 'MyPromotionLongTitle',
ruleDescription: 'MyPromotionRuleDescription',
title: 'MyPromotionTitle',
useExternalUrl: false,
} as Promotion;
categoriesServiceMock = mock(CategoriesService);
when(categoriesServiceMock.getTopLevelCategories(anyNumber())).thenReturn(
of(categoryTree([catA, catA123, catB].map(c => ({ ...c, completenessLevel: 0 }))))
);
when(categoriesServiceMock.getCategory(anything())).thenCall(uniqueId => {
switch (uniqueId) {
case 'A':
return of(
categoryTree([
{ ...catA, completenessLevel: CategoryCompletenessLevel.Max },
{ ...catA123, completenessLevel: 1 },
])
);
case 'B':
return of(categoryTree([{ ...catB, completenessLevel: CategoryCompletenessLevel.Max }]));
case 'A.123':
return of(
categoryTree([
beforeEach(() => {
@Component({ template: 'dummy' })
class DummyComponent {}
locales = [
{ lang: 'en_US', currency: 'USD', value: 'en' },
{ lang: 'de_DE', currency: 'EUR', value: 'de' },
{ lang: 'fr_FR', currency: 'EUR', value: 'fr' },
] as Locale[];
const categoriesServiceMock = mock(CategoriesService);
when(categoriesServiceMock.getTopLevelCategories(anyNumber())).thenReturn(of(categoryTree()));
const countryServiceMock = mock(CountryService);
when(countryServiceMock.getCountries()).thenReturn(of([{ countryCode: 'DE', name: 'Germany' }]));
const basketServiceMock = mock(BasketService);
when(basketServiceMock.getBasket(anything())).thenCall(() => {
const newBasket = {
...basket,
};
if (basketId) {
newBasket.id = basketId;
}
return of(newBasket);
});