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

Update createOrder to send SLAS USID #920

Merged
merged 5 commits into from
Jan 24, 2023
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 @@ -365,6 +365,11 @@ export default function useBasket(opts = {}) {
*/
async createOrder() {
const response = await api.shopperOrders.createOrder({
// We send the SLAS usid via this header. This is required by ECOM to map
// Einstein events sent via the API with the finishOrder event fired by ECOM
// when an Order transitions from Created to New status.
// Without this, various order conversion metrics will not appear on reports and dashboards
headers: {_sfdc_customer_id: api.auth.usid},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a test to confirm the expected header is sent when creating orders?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a change to the existing test to add the header. However, I'm not sure of a good way to test this change via unit test. The header does not modify the order response in any way.

I could make setting the header a requirement in OcapiShopperOrders but I don't know of this is a good change (ie. sites that don't use Einstein will have no need to set this header).

body: {basketId: basket.basketId}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ describe('CommerceAPI', () => {
const api = getAPI()
fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse))
const response = await api.shopperOrders.createOrder({
headers: {_sfdc_customer_id: 'usid'},
parameters: {},
body: {basketId: ''}
})
Expand All @@ -695,6 +696,7 @@ describe('CommerceAPI', () => {
const api = getAPI()
fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse))
const response = await api.shopperOrders.createOrder({
headers: {_sfdc_customer_id: 'usid'},
parameters: {}
})
expect(response.title).toEqual('Body is required for this request')
Expand All @@ -704,6 +706,7 @@ describe('CommerceAPI', () => {
const api = getAPI()
fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse))
const response = await api.shopperOrders.getOrder({
headers: {_sfdc_customer_id: 'usid'},
parameters: {orderNo: ''}
})
expect(response).toBeDefined()
Expand All @@ -713,6 +716,7 @@ describe('CommerceAPI', () => {
const api = getAPI()
fetch.mockResponseOnce(JSON.stringify(ocapiBasketResponse))
const response = await api.shopperOrders.getOrder({
headers: {_sfdc_customer_id: 'usid'},
parameters: {}
})
expect(response.title).toEqual(
Expand All @@ -728,6 +732,7 @@ describe('CommerceAPI', () => {
await expect(
api.shopperOrders.createOrder({
parameters: {},
headers: {_sfdc_customer_id: 'usid'},
body: {basketId: ''}
})
).rejects.toThrow(ocapiFaultResponse.fault.message)
Expand Down