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 return a valid MerchandisingUserContext object, if there are no facets, but a categoryCode exists, and the page is a CATEGORY_PAGE', () => {
const expectedUserContext: MerchandisingUserContext = {
category: '574',
facets: undefined,
};
spyOn(routingService, 'getPageContext').and.returnValue(
of(new PageContext('574', PageType.CATEGORY_PAGE))
);
spyOn(productSearchService, 'getResults').and.returnValue(
of(emptyPageSearchResults)
);
spyOn(converterService, 'pipeable')
.withArgs(MERCHANDISING_FACET_NORMALIZER)
.and.returnValue(map(() => undefined))
.withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
.and.returnValue(map(() => undefined));
let merchandisingUserContext: MerchandisingUserContext;
cdsMerchandisingUserContextService
.getUserContext()
.subscribe(userContext => (merchandisingUserContext = userContext))
.unsubscribe();
expect(merchandisingUserContext).toEqual(expectedUserContext);
it('should return a valid MerchandisingUserContext object, if there are no facets, but a productCode exists, and the page is a PRODUCT_PAGE', () => {
const expectedUserContext: MerchandisingUserContext = {
products: ['12345'],
};
spyOn(routingService, 'getPageContext').and.returnValue(
of(new PageContext('12345', PageType.PRODUCT_PAGE))
);
spyOn(productSearchService, 'getResults').and.returnValue(
of(emptyPageSearchResults)
);
let merchandisingUserContext: MerchandisingUserContext;
cdsMerchandisingUserContextService
.getUserContext()
.subscribe(userContext => (merchandisingUserContext = userContext))
.unsubscribe();
expect(merchandisingUserContext).toEqual(expectedUserContext);
});
const expectedUserContext: MerchandisingUserContext = {
category: 'brand123',
facets: undefined,
};
spyOn(converterService, 'pipeable')
.withArgs(MERCHANDISING_FACET_NORMALIZER)
.and.returnValue(map(() => undefined))
.withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
.and.returnValue(map(() => undefined));
spyOn(productSearchService, 'getResults').and.returnValue(
of(emptyPageSearchResults)
);
spyOn(routingService, 'getPageContext').and.returnValue(
of(new PageContext('brand123', PageType.CATEGORY_PAGE))
);
let merchandisingUserContext: MerchandisingUserContext;
cdsMerchandisingUserContextService
.getUserContext()
.subscribe(userContext => (merchandisingUserContext = userContext))
.unsubscribe();
expect(merchandisingUserContext).toEqual(expectedUserContext);
});
const merchandisingFacets = [
{
code: pageSearchResults.breadcrumbs[0].facetCode,
value: pageSearchResults.breadcrumbs[0].facetValueCode,
},
{
code: pageSearchResults.breadcrumbs[1].facetCode,
value: pageSearchResults.breadcrumbs[1].facetValueCode,
},
];
const queryParams = `${merchandisingFacets[0].code}:${merchandisingFacets[0].value}:${merchandisingFacets[1].code}:${merchandisingFacets[1].value}`;
spyOn(routingService, 'getPageContext').and.returnValue(
of(new PageContext('homepage', PageType.CONTENT_PAGE))
);
spyOn(productSearchService, 'getResults').and.returnValue(
of(pageSearchResults)
);
spyOn(converterService, 'pipeable')
.withArgs(MERCHANDISING_FACET_NORMALIZER)
.and.returnValue(map(() => merchandisingFacets))
.withArgs(MERCHANDISING_FACET_TO_QUERYPARAM_NORMALIZER)
.and.returnValue(map(() => queryParams));
let merchandisingUserContext: MerchandisingUserContext;
cdsMerchandisingUserContextService
.getUserContext()
.subscribe(userContext => (merchandisingUserContext = userContext))
.unsubscribe();
expect(merchandisingUserContext).toEqual(undefined);