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. Removes cookie from browser.
*/ */
export function deleteFunnelCookie() { export function deleteFunnelCookie() {
console.log("hi there")
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`; 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() { export async function loadOrderIfPresent() {
const funnelCookie = getFunnelCookie(); const funnelCookie = getFunnelCookie();
console.log(funnelCookie)
// Do nothing if there is no cookie or no correlation id. // Do nothing if there is no cookie or no correlation id.
if (funnelCookie == null || funnelCookie.ReferralCorrelationId == null) { if (funnelCookie == null || funnelCookie.ReferralCorrelationId == null) {
@ -20,6 +21,7 @@ export async function loadOrderIfPresent() {
if (funnelCookie.ShouldResetState) { if (funnelCookie.ShouldResetState) {
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie(); deleteFunnelCookie();
console.log("sup")
return null; return null;
} }

View file

@ -13,18 +13,21 @@ describe("loadOrderIfPresent", () => {
test("ShouldResetState == true => funnel cookie is deleted", () => { test("ShouldResetState == true => funnel cookie is deleted", () => {
// Arrange // Arrange
cookieHelper.deleteFunnelCookie = jest.spyOn(cookieHelper, "deleteFunnelCookie");
const testShouldResetState = true; const testShouldResetState = true;
const testCookieValue = { 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 // Act
loadOrderIfPresent(); loadOrderIfPresent();
// Assert // Assert
expect(cookieHelper.deleteFunnelCookie).toHaveBeenCalled();
expect(document.cookie).toBe(""); expect(document.cookie).toBe("");
}); });