@vtex/vtexis-compatibility-layer
Version:
Compatibility layer between intelligent search and VTEX
37 lines (36 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const mergeProductWithItems_1 = require("../mergeProductWithItems");
const itemsWithSimulationResponse_1 = require("./mock/itemsWithSimulationResponse");
const itemsWithSimulationResponse3P_1 = require("./mock/itemsWithSimulationResponse3P");
const vtexProduct_1 = require("./mock/vtexProduct");
const vtexProduct3P_1 = require("./mock/vtexProduct3P");
describe('mergeProductWithItems', () => {
it('should be able to merge the results from the itemsWithSimulation query', () => {
const mergedProduct = mergeProductWithItems_1.mergeProductWithItems(vtexProduct_1.vtexProductMock, itemsWithSimulationResponse_1.itemsWithSimulationResponseMock, 'default');
const [mergedItem] = mergedProduct.items;
const [mergedSeller] = mergedItem.sellers;
const [sellerFromSimulation] = itemsWithSimulationResponse_1.itemsWithSimulationResponseMock[0].sellers;
expect(mergedSeller.commertialOffer).toMatchObject(sellerFromSimulation.commertialOffer);
});
it('should be able to ignore simulation quantity', () => {
const mergedProduct = mergeProductWithItems_1.mergeProductWithItems(vtexProduct_1.vtexProductMock, itemsWithSimulationResponse_1.itemsWithSimulationResponseMock, 'default', true);
// Set the mock to 0, as the simulation quantity is 10000.
vtexProduct_1.vtexProductMock.items[0].sellers[0].commertialOffer.AvailableQuantity = 0;
const [mergedItem] = mergedProduct.items;
const [mergedSeller] = mergedItem.sellers;
const [sellerFromSimulation] = itemsWithSimulationResponse_1.itemsWithSimulationResponseMock[0].sellers;
expect(mergedSeller.commertialOffer).not.toMatchObject(sellerFromSimulation.commertialOffer);
expect(mergedSeller.commertialOffer.AvailableQuantity).toEqual(vtexProduct_1.vtexProductMock.items[0].sellers[0].commertialOffer.AvailableQuantity);
});
it('should ignore simulation seller 1 if simulationBehavior only3P', () => {
const mergedProduct = mergeProductWithItems_1.mergeProductWithItems(vtexProduct3P_1.vtexProduct3PMock, itemsWithSimulationResponse3P_1.itemsWithSimulationResponse3PMock, 'only3P');
const seller1 = vtexProduct3P_1.vtexProduct3PMock.items[0].sellers[0];
const [mergedItem] = mergedProduct.items;
const mergedSellers = mergedItem.sellers;
const seller1Merged = mergedSellers.find((seller) => seller.sellerId === '1');
const seller3PMerged = mergedSellers.find((seller) => seller.sellerId === 'seller3P');
expect(seller1Merged === null || seller1Merged === void 0 ? void 0 : seller1Merged.commertialOffer.spotPrice).toBe(375.77);
expect(seller3PMerged === null || seller3PMerged === void 0 ? void 0 : seller3PMerged.commertialOffer.spotPrice).toBe(223375.77);
});
});