session helper unit tests
This commit is contained in:
parent
5da7037e4d
commit
4ee9a3fd06
2 changed files with 91 additions and 2 deletions
|
|
@ -47,7 +47,7 @@ describe("loadOrderIfPresent", () => {
|
|||
expect(cookieHelper.getConceptCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE);
|
||||
|
||||
cookieHelper.getConceptCookie.mockRestore();
|
||||
|
||||
// store.dispatch.mockRestore();
|
||||
});
|
||||
|
||||
|
|
@ -69,8 +69,30 @@ describe("loadOrderIfPresent", () => {
|
|||
// Assert
|
||||
expect(cookieHelper.getConceptCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).not.toHaveBeenCalledWith(storeActions.RESET_STATE);
|
||||
});
|
||||
|
||||
cookieHelper.getConceptCookie.mockRestore();
|
||||
test("Concept cookie valid, should call loadOrder", async () => {
|
||||
// Arrange
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValueOnce({ ShouldResetState: false, ReferralNumber: 123456, ReferralCorrelationId: "yyy-yyy-yyyy", ReferralDate: new Date()});
|
||||
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.LOAD_ORDER,
|
||||
data: { ReferralNumber: 123456, vehicle: { year: 2010 } }
|
||||
}],
|
||||
}
|
||||
|
||||
var mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
const result = await loadOrderIfPresent();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.getConceptCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).not.toHaveBeenCalledWith(storeActions.LOAD_ORDER);
|
||||
expect(result.ReferralNumber).toBe(123456);
|
||||
expect(result.vehicle.year).toBe(2010);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
67
src/helpers/heritage-integration/session-helper.spec.js
Normal file
67
src/helpers/heritage-integration/session-helper.spec.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { isAnalyticsSessionStillActive, isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
||||
|
||||
describe("isAnalyticsSessionStillActive", () => {
|
||||
test("isAnalyticsSessionStillActive, should return true", () => {
|
||||
// Arrange
|
||||
const mockDate = new Date(new Date().toUTCString())
|
||||
mockDate.setDate(mockDate.getDate() + 1)
|
||||
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValue({ LastTouched: mockDate });
|
||||
|
||||
// Act
|
||||
const result = isAnalyticsSessionStillActive();
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("isAnalyticsSessionStillActive, should return false", () => {
|
||||
// Arrange
|
||||
const mockDate = new Date(new Date().toUTCString())
|
||||
mockDate.setDate(mockDate.getDate() - 1)
|
||||
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValue({ LastTouched: mockDate });
|
||||
|
||||
// Act
|
||||
const result = isAnalyticsSessionStillActive();
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isSavedSessionStillActive", () => {
|
||||
test("isSavedSessionStillActive, should return true", () => {
|
||||
// Arrange
|
||||
const mockDate = new Date(new Date().toUTCString())
|
||||
mockDate.setDate(mockDate.getDate() + 1);
|
||||
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValue({ SavedQuoteTimeoutDate: mockDate });
|
||||
|
||||
// Act
|
||||
const result = isSavedSessionStillActive();
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("isSavedSessionStillActive, should return false", () => {
|
||||
// Arrange
|
||||
const mockDate = new Date(new Date().toUTCString())
|
||||
mockDate.setDate(mockDate.getDate() + 65)
|
||||
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValue({ SavedQuoteTimeoutDate: mockDate });
|
||||
|
||||
// Act
|
||||
const result = isSavedSessionStillActive();
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue