UNPKG

@vtex/vtexis-compatibility-layer

Version:

Compatibility layer between intelligent search and VTEX

126 lines (125 loc) 8.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const searchOffers_1 = require("./mock/searchOffers"); const convertSearchDocument_1 = require("../convertSearchDocument"); const searchDocument_1 = require("./mock/searchDocument"); const searchProduct_1 = require("./mock/searchProduct"); const documentTranslations_1 = require("./mock/documentTranslations"); let searchDocument; let searchOffers; let convertedVtexProduct; let convertedSearchItems; let translations; describe('convertSearchDocument', () => { beforeAll(async () => { searchDocument = { ...searchDocument_1.searchDocumentMock }; searchOffers = { ...searchOffers_1.searchOffersMock }; convertedVtexProduct = (await convertSearchDocument_1.convertSearchDocument([searchDocument], searchOffers, 'biggy'))[0]; convertedSearchItems = convertedVtexProduct.items; translations = documentTranslations_1.translationsMock; }); it('should convert brand information properly', () => { const { brand, brandId } = convertedVtexProduct; expect(brand).toBe(searchProduct_1.searchProductMock.brand); expect(brandId).toBe(searchProduct_1.searchProductMock.brandId); }); it('should convert category information properly', () => { const { categoryId, categories } = convertedVtexProduct; expect(categoryId).toBe(searchProduct_1.searchProductMock.categoryId); expect(categories).toMatchObject(searchProduct_1.searchProductMock.categories); // We don't support to category tree currently // expect(categoryTree).toMatchObject(searchProductMock.categoryTree) }); it('should convert productClusters and clusterHighLights properly', () => { const { clusterHighlights, productClusters } = convertedVtexProduct; expect(clusterHighlights).toMatchObject(searchProduct_1.searchProductMock.clusterHighlights); expect(productClusters).toMatchObject(searchProduct_1.searchProductMock.productClusters); }); it('should convert description properly', () => { const { description } = convertedVtexProduct; expect(description).toBe(searchProduct_1.searchProductMock.description); }); it('should convert skuSpecifications properly', () => { const { skuSpecifications } = convertedVtexProduct; expect(skuSpecifications).toMatchObject(searchProduct_1.searchProductMock.skuSpecifications); }); it('should convert link information properly', () => { const { linkText } = convertedVtexProduct; expect(linkText).toBe(searchProduct_1.searchProductMock.linkText); }); it('should convert productId properly', () => { const { productId } = convertedVtexProduct; expect(productId).toBe(searchProduct_1.searchProductMock.productId); }); it('should convert name information properly', () => { const { productName } = convertedVtexProduct; expect(productName).toBe(searchProduct_1.searchProductMock.productName); }); it('should convert productReference properly', () => { const { productReference } = convertedVtexProduct; expect(productReference).toBe(searchProduct_1.searchProductMock.productReference); }); it('should convert priceRange properly', () => { const { priceRange } = convertedVtexProduct; expect(priceRange).toMatchObject(searchProduct_1.searchProductMock.priceRange); }); it('should convert specifications info properly', () => { const { specificationGroups, properties, skuSpecifications } = convertedVtexProduct; expect(skuSpecifications).toMatchObject(searchProduct_1.searchProductMock.skuSpecifications); searchProduct_1.searchProductMock.specificationGroups.forEach((specification) => { expect(specificationGroups).toEqual(expect.arrayContaining([ expect.objectContaining({ name: specification.name, originalName: specification.originalName, specifications: expect.arrayContaining([...specification.specifications]), }), ])); }); searchProduct_1.searchProductMock.properties.forEach((property) => { expect(properties).toEqual(expect.arrayContaining([property])); }); }); it('should covert items in the correct order', () => { expect(convertedSearchItems).toHaveLength(searchProduct_1.searchProductMock.items.length); convertedSearchItems.forEach((item, idx) => { expect(item.itemId).toBe(searchProduct_1.searchProductMock.items[idx].itemId); }); }); it('should translate product details properly', async () => { var _a, _b, _c; const [translatedProduct] = await convertSearchDocument_1.convertSearchDocument([searchDocument], searchOffers, 'biggy', translations); const productName = (_a = translations.find((item) => item.field === 'ProductName')) === null || _a === void 0 ? void 0 : _a.translation; const description = (_b = translations.find((item) => item.field === 'Description')) === null || _b === void 0 ? void 0 : _b.translation; const brand = (_c = translations.find((item) => item.field === 'BrandName')) === null || _c === void 0 ? void 0 : _c.translation; expect(translatedProduct.productName).toEqual(productName); expect(translatedProduct.description).toEqual(description); expect(translatedProduct.brand).toEqual(brand); }); it('should translate product specifications properly', async () => { var _a, _b; const [translatedProduct] = await convertSearchDocument_1.convertSearchDocument([searchDocument], searchOffers, 'biggy', translations); const skuSpecificationName = (_a = translations.find((item) => item.field === 'SpecificationName' && item.context === '30')) === null || _a === void 0 ? void 0 : _a.translation; const skuSpecificationValue = (_b = translations.find((item) => item.field === 'SpecificationValue' && item.context === 'Roxo/Lilas')) === null || _b === void 0 ? void 0 : _b.translation; expect(translatedProduct.skuSpecifications[0].field.name).toEqual(skuSpecificationName); expect(translatedProduct.skuSpecifications[0].values[0].name).toEqual(skuSpecificationValue); expect(translatedProduct.specificationGroups[0].name).toEqual(searchProduct_1.searchProductMock.specificationGroups[0].name); expect(translatedProduct.specificationGroups[0].specifications[0].name).toEqual(skuSpecificationName); expect(translatedProduct.specificationGroups[0].specifications[0].values).toEqual([skuSpecificationValue]); }); it('should translate item details properly', async () => { var _a, _b, _c; const [translatedItem] = (await convertSearchDocument_1.convertSearchDocument([searchDocument], searchOffers, 'biggy', translations))[0].items; const itemName = (_a = translations.find((item) => item.field === 'SkuName' && item.context === '326782298')) === null || _a === void 0 ? void 0 : _a.translation; const nameComplete = `${(_b = translations.find((item) => item.field === 'ProductName')) === null || _b === void 0 ? void 0 : _b.translation} ${(_c = translations.find((item) => item.field === 'SkuName' && item.context === '326782298')) === null || _c === void 0 ? void 0 : _c.translation}`; expect(translatedItem.name).toEqual(itemName); expect(translatedItem.nameComplete).toEqual(nameComplete); }); it('should translate category names properly', async () => { var _a, _b; const [translatedProduct] = await convertSearchDocument_1.convertSearchDocument([searchDocument], searchOffers, 'biggy', translations); const category1 = (_a = translations.find((item) => item.field === 'CategoryName' && item.context === '14')) === null || _a === void 0 ? void 0 : _a.translation; const category2 = (_b = translations.find((item) => item.field === 'CategoryName' && item.context === '356')) === null || _b === void 0 ? void 0 : _b.translation; expect(translatedProduct.categories[1].split('/')[1]).toEqual(category1); expect(translatedProduct.categories[0].split('/')[2]).toEqual(category2); }); });