-
Notifications
You must be signed in to change notification settings - Fork 5
DINT-1856: Allow custom context for multiple ProductListItems #188
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d1b6c7
DINT-1856:
NadiyaS 0df4242
Use custom context for product List itmes
benjaminkalk bb8fc77
update documentation
benjaminkalk 365ae51
add custom context test, fix context manipulation issue
benjaminkalk cca268a
remove console log
benjaminkalk d26a349
add note to custom event override doc
benjaminkalk 9cfe713
Update custom context doc
benjaminkalk cf71ebe
Fix doc spacing
benjaminkalk 107bbb9
lint fix
benjaminkalk e34bcfc
Fix typo
benjaminkalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/storefront-events-collector/tests/handlers/shoppingCart/shoppingCartViewAep.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| jest.mock("../../../src/alloy"); | ||
| import { Event } from "@adobe/magento-storefront-events-sdk/dist/types/types/events"; | ||
| import { sendEvent } from "../../../src/alloy"; | ||
| import { shoppingCartViewHandlerAEP } from "../../../src/handlers"; | ||
| import { mockEvent } from "../../utils/mocks"; | ||
|
|
||
| const AEPevent = { ...mockEvent }; | ||
| delete AEPevent.eventInfo.customContext; | ||
|
|
||
| test("correctly structures AEP event and calls alloy.sendEvent", () => { | ||
| shoppingCartViewHandlerAEP(mockEvent); | ||
|
|
||
| expect(sendEvent).toHaveBeenCalledTimes(1); | ||
|
|
||
| expect(sendEvent).toHaveBeenCalledWith( | ||
| { | ||
| commerce: { | ||
| cart: { | ||
| cartID: "111111", | ||
| }, | ||
| productListViews: { | ||
| value: 1, | ||
| }, | ||
| commerceScope: { | ||
| environmentID: "aaaaaa", | ||
| storeCode: "magento", | ||
| storeViewCode: "default", | ||
| websiteCode: "website", | ||
| }, | ||
| order: { | ||
| discountAmount: 0, | ||
| }, | ||
| }, | ||
| productListItems: [ | ||
| { | ||
| SKU: "ts001", | ||
| name: "T-Shirt", | ||
| quantity: 1, | ||
| priceTotal: 20, | ||
| productImageUrl: undefined, | ||
| currencyCode: "USD", | ||
| discountAmount: 0, | ||
| selectedOptions: [], | ||
| }, | ||
| { | ||
| SKU: "h001", | ||
| name: "Hoodie", | ||
| quantity: 1, | ||
| priceTotal: 50, | ||
| productImageUrl: undefined, | ||
| currencyCode: "USD", | ||
| discountAmount: 0, | ||
| selectedOptions: [], | ||
| }, | ||
| ], | ||
| _id: undefined, | ||
| eventType: "commerce.productListViews", | ||
| }, | ||
| mockEvent, | ||
| ); | ||
| }); | ||
|
|
||
| test("correctly structures AEP event with customContext and calls alloy.sendEvent", () => { | ||
| const customContext = { | ||
| commerce: { | ||
| order: { | ||
| couponCode: "couponCode123", | ||
| }, | ||
| }, | ||
| productListItems: [ | ||
| { | ||
| SKU: "ts001", | ||
| name: "Custom Product Name", | ||
| categoryId: "customCat001", | ||
| }, | ||
| ], | ||
| }; | ||
| const mockedAEPevent = { | ||
| event: "shopping-cart-view", | ||
| eventInfo: { | ||
| ...AEPevent.eventInfo, | ||
| customContext, | ||
| }, | ||
| } as Event; | ||
|
|
||
| shoppingCartViewHandlerAEP(mockedAEPevent); | ||
|
|
||
| expect(sendEvent).toHaveBeenCalledTimes(1); | ||
|
|
||
| expect(sendEvent).toHaveBeenCalledWith( | ||
| { | ||
| commerce: { | ||
| cart: { | ||
| cartID: "111111", | ||
| }, | ||
| productListViews: { | ||
| value: 1, | ||
| }, | ||
| commerceScope: { | ||
| environmentID: "aaaaaa", | ||
| storeCode: "magento", | ||
| storeViewCode: "default", | ||
| websiteCode: "website", | ||
| }, | ||
| order: { | ||
| discountAmount: 0, | ||
| couponCode: customContext.commerce.order.couponCode, | ||
| }, | ||
| }, | ||
| productListItems: [ | ||
| { | ||
| SKU: "ts001", | ||
| name: customContext.productListItems[0].name, | ||
| quantity: 1, | ||
| priceTotal: 20, | ||
| productImageUrl: undefined, | ||
| currencyCode: "USD", | ||
| discountAmount: 0, | ||
| selectedOptions: [], | ||
| categoryId: customContext.productListItems[0].categoryId, | ||
| }, | ||
| { | ||
| SKU: "h001", | ||
| name: "Hoodie", | ||
| quantity: 1, | ||
| priceTotal: 50, | ||
| productImageUrl: undefined, | ||
| currencyCode: "USD", | ||
| discountAmount: 0, | ||
| selectedOptions: [], | ||
| }, | ||
| ], | ||
| _id: undefined, | ||
| eventType: "commerce.productListViews", | ||
| }, | ||
| mockedAEPevent, | ||
| ); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.