Updates
This commit is contained in:
parent
0d981dde56
commit
e230bdd345
7 changed files with 15355 additions and 68 deletions
15261
package-lock.json
generated
15261
package-lock.json
generated
File diff suppressed because it is too large
Load diff
3
src/constants/header-keys.js
Normal file
3
src/constants/header-keys.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export const headerKeys = {
|
||||||
|
EXPERIMENT: "X-Experiment-Data",
|
||||||
|
};
|
||||||
|
|
@ -3,6 +3,8 @@ import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||||
|
|
||||||
import { applicationConfig } from "@/constants/application-config.js";
|
import { applicationConfig } from "@/constants/application-config.js";
|
||||||
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||||
|
import { headerKeys } from "@/constants/header-keys";
|
||||||
|
import { useMainStore } from "@/store";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
callHttpClient({ method, endpoint, payload, logApiCall = true}) {
|
callHttpClient({ method, endpoint, payload, logApiCall = true}) {
|
||||||
|
|
@ -10,7 +12,7 @@ export default {
|
||||||
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
||||||
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "SelfService" });
|
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "SelfService" });
|
||||||
const headers = {
|
const headers = {
|
||||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings),
|
[headerKeys.EXPERIMENT]: JSON.stringify(useMainStore.getters.experimentSettings),
|
||||||
};
|
};
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
|
|
|
||||||
|
|
@ -20,27 +20,125 @@ const mockMixin = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Common methods
|
// Common methods
|
||||||
export function getMountOptions(mockData) {
|
export function getMountOptions(mockData) {
|
||||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||||
const mocks = {};
|
const mocks = {};
|
||||||
|
|
||||||
|
//this is mocking if you use the mixin directly(baseMixin.methods.dispatchStoreAction) vs this.dispatchStoreAction
|
||||||
|
setupBaseMixinDispatchStoreAction(mockData);
|
||||||
|
|
||||||
// Mock const files
|
mocks.pushEventToGA = jest.fn();
|
||||||
mocks.storeActions = storeActions;
|
mocks.pushPageViewToGA = jest.fn();
|
||||||
mocks.navigationScenarios = navigationScenarios;
|
mocks.logEvent = jest.fn();
|
||||||
mocks.vehicleCategories = vehicleCategories;
|
mocks.pushExperimentsToDataLayer = jest.fn();
|
||||||
mocks.issPageValues = issPageValues;
|
mocks.prependActionToMethod = jest.fn();
|
||||||
mocks.queryStrings = queryStrings;
|
mocks.dispatchStoreAction = jest.fn();
|
||||||
|
mocks.dispatchStoreAction.mockImplementation((actionName) => {
|
||||||
|
let actionFilterResult = mockData.actionList?.filter((x) => x.actionName == actionName);
|
||||||
|
|
||||||
|
if (actionFilterResult?.length === 1) {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: actionFilterResult[0].data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const global = {
|
// Mock const files
|
||||||
mocks: mocks,
|
mocks.storeActions = storeActions;
|
||||||
mixins: [mockMixin],
|
mocks.storeMutations = storeMutations;
|
||||||
plugins: [pinia],
|
mocks.navigationScenarios = navigationScenarios;
|
||||||
stubs: { Form }
|
mocks.vehicleCategories = vehicleCategories;
|
||||||
};
|
mocks.fmgPageValues = fmgPageValues;
|
||||||
|
mocks.analyticsPageEvents = analyticsPageEvents;
|
||||||
|
mocks.GaCategories = GaCategories;
|
||||||
|
mocks.GaActions = GaActions;
|
||||||
|
mocks.GaLabels = GaLabels;
|
||||||
|
mocks.GaEvents = GaEvents;
|
||||||
|
mocks.ValueToLogTypes = ValueToLogTypes;
|
||||||
|
mocks.queryStrings = queryStrings;
|
||||||
|
mocks.routerParams = routerParams;
|
||||||
|
|
||||||
return { global };
|
// Mock $store and $router when accessing this.$store/$router
|
||||||
|
mocks.$store = mockData.store;
|
||||||
|
mocks.$router = mockData.router;
|
||||||
|
mocks.$route = mockData.route;
|
||||||
|
mocks.$loadScript = mockData.loadScript;
|
||||||
|
|
||||||
|
const global = {
|
||||||
|
mocks: mocks,
|
||||||
|
mixins: mockData.mixins,
|
||||||
|
plugins: [pinia],
|
||||||
|
stubs: { Form }
|
||||||
|
};
|
||||||
|
|
||||||
|
return { global };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupMocksForJsFiles(mockData = {}) {
|
||||||
|
setupBaseMixinDispatchStoreAction(mockData);
|
||||||
|
|
||||||
|
return { baseMixin };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heritage integration common methods
|
||||||
|
export const cookies = {
|
||||||
|
[cookieNames.FUNNEL_SESSION_INFO]: `{"ReferralNumber":"1566818","ReferralDate":"2022-03-15T10:56:24.597","ReferralCorrelationId":"404d2b04-f86e-45c3-b373-127b6217b060","ShouldResetState":false,"DidHeritageFunnelUpdateLast":true}`,
|
||||||
|
UNIQUE_SESSION_ID: "33756020-b58e-4ec7-b8b8-3f1576719c40",
|
||||||
|
anotherCookie: "{}",
|
||||||
|
someOtherCookie: "{}",
|
||||||
|
dxdev: "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
||||||
|
sid: "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
||||||
|
skey: "12345",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Removes test cookies for testing cookie-helper and order-helper
|
||||||
|
export function removeAllTestCookies() {
|
||||||
|
Object.keys(cookies).forEach((key) => {
|
||||||
|
document.cookie = `${key}=;Max-Age=0;`;
|
||||||
|
document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getMockOrderInfo(
|
||||||
|
mockReferralNumber,
|
||||||
|
mockCorrelationId,
|
||||||
|
mockReferralDate,
|
||||||
|
accountNumber = "0",
|
||||||
|
savedSessionId,
|
||||||
|
crmCustomerId
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
referralNumber: mockReferralNumber,
|
||||||
|
referralCorrelationId: mockCorrelationId,
|
||||||
|
referralDate: mockReferralDate,
|
||||||
|
accountNumber: accountNumber,
|
||||||
|
savedSessionId: savedSessionId,
|
||||||
|
crmCustomerId: crmCustomerId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = true }) {
|
||||||
|
Object.keys(cookies).forEach((key) => {
|
||||||
|
const cookieValue =
|
||||||
|
key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key];
|
||||||
|
if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO)
|
||||||
|
setCookieProperties({ [key]: cookieValue }, { isSecure: false });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private methods
|
||||||
|
function setupBaseMixinDispatchStoreAction(mockData) {
|
||||||
|
if (mockData.actionList !== undefined) {
|
||||||
|
baseMixin.methods.dispatchStoreAction = jest.fn();
|
||||||
|
baseMixin.methods.dispatchStoreAction.mockImplementation((actionName) => {
|
||||||
|
let actionFilterResult = mockData.actionList.filter((x) => x.actionName == actionName);
|
||||||
|
|
||||||
|
if (actionFilterResult.length > 0 && actionFilterResult.length === 1) {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: actionFilterResult[0].data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export default {
|
||||||
action: "",
|
action: "",
|
||||||
event: pageEvent,
|
event: pageEvent,
|
||||||
shouldUseSessionId: false,
|
shouldUseSessionId: false,
|
||||||
experimentsForUser: useMainStore.getters.applicationUser.experiments,
|
experimentsForUser: useMainStore.getters.applicationUserObj.experiments,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||||
|
|
@ -53,7 +53,7 @@ export default {
|
||||||
label: label,
|
label: label,
|
||||||
value: value,
|
value: value,
|
||||||
shouldUseSessionId: false,
|
shouldUseSessionId: false,
|
||||||
experimentsForUser: useMainStore.getters.applicationUser.experiments,
|
experimentsForUser: useMainStore.getters.applicationUserObj.experiments,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
||||||
|
|
@ -93,7 +93,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
pushExperimentsToDataLayer() {
|
pushExperimentsToDataLayer() {
|
||||||
const experiments = useMainStore.getters.applicationUser.experiments;
|
const experiments = useMainStore.getters.applicationUserObj.experiments;
|
||||||
experiments?.forEach((exp) => {
|
experiments?.forEach((exp) => {
|
||||||
// Set Google Dimension Index based on experiment settings.
|
// Set Google Dimension Index based on experiment settings.
|
||||||
let googleDimensionIndex = 99;
|
let googleDimensionIndex = 99;
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ router.afterEach((to, from) => {
|
||||||
// If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate
|
// If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate
|
||||||
if (eval(to.params.isSavingNavigation)) {
|
if (eval(to.params.isSavingNavigation)) {
|
||||||
if (
|
if (
|
||||||
store.getters.applicationUser.savedSessionId ||
|
store.applicationUser.savedSessionId ||
|
||||||
store.getters.order.customer?.emailAddress
|
store.order.customer?.emailAddress
|
||||||
) {
|
) {
|
||||||
saveSession();
|
saveSession();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ const getDefaultState = () => {
|
||||||
savedSessionId: null,
|
savedSessionId: null,
|
||||||
crmCustomerId: null,
|
crmCustomerId: null,
|
||||||
lastPageVisited: null,
|
lastPageVisited: null,
|
||||||
experiments: [],
|
|
||||||
triggeredSiteEntry: false,
|
triggeredSiteEntry: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -58,7 +57,7 @@ export const useMainStore = defineStore({
|
||||||
id: storeId,
|
id: storeId,
|
||||||
state: () => state,
|
state: () => state,
|
||||||
getters: {
|
getters: {
|
||||||
applicationUser: (state) => state.applicationUser,
|
applicationUserObj: (state) => state.applicationUser,
|
||||||
pageData: (state) => (page) => {
|
pageData: (state) => (page) => {
|
||||||
return state.applicationUser.pageData[page];
|
return state.applicationUser.pageData[page];
|
||||||
},
|
},
|
||||||
|
|
@ -117,13 +116,11 @@ export const useMainStore = defineStore({
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
experimentSettings: (state) =>
|
experimentSettings: (state) =>
|
||||||
state.applicationUser.experiments
|
state.applicationUser.experiments
|
||||||
.map((x) => x.settings)
|
.map((x) => x.settings)
|
||||||
.reduce((r, c) => Object.assign(r, c), {}) ?? {},
|
.reduce((r, c) => Object.assign(r, c), {}) ?? {}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
actions:
|
actions:
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue