CSR-98 Fix tests

This commit is contained in:
Katie 2022-03-24 16:59:30 -04:00
commit 61c8dc70c9
4 changed files with 48 additions and 48 deletions

View file

@ -36,7 +36,7 @@ export async function saveOrder() {
*/ */
export async function loadOrderIfPresent() { export async function loadOrderIfPresent() {
console.log("attempting to load referral...."); console.log("attempting to load referral....");
const conceptCookie = getConceptCookie(); const conceptCookie = this.getConceptCookie();
// Do nothing if there is no cookie or no correlation id. // Do nothing if there is no cookie or no correlation id.
if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) { if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) {
@ -180,7 +180,7 @@ export function isSavedSessionStillActive() {
export async function navigateToHeritageFunnel() { export async function navigateToHeritageFunnel() {
// Create the order (or save existing order) when navigating to Heritage Funnel. // Create the order (or save existing order) when navigating to Heritage Funnel.
await saveOrder(); await this.saveOrder();
router.navigateToExternalUrl( router.navigateToExternalUrl(
externalUrls.HERITAGE_FUNNEL, externalUrls.HERITAGE_FUNNEL,

View file

@ -7,13 +7,14 @@ import store from "@/store";
import router from "@/router"; import router from "@/router";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
import baseMixin from "@/mixins/base-mixin"; import baseMixin from "@/mixins/base-mixin";
import { externalUrls } from "@/router/router-constants/externalUrl-values";
describe("loadReferralFromHeritageFunnelIfPresent", () => { describe("loadOrderIfPresent", () => {
afterEach(() => { afterEach(() => {
removeAllTestCookies(); removeAllTestCookies();
}); });
test("ShouldResetState == true => heritage cookie is deleted", () => { test("ShouldResetState == true => concept cookie is deleted", () => {
// Arrange // Arrange
const testShouldResetState = true; const testShouldResetState = true;
@ -24,7 +25,7 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => {
document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`; document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`;
// Act // Act
helper.loadReferralFromHeritageFunnelIfPresent(); helper.loadOrderIfPresent();
// Assert // Assert
expect(document.cookie).toBe(""); expect(document.cookie).toBe("");
@ -32,8 +33,8 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => {
test("ShouldResetState == true => reset store", () => { test("ShouldResetState == true => reset store", () => {
// Arrange // Arrange
const getHeritageCookieValueMethod = jest.spyOn(helper, "getHeritageCookieValue") const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie")
getHeritageCookieValueMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } }); getConceptCookieMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } });
const mockData = { const mockData = {
actionList: [{ actionList: [{
@ -44,20 +45,19 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => {
setupMocksForJsFiles(mockData); setupMocksForJsFiles(mockData);
// Act // Act
helper.loadReferralFromHeritageFunnelIfPresent(); helper.loadOrderIfPresent();
// Assert // Assert
expect(getHeritageCookieValueMethod).toHaveBeenCalled(); expect(getConceptCookieMethod).toHaveBeenCalled();
expect(baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE); expect(baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE);
getHeritageCookieValueMethod.mockRestore(); getConceptCookieMethod.mockRestore();
// store.dispatch.mockRestore();
}); });
test("Heritage cookie is null => store is unchanged", () => { test("Concept cookie is null => store is unchanged", () => {
// Arrange // Arrange
const getHeritageCookieValueMethod = jest.spyOn(helper, "getHeritageCookieValue") const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie")
getHeritageCookieValueMethod.mockImplementation(() => null); getConceptCookieMethod.mockImplementation(() => null);
store.dispatch = jest.spyOn(store, "dispatch"); store.dispatch = jest.spyOn(store, "dispatch");
@ -70,14 +70,13 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => {
setupMocksForJsFiles(mockData); setupMocksForJsFiles(mockData);
// Act // Act
helper.loadReferralFromHeritageFunnelIfPresent(); helper.loadOrderIfPresent();
// Assert // Assert
expect(helper.getHeritageCookieValue).toHaveBeenCalled(); expect(helper.getConceptCookie).toHaveBeenCalled();
expect(store.dispatch).not.toHaveBeenCalledWith(storeActions.RESET_STATE); expect(store.dispatch).not.toHaveBeenCalledWith(storeActions.RESET_STATE);
getHeritageCookieValueMethod.mockRestore(); getConceptCookieMethod.mockRestore();
store.dispatch.mockRestore();
}); });
}); });
@ -113,11 +112,12 @@ describe("saveOrder", () => {
await helper.saveOrder(); await helper.saveOrder();
// Assert // Assert
expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SAVE_ORDER);
expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SET_REFERRAL_INFORMATION, { expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SET_REFERRAL_INFORMATION, {
referralNumber: mockReferralNumber, referralNumber: mockReferralNumber,
referralDate: mockReferralDate, referralDate: mockReferralDate,
referralCorrelationId: mockCorrelationId referralCorrelationId: mockCorrelationId
}); }, false);
}); });
test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => { test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
@ -146,13 +146,13 @@ describe("saveOrder", () => {
DidHeritageFunnelUpdateLast: true DidHeritageFunnelUpdateLast: true
} }
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) });
// Act // Act
await helper.saveOrder(); await helper.saveOrder();
// Assert // Assert
expect(helper.getHeritageCookieValue().DidHeritageFunnelUpdateLast).toEqual(false); expect(helper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false);
}); });
}); });
@ -169,12 +169,12 @@ describe("navigateToHeritageFunnel", () => {
actionList: [{ actionList: [{
actionName: storeActions.SAVE_ORDER, actionName: storeActions.SAVE_ORDER,
data: mockOrderInfo, data: mockOrderInfo,
}], }]
router: router
} }
setupMocksForJsFiles(mockData); setupMocksForJsFiles(mockData);
const saveOrderFunction = jest.spyOn(helper, "saveOrder"); const saveOrderFunction = jest.spyOn(helper, "saveOrder");
router.navigateToExternalUrl = jest.fn();
// Act // Act
await helper.navigateToHeritageFunnel(); await helper.navigateToHeritageFunnel();
@ -184,7 +184,7 @@ describe("navigateToHeritageFunnel", () => {
// Should alway save before we navigate to heritage // Should alway save before we navigate to heritage
const saveOrderFunctionCallOrder = saveOrderFunction.mock.invocationCallOrder[0]; const saveOrderFunctionCallOrder = saveOrderFunction.mock.invocationCallOrder[0];
const routerNavigateFunctionCallOrder = router.navigate.mock.invocationCallOrder[0]; const routerNavigateFunctionCallOrder = router.navigateToExternalUrl.mock.invocationCallOrder[0];
expect(saveOrderFunctionCallOrder).toBeLessThan(routerNavigateFunctionCallOrder); expect(saveOrderFunctionCallOrder).toBeLessThan(routerNavigateFunctionCallOrder);
saveOrderFunction.mockRestore(); saveOrderFunction.mockRestore();
}); });
@ -201,18 +201,21 @@ describe("navigateToHeritageFunnel", () => {
actionList: [{ actionList: [{
actionName: storeActions.SAVE_ORDER, actionName: storeActions.SAVE_ORDER,
data: mockOrderInfo, data: mockOrderInfo,
}], }]
router: router
} }
const mocks = setupMocksForJsFiles(mockData); setupMocksForJsFiles(mockData);
store.getters.order.referralCorrelationId = mockCorrelationId
router.navigateToExternalUrl = jest.fn();
// Act // Act
await helper.navigateToHeritageFunnel(); await helper.navigateToHeritageFunnel();
// Assert // Assert
expect(router.navigate).toHaveBeenCalled(); expect(router.navigateToExternalUrl).toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith(navigationScenarios.MOVE_TO_HERITAGE_FUNNEL, expect.anything(), expect(router.navigateToExternalUrl).toHaveBeenCalledWith(externalUrls.HERITAGE_FUNNEL,
expect.objectContaining({ expect.objectContaining({
corid: mockCorrelationId corid: mockCorrelationId
}) })
@ -225,7 +228,7 @@ describe("cookies", () => {
removeAllTestCookies(); removeAllTestCookies();
}) })
describe("getHeritageCookieValue method", () => { describe("getConceptCookie method", () => {
test("gets correct value when cookie is present", () => { test("gets correct value when cookie is present", () => {
// Arrange // Arrange
const testReferralNumber = 1566818; const testReferralNumber = 1566818;
@ -241,10 +244,10 @@ describe("cookies", () => {
ShouldResetState: testShouldResetState, ShouldResetState: testShouldResetState,
DidHeritageFunnelUpdateLast: testDidHeritageFunnelUpdateLast DidHeritageFunnelUpdateLast: testDidHeritageFunnelUpdateLast
} }
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) });
// Act // Act
var result = helper.getHeritageCookieValue(); var result = helper.getConceptCookie();
// Assert // Assert
expect(result).toEqual(testCookieValue); expect(result).toEqual(testCookieValue);
@ -259,10 +262,10 @@ describe("cookies", () => {
test("returns empty object when value is empty object", () => { test("returns empty object when value is empty object", () => {
// Arrange // Arrange
const testCookieValue = {}; const testCookieValue = {};
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) });
// Act // Act
var result = helper.getHeritageCookieValue(); var result = helper.getConceptCookie();
// Assert // Assert
expect(result).toEqual(testCookieValue); expect(result).toEqual(testCookieValue);
@ -273,21 +276,21 @@ describe("cookies", () => {
test("returns null when value is empty string", () => { test("returns null when value is empty string", () => {
// Arrange // Arrange
const testCookieValue = ""; const testCookieValue = "";
setupCookies({ heritageCookieValue: testCookieValue }); setupCookies({ conceptCookieValue: testCookieValue });
// Act // Act
var result = helper.getHeritageCookieValue(); var result = helper.getConceptCookie();
// Assert // Assert
expect(result).toEqual(null); expect(result).toEqual(null);
}); });
test("returns null when heritage cookie doesn't exist", () => { test("returns null when concept cookie doesn't exist", () => {
// Arrange // Arrange
setupCookies({ includeHeritageCookie: false }); setupCookies({ includeHeritageCookie: false });
// Act // Act
var result = helper.getHeritageCookieValue(); var result = helper.getConceptCookie();
// Assert // Assert
expect(result).toEqual(null); expect(result).toEqual(null);
@ -297,10 +300,10 @@ describe("cookies", () => {
// Arrange // Arrange
const testCookieValue = { test: "testValue" }; const testCookieValue = { test: "testValue" };
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) });
// Act // Act
const actualCookieValue = helper.getHeritageCookieValue(); const actualCookieValue = helper.getConceptCookie();
// Assert // Assert
expect(actualCookieValue).toEqual(testCookieValue); expect(actualCookieValue).toEqual(testCookieValue);
@ -311,7 +314,7 @@ describe("cookies", () => {
setupCookies({ includeHeritageCookie: false }); setupCookies({ includeHeritageCookie: false });
// Act // Act
const actualCookieValue = helper.getHeritageCookieValue(); const actualCookieValue = helper.getConceptCookie();
// Assert // Assert
expect(actualCookieValue).toBeNull(); expect(actualCookieValue).toBeNull();
@ -330,9 +333,9 @@ const cookies = {
"addshoppers.com": "2%7C1%3A0%7C10%3A1646681050%7C15%3Aaddshoppers.com%7C44%3AODM1OTczNWI0MmFjNGNmMmExNDY3OWRlNTQ1NmM5MGY%3D%7Cef2a50fafe40fc5abf641a14ee5541c70bef2950666f59d3a809fd9352c7b963" "addshoppers.com": "2%7C1%3A0%7C10%3A1646681050%7C15%3Aaddshoppers.com%7C44%3AODM1OTczNWI0MmFjNGNmMmExNDY3OWRlNTQ1NmM5MGY%3D%7Cef2a50fafe40fc5abf641a14ee5541c70bef2950666f59d3a809fd9352c7b963"
}; };
function setupCookies({ heritageCookieValue = "", includeHeritageCookie = true }) { function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) {
Object.keys(cookies).forEach(key => { Object.keys(cookies).forEach(key => {
const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? heritageCookieValue : cookies[key]; const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key];
if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO) if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO)
document.cookie = `${key}=${cookieValue}; path=/;`; document.cookie = `${key}=${cookieValue}; path=/;`;

View file

@ -81,8 +81,5 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) {
export function setupMocksForJsFiles(mockData = {}) { export function setupMocksForJsFiles(mockData = {}) {
setupBaseMixinDispatchNonBlockingStoreAction(mockData); setupBaseMixinDispatchNonBlockingStoreAction(mockData);
if (mockData.router)
mockData.router.navigate = jest.fn();
return { baseMixin }; return { baseMixin };
} }

View file

@ -173,7 +173,7 @@ export const mutations = {
// Misc Mutations // Misc Mutations
setLoadOrderInformation(state, orderInformation) { setLoadOrderInformation(state, orderInformation) {
state.order.referralNumber = orderInformation.referralNumber; state.order.referralNumber = orderInformation.referralNumber;
state.order.referralDate = orderInformation.referralDate; state.order.referralDate = orderInformation.referralDate;
state.order.referralCorrelationId = orderInformation.referralCorrelationId; state.order.referralCorrelationId = orderInformation.referralCorrelationId;
state.order.vehicle = { state.order.vehicle = {
year: orderInformation.vehicle?.year, year: orderInformation.vehicle?.year,
@ -383,7 +383,7 @@ export const actions = {
}); });
}, },
loadOrder(context, {referralNumber, referralDate, referralCorrelationId}) { loadOrder(context, { referralNumber, referralDate, referralCorrelationId }) {
return globalMethods.callHttpClient({ return globalMethods.callHttpClient({
method: endpoints.LoadOrder.method, method: endpoints.LoadOrder.method,
endpoint: endpoints.LoadOrder.url, endpoint: endpoints.LoadOrder.url,