From dd29180459c66fff17a8c8a6528c37d27ca075db Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Tue, 20 Feb 2024 09:04:27 -0500 Subject: [PATCH] CSR-1971 | Unit tests to confirm IDs are present on validate promo --- src/store/store.spec.js | 124 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index bfa09f9a1..535053e57 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -2929,6 +2929,130 @@ describe("Actions", () => { }); }); describe("validateOrderPromoAndSaveServerData", () => { + it("should add GUIDs if not there to provided lineItemsToUse.vaps before sending the http call", async () => { + // Arrange + const context = state; + const promoCode = "testPromo"; + const lineItemsToUse = { vaps: [{ partNumber: 1 }], promos: [2] }; + const addableVaps = [{ partNumber: "addableVap" }]; + + context["getters"] = { + order: { + serviceLocation: { + appointmentType: "test", + state: "test", + zipCodeCtu: "test", + }, + vehicle: { + carId: "test", + year: "test", + }, + referralCorrelationId: "test", + eon: "test", + damage: { + isRepair: true, + glassToReplace: null, + }, + payment: { + parentAccountNumber: "test", + }, + referralSequenceNumber: "test", + lineItems: { + serverData: "test", + }, + }, + }; + + globalMethods.callHttpClient = jest.fn().mockResolvedValue({ + data: {}, + }); + + crypto.randomUUID = jest.fn(() => "GUID"); + + // Act + actions.validateOrderPromoAndSaveServerData(context, { + payload: { + promoCode: promoCode, + lineItemsToUse: lineItemsToUse, + addableVaps: addableVaps, + }, + pageNameToLog: "test", + }); + + const firstCallArgs = globalMethods.callHttpClient.mock.calls[0]; + + // Assert + const vapsItem = firstCallArgs[0].payload.order.lineItemsOnOrder.filter( + (item) => item.partNumber == 1 + )[0]; + expect(vapsItem.id).toEqual("GUID"); + }); + it("should not duplicate ids during syncing if there are two identical vaps items", async () => { + // Arrange + const context = state; + const promoCode = "testPromo"; + // AddableVaps will sync its ids to vaps already on the order + const lineItemsToUse = { + vaps: [ + { partNumber: "SBB22", id: "GUID1" }, + { partNumber: "SBB22", id: "GUID2" }, + ], + promos: [2], + }; + const addableVaps = [{ partNumber: "SBB22" }, { partNumber: "SBB22" }]; + + context["getters"] = { + order: { + serviceLocation: { + appointmentType: "test", + state: "test", + zipCodeCtu: "test", + }, + vehicle: { + carId: "test", + year: "test", + }, + referralCorrelationId: "test", + eon: "test", + damage: { + isRepair: true, + glassToReplace: null, + }, + payment: { + parentAccountNumber: "test", + }, + referralSequenceNumber: "test", + lineItems: { + serverData: "test", + }, + }, + }; + + globalMethods.callHttpClient = jest.fn().mockResolvedValue({ + data: {}, + }); + + crypto.randomUUID = jest.fn(() => "GUID"); + + // Act + actions.validateOrderPromoAndSaveServerData(context, { + payload: { + promoCode: promoCode, + lineItemsToUse: lineItemsToUse, + addableVaps: addableVaps, + }, + pageNameToLog: "test", + }); + + const firstCallArgs = globalMethods.callHttpClient.mock.calls[0]; + + // Assert + const vapsItems = firstCallArgs[0].payload.addableVaps.filter( + (item) => item.partNumber == "SBB22" + ); + expect(vapsItems[1].id).toEqual("GUID1"); + expect(vapsItems[0].id).toEqual("GUID2"); + }); it("should add GUIDs if not there to provided addableVaps before sending the http call", async () => { // Arrange const context = state;