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 { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||
import { headerKeys } from "@/constants/header-keys";
|
||||
import { useMainStore } from "@/store";
|
||||
|
||||
export default {
|
||||
callHttpClient({ method, endpoint, payload, logApiCall = true}) {
|
||||
|
|
@ -10,7 +12,7 @@ export default {
|
|||
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
||||
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "SelfService" });
|
||||
const headers = {
|
||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings),
|
||||
[headerKeys.EXPERIMENT]: JSON.stringify(useMainStore.getters.experimentSettings),
|
||||
};
|
||||
|
||||
axios({
|
||||
|
|
|
|||
|
|
@ -20,27 +20,125 @@ const mockMixin = {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Common methods
|
||||
export function getMountOptions(mockData) {
|
||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||
const mocks = {};
|
||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||
const mocks = {};
|
||||
|
||||
//this is mocking if you use the mixin directly(baseMixin.methods.dispatchStoreAction) vs this.dispatchStoreAction
|
||||
setupBaseMixinDispatchStoreAction(mockData);
|
||||
|
||||
// Mock const files
|
||||
mocks.storeActions = storeActions;
|
||||
mocks.navigationScenarios = navigationScenarios;
|
||||
mocks.vehicleCategories = vehicleCategories;
|
||||
mocks.issPageValues = issPageValues;
|
||||
mocks.queryStrings = queryStrings;
|
||||
mocks.pushEventToGA = jest.fn();
|
||||
mocks.pushPageViewToGA = jest.fn();
|
||||
mocks.logEvent = jest.fn();
|
||||
mocks.pushExperimentsToDataLayer = jest.fn();
|
||||
mocks.prependActionToMethod = jest.fn();
|
||||
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 = {
|
||||
mocks: mocks,
|
||||
mixins: [mockMixin],
|
||||
plugins: [pinia],
|
||||
stubs: { Form }
|
||||
};
|
||||
// Mock const files
|
||||
mocks.storeActions = storeActions;
|
||||
mocks.storeMutations = storeMutations;
|
||||
mocks.navigationScenarios = navigationScenarios;
|
||||
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: "",
|
||||
event: pageEvent,
|
||||
shouldUseSessionId: false,
|
||||
experimentsForUser: useMainStore.getters.applicationUser.experiments,
|
||||
experimentsForUser: useMainStore.getters.applicationUserObj.experiments,
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||
|
|
@ -53,7 +53,7 @@ export default {
|
|||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: false,
|
||||
experimentsForUser: useMainStore.getters.applicationUser.experiments,
|
||||
experimentsForUser: useMainStore.getters.applicationUserObj.experiments,
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
||||
|
|
@ -93,7 +93,7 @@ export default {
|
|||
},
|
||||
|
||||
pushExperimentsToDataLayer() {
|
||||
const experiments = useMainStore.getters.applicationUser.experiments;
|
||||
const experiments = useMainStore.getters.applicationUserObj.experiments;
|
||||
experiments?.forEach((exp) => {
|
||||
// Set Google Dimension Index based on experiment settings.
|
||||
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 (eval(to.params.isSavingNavigation)) {
|
||||
if (
|
||||
store.getters.applicationUser.savedSessionId ||
|
||||
store.getters.order.customer?.emailAddress
|
||||
store.applicationUser.savedSessionId ||
|
||||
store.order.customer?.emailAddress
|
||||
) {
|
||||
saveSession();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ const getDefaultState = () => {
|
|||
savedSessionId: null,
|
||||
crmCustomerId: null,
|
||||
lastPageVisited: null,
|
||||
experiments: [],
|
||||
triggeredSiteEntry: false,
|
||||
},
|
||||
};
|
||||
|
|
@ -58,7 +57,7 @@ export const useMainStore = defineStore({
|
|||
id: storeId,
|
||||
state: () => state,
|
||||
getters: {
|
||||
applicationUser: (state) => state.applicationUser,
|
||||
applicationUserObj: (state) => state.applicationUser,
|
||||
pageData: (state) => (page) => {
|
||||
return state.applicationUser.pageData[page];
|
||||
},
|
||||
|
|
@ -117,13 +116,11 @@ export const useMainStore = defineStore({
|
|||
),
|
||||
],
|
||||
};
|
||||
},
|
||||
experimentSettings: (state) =>
|
||||
state.applicationUser.experiments
|
||||
.map((x) => x.settings)
|
||||
.reduce((r, c) => Object.assign(r, c), {}) ?? {},
|
||||
|
||||
|
||||
},
|
||||
experimentSettings: (state) =>
|
||||
state.applicationUser.experiments
|
||||
.map((x) => x.settings)
|
||||
.reduce((r, c) => Object.assign(r, c), {}) ?? {}
|
||||
},
|
||||
actions:
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue