Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tagging): make tagging and queryTagging optional #797

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SearchResponse {
facets?: Facet[];
partialResults?: PartialResult[];
promoteds?: Promoted[];
queryTagging: TaggingRequest;
queryTagging?: TaggingRequest;
redirections?: Redirection[];
results: Result[];
spellcheck?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/search-types/src/tagging.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TaggingRequest } from './request/tagging-request.model';
*/
export interface Taggable {
/** Tagging object containing the different taggable events. */
tagging: Tagging;
tagging?: Tagging;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('testing pdp add to cart', () => {
service.trackAddToCart();

expect(sessionGetItemSpy).toHaveBeenCalledWith(`add-to-cart-${productPathName}`);
expect(storeDispatchSpy).toHaveBeenCalledWith('x/tagging/track', result.tagging.add2cart);
expect(storeDispatchSpy).toHaveBeenCalledWith('x/tagging/track', result.tagging?.add2cart);

commitTaggingConfig(store, { clickedResultStorageKey: 'id', clickedResultStorageTTLMs });
service.storeResultClicked(result);
Expand All @@ -146,6 +146,14 @@ describe('testing pdp add to cart', () => {
service.trackAddToCart(id);

expect(sessionGetItemSpy).toHaveBeenCalledWith(`add-to-cart-${id}`);
expect(storeDispatchSpy).toHaveBeenCalledWith('x/tagging/track', result.tagging.add2cart);
expect(storeDispatchSpy).toHaveBeenCalledWith('x/tagging/track', result.tagging?.add2cart);
});

it('does not dispatch the add to track if result has no tagging', () => {
commitTaggingConfig(store, {});
service.storeResultClicked({ ...result, tagging: undefined });
service.trackAddToCart();

expect(storeDispatchSpy).not.toHaveBeenCalledWith('x/tagging/track', expect.anything());
});
});
4 changes: 2 additions & 2 deletions packages/x-components/src/x-modules/tagging/wiring.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Result, TaggingRequest } from '@empathyco/x-types';
import { Result, Tagging, TaggingRequest } from '@empathyco/x-types';
import { DefaultSessionService } from '@empathyco/x-utils';
import {
namespacedWireCommit,
Expand Down Expand Up @@ -147,7 +147,7 @@ export const trackAddToCartWire = createTrackResultWire('add2cart');
*
* @internal
*/
function createTrackResultWire(property: keyof Result['tagging']): Wire<Result> {
function createTrackResultWire(property: keyof Tagging): Wire<Result> {
return filter(
wireDispatch('track', ({ eventPayload: { tagging }, metadata: { location } }) => {
const taggingInfo: TaggingRequest = tagging[property];
Expand Down