CSR-98 Fix tests

This commit is contained in:
Katie 2022-03-30 13:34:14 -04:00
parent 5803b4dcbb
commit b98ec44714
3 changed files with 8 additions and 2 deletions

View file

@ -42,6 +42,7 @@ export function getFunnelCookie() {
Removes cookie from browser.
*/
export function deleteFunnelCookie() {
console.log("hi there")
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`;
}

View file

@ -10,6 +10,7 @@ import baseMixin from "@/mixins/base-mixin";
*/
export async function loadOrderIfPresent() {
const funnelCookie = getFunnelCookie();
console.log(funnelCookie)
// Do nothing if there is no cookie or no correlation id.
if (funnelCookie == null || funnelCookie.ReferralCorrelationId == null) {
@ -20,6 +21,7 @@ export async function loadOrderIfPresent() {
if (funnelCookie.ShouldResetState) {
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie();
console.log("sup")
return null;
}

View file

@ -13,18 +13,21 @@ describe("loadOrderIfPresent", () => {
test("ShouldResetState == true => funnel cookie is deleted", () => {
// Arrange
cookieHelper.deleteFunnelCookie = jest.spyOn(cookieHelper, "deleteFunnelCookie");
const testShouldResetState = true;
const testCookieValue = {
ShouldResetState: testShouldResetState
ShouldResetState: testShouldResetState,
ReferralCorrelationId: "xxx"
}
document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; ${cookieHelper.getCookieDomainValue()}`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(testCookieValue)}; path=/; ${cookieHelper.getCookieDomainValue()}`;
// Act
loadOrderIfPresent();
// Assert
expect(cookieHelper.deleteFunnelCookie).toHaveBeenCalled();
expect(document.cookie).toBe("");
});