From 5c100e7e9a3527aeb9bd752f5af6da307f7bad11 Mon Sep 17 00:00:00 2001 From: trojanh Date: Wed, 11 Dec 2019 15:26:43 +0530 Subject: [PATCH 1/9] test: remove mockShop from catalogItem tests Signed-off-by: trojanh --- .../queries/catalogItemProduct/catalogItemProduct.test.js | 3 ++- .../api/queries/catalogItems/catalogItems.test.js | 6 +++++- tests/mocks/mockShop.js | 8 -------- 3 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 tests/mocks/mockShop.js diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index 4f16e9c8f19..1036e118b07 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,6 +1,5 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import { internalShopId, shopName } from "../../../../mocks/mockShop"; import { internalTagIds } from "../../../../mocks/mockTags"; import { mockCatalogItems, mockExternalCatalogProductNodes } from "../../../../mocks/mockCatalogItems"; import { opaqueCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; @@ -10,6 +9,8 @@ const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuer jest.setTimeout(300000); const mockCatalogItem = mockCatalogItems[0]; +const internalShopId = "123"; +const shopName = "Test Shop"; const expectedItemsResponse = { catalogItemProduct: mockExternalCatalogProductNodes[0] diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index daa315a7485..6e109283896 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,7 +1,6 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; // temp mocks -import { internalShopId, opaqueShopId, shopName } from "../../../../mocks/mockShop"; import { internalTagIds, opaqueTagIds } from "../../../../mocks/mockTags"; import { internalCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; import { @@ -19,6 +18,11 @@ jest.setTimeout(300000); let testApp; let query; let paginatedQuery; + +const internalShopId = "123"; +const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; +const shopName = "Test Shop"; + beforeAll(async () => { testApp = new TestApp(); await testApp.start(); diff --git a/tests/mocks/mockShop.js b/tests/mocks/mockShop.js deleted file mode 100644 index f22324288fb..00000000000 --- a/tests/mocks/mockShop.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - * @todo TEMP Mocks these will be removed in favor of a fixture/factory solution - */ - -export const internalShopId = "123"; -export const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; // reaction/shop:123 -export const shopName = "Test Shop"; From db482d3a006dbb13ff82d2f11eb9af348306ffcd Mon Sep 17 00:00:00 2001 From: trojanh Date: Wed, 11 Dec 2019 15:30:32 +0530 Subject: [PATCH 2/9] tests: remove mockTags for tests Signed-off-by: trojanh --- .../queries/catalogItemProduct/catalogItemProduct.test.js | 2 +- .../api/queries/catalogItems/catalogItems.test.js | 4 +++- tests/mocks/mockTags.js | 7 ------- 3 files changed, 4 insertions(+), 9 deletions(-) delete mode 100644 tests/mocks/mockTags.js diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index 1036e118b07..d9f75587935 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,6 +1,5 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import { internalTagIds } from "../../../../mocks/mockTags"; import { mockCatalogItems, mockExternalCatalogProductNodes } from "../../../../mocks/mockCatalogItems"; import { opaqueCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; @@ -11,6 +10,7 @@ jest.setTimeout(300000); const mockCatalogItem = mockCatalogItems[0]; const internalShopId = "123"; const shopName = "Test Shop"; +const internalTagIds = ["923", "924"]; const expectedItemsResponse = { catalogItemProduct: mockExternalCatalogProductNodes[0] diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index 6e109283896..1290a85f4b6 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,7 +1,6 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; // temp mocks -import { internalTagIds, opaqueTagIds } from "../../../../mocks/mockTags"; import { internalCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; import { mockCatalogItems, @@ -22,6 +21,9 @@ let paginatedQuery; const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; const shopName = "Test Shop"; +const internalTagIds = ["923", "924"]; +const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag + beforeAll(async () => { testApp = new TestApp(); diff --git a/tests/mocks/mockTags.js b/tests/mocks/mockTags.js deleted file mode 100644 index 63632bd1b5e..00000000000 --- a/tests/mocks/mockTags.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * - * @todo TEMP mocks these will be removed in favor of a fixture/factory solution - */ - -export const internalTagIds = ["923", "924"]; -export const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag From 5d8a7b10d6e6f47c83378ac560c6871256b7cc9e Mon Sep 17 00:00:00 2001 From: trojanh Date: Wed, 11 Dec 2019 17:08:52 +0530 Subject: [PATCH 3/9] tests: use factory mocks in catalogItemProduct query Signed-off-by: trojanh --- .../catalogItemProduct.test.js | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index d9f75587935..c8c6529d431 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,20 +1,32 @@ +import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import { mockCatalogItems, mockExternalCatalogProductNodes } from "../../../../mocks/mockCatalogItems"; -import { opaqueCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; +import Factory from "/tests/util/factory.js"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); +const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); -jest.setTimeout(300000); - -const mockCatalogItem = mockCatalogItems[0]; const internalShopId = "123"; +const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; const shopName = "Test Shop"; const internalTagIds = ["923", "924"]; -const expectedItemsResponse = { - catalogItemProduct: mockExternalCatalogProductNodes[0] -}; +const mockCatalogItem = Factory.Catalog.makeOne({ + _id: "999", + product: Factory.CatalogProduct.makeOne({ + _id: "100", + slug: "fake-product", + isDeleted: false, + isVisible: true, + productId: "100", + tagIds: internalTagIds, + shopId: internalShopId + }), + shopId: internalShopId +}); + +jest.setTimeout(300000); let testApp; let query; @@ -36,24 +48,33 @@ afterAll(async () => { test("get a catalog product by slug", async () => { let result; + + console.log({mockCatalogItem}) + try { result = await query({ slugOrId: mockCatalogItem.product.slug }); } catch (error) { expect(error).toBeUndefined(); return; } - - expect(result).toEqual(expectedItemsResponse); + console.log({result}) + expect(result).toEqual({ + _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), + shopId: opaqueShopId + }); }); test("get a catalog product by ID", async () => { let result; try { - result = await query({ slugOrId: opaqueCatalogItemIds[0] }); + result = await query({ slugOrId: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id) }); } catch (error) { expect(error).toBeUndefined(); return; } - expect(result).toEqual(expectedItemsResponse); + expect(result).toEqual({ + _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), + shopId: opaqueShopId + }); }); From eac275a62067eeaec456d0bf92b378908f867e5e Mon Sep 17 00:00:00 2001 From: trojanh Date: Wed, 11 Dec 2019 17:07:56 +0530 Subject: [PATCH 4/9] test: move mock catalog mock file to catalog queries Signed-off-by: trojanh --- .../catalogItemProduct.test.js | 488 ++++++- .../queries/catalogItems/catalogItems.test.js | 1213 ++++++++++++++++- tests/mocks/mockCatalogProducts.js | 715 ---------- 3 files changed, 1656 insertions(+), 760 deletions(-) delete mode 100644 tests/mocks/mockCatalogProducts.js diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index c8c6529d431..9cb0d66a533 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,32 +1,468 @@ -import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import Factory from "/tests/util/factory.js"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); -const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); + +jest.setTimeout(300000); const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const shopName = "Test Shop"; const internalTagIds = ["923", "924"]; +const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag +const shopName = "Test Shop"; -const mockCatalogItem = Factory.Catalog.makeOne({ +const mockCatalogItem = { _id: "999", - product: Factory.CatalogProduct.makeOne({ - _id: "100", - slug: "fake-product", - isDeleted: false, + product: { + _id: "999", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, isVisible: true, - productId: "100", - tagIds: internalTagIds, - shopId: internalShopId - }), - shopId: internalShopId -}); + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + productId: "999", + media: [ + { + priority: 1, + productId: "999", + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "999", + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { + service: "twitter", + message: "twitterMessage" + }, + { + service: "facebook", + message: "facebookMessage" + }, + { + service: "googleplus", + message: "googlePlusMessage" + }, + { + service: "pinterest", + message: "pinterestMessage" + } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "875", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "874", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "874", + weight: 2, + width: 2 + }, + { + _id: "873", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "873", + weight: 2, + width: 2 + } + ], + optionTitle: "Untitled Option", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "875", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" +}; -jest.setTimeout(300000); +const expectedItemsResponse = { + catalogItemProduct: { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + } +}; let testApp; let query; @@ -35,7 +471,9 @@ beforeAll(async () => { await testApp.start(); query = testApp.query(CatalogItemProductFullQuery); await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); - await Promise.all(internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` }))); + await Promise.all( + internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` })) + ); await testApp.collections.Catalog.insertOne(mockCatalogItem); }); @@ -48,20 +486,13 @@ afterAll(async () => { test("get a catalog product by slug", async () => { let result; - - console.log({mockCatalogItem}) - try { result = await query({ slugOrId: mockCatalogItem.product.slug }); } catch (error) { expect(error).toBeUndefined(); return; } - console.log({result}) - expect(result).toEqual({ - _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), - shopId: opaqueShopId - }); + expect(result).toEqual(expectedItemsResponse); }); test("get a catalog product by ID", async () => { @@ -73,8 +504,5 @@ test("get a catalog product by ID", async () => { return; } - expect(result).toEqual({ - _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), - shopId: opaqueShopId - }); + expect(result).toEqual(expectedItemsResponse); }); diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index 1290a85f4b6..f4e53d0e5f9 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,29 +1,1212 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -// temp mocks -import { internalCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; -import { - mockCatalogItems, - mockUnsortedCatalogItemsResponse, - mockSortedByPriceHigh2LowCatalogItemsResponse, - mockSortedByPriceLow2HighCatalogItemsResponse -} from "../../../../mocks/mockCatalogItems"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); -jest.setTimeout(300000); - -let testApp; -let query; -let paginatedQuery; - const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const shopName = "Test Shop"; const internalTagIds = ["923", "924"]; const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag +const shopName = "Test Shop"; +const internalCatalogItemIds = ["999", "222"]; + +const mockCatalogItems = [ + { + _id: "999", + product: { + _id: "999", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: { + USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } + }, + productId: "999", + media: [ + { + priority: 1, + productId: "999", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + } + ], + primaryImage: { + priority: 1, + productId: "999", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "875", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "874", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { compareAtPrice: null, displayPrice: "5.99", maxPrice: 5.99, minPrice: 5.99, price: 5.99 } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "874", + weight: 2, + width: 2 + }, + { + _id: "873", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { compareAtPrice: null, displayPrice: "2.99", maxPrice: 2.99, minPrice: 2.99, price: 2.99 } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "873", + weight: 2, + width: 2 + } + ], + optionTitle: "Untitled Option", + originCountry: "US", + pricing: { + USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "875", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" + }, + { + _id: "222", + product: { + _id: "222", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: { + USD: { compareAtPrice: 35, displayPrice: "16.99 - 25.99", maxPrice: 25.99, minPrice: 16.99, price: null } + }, + productId: "222", + media: [ + { + priority: 1, + productId: "222", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + } + ], + primaryImage: { + priority: 1, + productId: "222", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Another Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" + } +]; + +const mockUnsortedCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +const mockSortedByPriceHigh2LowCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +const mockSortedByPriceLow2HighCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +jest.setTimeout(300000); + +let testApp; +let query; +let paginatedQuery; beforeAll(async () => { testApp = new TestApp(); diff --git a/tests/mocks/mockCatalogProducts.js b/tests/mocks/mockCatalogProducts.js deleted file mode 100644 index 60e0aac2869..00000000000 --- a/tests/mocks/mockCatalogProducts.js +++ /dev/null @@ -1,715 +0,0 @@ -import { internalShopId, opaqueShopId } from "./mockShop"; -import { internalTagIds, opaqueTagIds } from "./mockTags"; - -/** - * - * @todo TEMP mocks these will be removed in favor of a fixture/factory solution - */ - -export const internalProductIds = ["999", "222"]; -export const opaqueProductIds = ["cmVhY3Rpb24vcHJvZHVjdDo5OTk=", "cmVhY3Rpb24vcHJvZHVjdDoyMjI="]; // reaction/product - -export const internalVariantIds = ["875", "874", "873"]; -export const opaqueVariantIds = [ - "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - "cmVhY3Rpb24vcHJvZHVjdDo4NzM=" -]; // reaction/product - -export const internalCatalogProductIds = ["999", "222"]; -export const opaqueCatalogProductIds = ["cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy"]; // reaction/catalogProduct - -export const opaqueCatalogVariantIds = [ - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==" -]; // reaction/catalogProductVariant - -export const internalCatalogItemIds = ["999", "222"]; -export const opaqueCatalogItemIds = ["cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy"]; // reaction/catalogItem - -export const createdAt = new Date("2018-04-16T15:34:28.043Z"); -export const updatedAt = new Date("2018-04-17T15:34:28.043Z"); - -/** - * mock internal catalog product variant options - */ -export const mockInternalCatalogOptions = [ - { - _id: internalVariantIds[1], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: internalVariantIds[1], - weight: 2, - width: 2 - }, - { - _id: internalVariantIds[2], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: internalVariantIds[2], - weight: 2, - width: 2 - } -]; - -/** - * mock external catalog product variant options - */ -export const mockExternalCatalogOptions = [ - { - _id: opaqueCatalogVariantIds[1], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: opaqueVariantIds[1], - weight: 2, - width: 2 - }, - { - _id: opaqueCatalogVariantIds[2], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: opaqueVariantIds[2], - weight: 2, - width: 2 - } -]; - -/** - * mock internal catalog product variants - */ -export const mockInternalCatalogVariants = [ - { - _id: internalVariantIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - height: 0, - index: 0, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: mockInternalCatalogOptions, - optionTitle: "Untitled Option", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: updatedAt.toISOString(), - variantId: internalVariantIds[0], - weight: 0, - width: 0 - } -]; - -/** - * mock external catalog product variants - */ -export const mockExternalCatalogVariants = [ - { - _id: opaqueCatalogVariantIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: mockExternalCatalogOptions, - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: updatedAt.toISOString(), - variantId: opaqueVariantIds[0], - weight: 0, - width: 0 - } -]; - -/** - * mock internal catalog products - */ -export const mockInternalCatalogProducts = [ - { - _id: internalCatalogProductIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - productId: internalProductIds[0], - media: [ - { - priority: 1, - productId: internalProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: internalProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shopId: internalShopId, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: internalTagIds, - title: "Fake Product Title", - type: "product-simple", - updatedAt: updatedAt.toISOString(), - variants: mockInternalCatalogVariants, - vendor: "vendor", - weight: 15.6, - width: 8.4 - }, - { - _id: internalCatalogProductIds[1], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: { - USD: { - compareAtPrice: 35, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - }, - productId: internalProductIds[1], - media: [ - { - priority: 1, - productId: internalProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: internalProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shopId: internalShopId, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: internalTagIds, - title: "Another Fake Product Title", - type: "product-simple", - updatedAt: updatedAt.toISOString(), - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } -]; - -/** - * mock external catalog products - */ -export const mockExternalCatalogProducts = [ - { - _id: opaqueCatalogItemIds[0], - createdAt: createdAt.toISOString(), - updatedAt: updatedAt.toISOString(), - shop: { - _id: opaqueShopId - }, - product: { - _id: opaqueCatalogProductIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - productId: opaqueProductIds[0], - media: [ - { - priority: 1, - productId: opaqueProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: opaqueProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shop: { - _id: opaqueShopId - }, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: opaqueTagIds, - tags: { - nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] - }, - title: "Fake Product Title", - updatedAt: updatedAt.toISOString(), - variants: mockExternalCatalogVariants, - vendor: "vendor", - weight: 15.6, - width: 8.4 - } - }, - { - _id: opaqueCatalogItemIds[1], - createdAt: createdAt.toISOString(), - updatedAt: updatedAt.toISOString(), - shop: { - _id: opaqueShopId - }, - product: { - _id: opaqueCatalogProductIds[1], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 35 }, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - ], - productId: opaqueProductIds[1], - media: [ - { - priority: 1, - productId: opaqueProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: opaqueProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shop: { - _id: opaqueShopId - }, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: opaqueTagIds, - tags: { - nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] - }, - title: "Another Fake Product Title", - updatedAt: updatedAt.toISOString(), - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } - } -]; From 18926f39ced2ec29524acb03eb943f490ab8d450 Mon Sep 17 00:00:00 2001 From: trojanh Date: Wed, 11 Dec 2019 17:07:56 +0530 Subject: [PATCH 5/9] test: move mock catalog mock file to catalog queries Signed-off-by: trojanh --- .../catalogItemProduct.test.js | 488 ++++++- .../queries/catalogItems/catalogItems.test.js | 1213 ++++++++++++++++- tests/mocks/mockCatalogProducts.js | 715 ---------- 3 files changed, 1656 insertions(+), 760 deletions(-) delete mode 100644 tests/mocks/mockCatalogProducts.js diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index c8c6529d431..9cb0d66a533 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,32 +1,468 @@ -import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import Factory from "/tests/util/factory.js"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); -const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); + +jest.setTimeout(300000); const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const shopName = "Test Shop"; const internalTagIds = ["923", "924"]; +const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag +const shopName = "Test Shop"; -const mockCatalogItem = Factory.Catalog.makeOne({ +const mockCatalogItem = { _id: "999", - product: Factory.CatalogProduct.makeOne({ - _id: "100", - slug: "fake-product", - isDeleted: false, + product: { + _id: "999", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, isVisible: true, - productId: "100", - tagIds: internalTagIds, - shopId: internalShopId - }), - shopId: internalShopId -}); + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + productId: "999", + media: [ + { + priority: 1, + productId: "999", + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "999", + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { + service: "twitter", + message: "twitterMessage" + }, + { + service: "facebook", + message: "facebookMessage" + }, + { + service: "googleplus", + message: "googlePlusMessage" + }, + { + service: "pinterest", + message: "pinterestMessage" + } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "875", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "874", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "874", + weight: 2, + width: 2 + }, + { + _id: "873", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "873", + weight: 2, + width: 2 + } + ], + optionTitle: "Untitled Option", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "875", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" +}; -jest.setTimeout(300000); +const expectedItemsResponse = { + catalogItemProduct: { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + } +}; let testApp; let query; @@ -35,7 +471,9 @@ beforeAll(async () => { await testApp.start(); query = testApp.query(CatalogItemProductFullQuery); await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); - await Promise.all(internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` }))); + await Promise.all( + internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` })) + ); await testApp.collections.Catalog.insertOne(mockCatalogItem); }); @@ -48,20 +486,13 @@ afterAll(async () => { test("get a catalog product by slug", async () => { let result; - - console.log({mockCatalogItem}) - try { result = await query({ slugOrId: mockCatalogItem.product.slug }); } catch (error) { expect(error).toBeUndefined(); return; } - console.log({result}) - expect(result).toEqual({ - _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), - shopId: opaqueShopId - }); + expect(result).toEqual(expectedItemsResponse); }); test("get a catalog product by ID", async () => { @@ -73,8 +504,5 @@ test("get a catalog product by ID", async () => { return; } - expect(result).toEqual({ - _id: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id), - shopId: opaqueShopId - }); + expect(result).toEqual(expectedItemsResponse); }); diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index 1290a85f4b6..f4e53d0e5f9 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,29 +1,1212 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -// temp mocks -import { internalCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; -import { - mockCatalogItems, - mockUnsortedCatalogItemsResponse, - mockSortedByPriceHigh2LowCatalogItemsResponse, - mockSortedByPriceLow2HighCatalogItemsResponse -} from "../../../../mocks/mockCatalogItems"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); -jest.setTimeout(300000); - -let testApp; -let query; -let paginatedQuery; - const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const shopName = "Test Shop"; const internalTagIds = ["923", "924"]; const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag +const shopName = "Test Shop"; +const internalCatalogItemIds = ["999", "222"]; + +const mockCatalogItems = [ + { + _id: "999", + product: { + _id: "999", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: { + USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } + }, + productId: "999", + media: [ + { + priority: 1, + productId: "999", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + } + ], + primaryImage: { + priority: 1, + productId: "999", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "875", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "874", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { compareAtPrice: null, displayPrice: "5.99", maxPrice: 5.99, minPrice: 5.99, price: 5.99 } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "874", + weight: 2, + width: 2 + }, + { + _id: "873", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { compareAtPrice: null, displayPrice: "2.99", maxPrice: 2.99, minPrice: 2.99, price: 2.99 } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "873", + weight: 2, + width: 2 + } + ], + optionTitle: "Untitled Option", + originCountry: "US", + pricing: { + USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } + }, + shopId: "123", + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "875", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" + }, + { + _id: "222", + product: { + _id: "222", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: { + USD: { compareAtPrice: 35, displayPrice: "16.99 - 25.99", maxPrice: 25.99, minPrice: 16.99, price: null } + }, + productId: "222", + media: [ + { + priority: 1, + productId: "222", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + } + ], + primaryImage: { + priority: 1, + productId: "222", + variantId: null, + URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } + }, + productType: "productType", + shopId: "123", + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["923", "924"], + title: "Another Fake Product Title", + type: "product-simple", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + }, + shopId: "123", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z" + } +]; + +const mockUnsortedCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +const mockSortedByPriceHigh2LowCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +const mockSortedByPriceLow2HighCatalogItemsResponse = { + catalogItems: { + nodes: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: [ + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + weight: 2, + width: 2 + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", + weight: 2, + width: 2 + } + ], + originCountry: "US", + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: "2018-04-17T15:34:28.043Z", + variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + weight: 0, + width: 0 + } + ], + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", + createdAt: "2018-04-16T15:34:28.043Z", + updatedAt: "2018-04-17T15:34:28.043Z", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + product: { + _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", + barcode: "barcode", + createdAt: "2018-04-16T15:34:28.043Z", + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + pricing: [ + { + currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + media: [ + { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ], + primaryImage: { + priority: 1, + productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + }, + productType: "productType", + shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], + tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, + title: "Another Fake Product Title", + updatedAt: "2018-04-17T15:34:28.043Z", + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + } + ] + } +}; + +jest.setTimeout(300000); + +let testApp; +let query; +let paginatedQuery; beforeAll(async () => { testApp = new TestApp(); diff --git a/tests/mocks/mockCatalogProducts.js b/tests/mocks/mockCatalogProducts.js deleted file mode 100644 index 60e0aac2869..00000000000 --- a/tests/mocks/mockCatalogProducts.js +++ /dev/null @@ -1,715 +0,0 @@ -import { internalShopId, opaqueShopId } from "./mockShop"; -import { internalTagIds, opaqueTagIds } from "./mockTags"; - -/** - * - * @todo TEMP mocks these will be removed in favor of a fixture/factory solution - */ - -export const internalProductIds = ["999", "222"]; -export const opaqueProductIds = ["cmVhY3Rpb24vcHJvZHVjdDo5OTk=", "cmVhY3Rpb24vcHJvZHVjdDoyMjI="]; // reaction/product - -export const internalVariantIds = ["875", "874", "873"]; -export const opaqueVariantIds = [ - "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - "cmVhY3Rpb24vcHJvZHVjdDo4NzM=" -]; // reaction/product - -export const internalCatalogProductIds = ["999", "222"]; -export const opaqueCatalogProductIds = ["cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy"]; // reaction/catalogProduct - -export const opaqueCatalogVariantIds = [ - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==" -]; // reaction/catalogProductVariant - -export const internalCatalogItemIds = ["999", "222"]; -export const opaqueCatalogItemIds = ["cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy"]; // reaction/catalogItem - -export const createdAt = new Date("2018-04-16T15:34:28.043Z"); -export const updatedAt = new Date("2018-04-17T15:34:28.043Z"); - -/** - * mock internal catalog product variant options - */ -export const mockInternalCatalogOptions = [ - { - _id: internalVariantIds[1], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: internalVariantIds[1], - weight: 2, - width: 2 - }, - { - _id: internalVariantIds[2], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: internalVariantIds[2], - weight: 2, - width: 2 - } -]; - -/** - * mock external catalog product variant options - */ -export const mockExternalCatalogOptions = [ - { - _id: opaqueCatalogVariantIds[1], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: opaqueVariantIds[1], - weight: 2, - width: 2 - }, - { - _id: opaqueCatalogVariantIds[2], - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: opaqueVariantIds[2], - weight: 2, - width: 2 - } -]; - -/** - * mock internal catalog product variants - */ -export const mockInternalCatalogVariants = [ - { - _id: internalVariantIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - height: 0, - index: 0, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: mockInternalCatalogOptions, - optionTitle: "Untitled Option", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - shopId: internalShopId, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: updatedAt.toISOString(), - variantId: internalVariantIds[0], - weight: 0, - width: 0 - } -]; - -/** - * mock external catalog product variants - */ -export const mockExternalCatalogVariants = [ - { - _id: opaqueCatalogVariantIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: mockExternalCatalogOptions, - originCountry: "US", - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { - _id: opaqueShopId - }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: updatedAt.toISOString(), - variantId: opaqueVariantIds[0], - weight: 0, - width: 0 - } -]; - -/** - * mock internal catalog products - */ -export const mockInternalCatalogProducts = [ - { - _id: internalCatalogProductIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - productId: internalProductIds[0], - media: [ - { - priority: 1, - productId: internalProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: internalProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shopId: internalShopId, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: internalTagIds, - title: "Fake Product Title", - type: "product-simple", - updatedAt: updatedAt.toISOString(), - variants: mockInternalCatalogVariants, - vendor: "vendor", - weight: 15.6, - width: 8.4 - }, - { - _id: internalCatalogProductIds[1], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: { - USD: { - compareAtPrice: 35, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - }, - productId: internalProductIds[1], - media: [ - { - priority: 1, - productId: internalProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: internalProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shopId: internalShopId, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: internalTagIds, - title: "Another Fake Product Title", - type: "product-simple", - updatedAt: updatedAt.toISOString(), - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } -]; - -/** - * mock external catalog products - */ -export const mockExternalCatalogProducts = [ - { - _id: opaqueCatalogItemIds[0], - createdAt: createdAt.toISOString(), - updatedAt: updatedAt.toISOString(), - shop: { - _id: opaqueShopId - }, - product: { - _id: opaqueCatalogProductIds[0], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - productId: opaqueProductIds[0], - media: [ - { - priority: 1, - productId: opaqueProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: opaqueProductIds[0], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shop: { - _id: opaqueShopId - }, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: opaqueTagIds, - tags: { - nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] - }, - title: "Fake Product Title", - updatedAt: updatedAt.toISOString(), - variants: mockExternalCatalogVariants, - vendor: "vendor", - weight: 15.6, - width: 8.4 - } - }, - { - _id: opaqueCatalogItemIds[1], - createdAt: createdAt.toISOString(), - updatedAt: updatedAt.toISOString(), - shop: { - _id: opaqueShopId - }, - product: { - _id: opaqueCatalogProductIds[1], - barcode: "barcode", - createdAt: createdAt.toISOString(), - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: [ - { - currency: { - _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", - code: "USD" - }, - compareAtPrice: { amount: 35 }, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - ], - productId: opaqueProductIds[1], - media: [ - { - priority: 1, - productId: opaqueProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: opaqueProductIds[1], - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shop: { - _id: opaqueShopId - }, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: opaqueTagIds, - tags: { - nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] - }, - title: "Another Fake Product Title", - updatedAt: updatedAt.toISOString(), - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } - } -]; From d63a5d01ec6a88e60561eea0d3ef291041345a39 Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 16:51:44 +0530 Subject: [PATCH 6/9] test: Add integration tests for catalogItems query Signed-off-by: trojanh --- .../queries/catalogItems/catalogItems.test.js | 1294 ++--------------- tests/mocks/mockCatalogItems.js | 90 -- 2 files changed, 101 insertions(+), 1283 deletions(-) delete mode 100644 tests/mocks/mockCatalogItems.js diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index f4e53d0e5f9..07463c12bce 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,1206 +1,93 @@ +import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; +import Factory from "/tests/util/factory.js"; import TestApp from "/tests/util/TestApp.js"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); +const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); + const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const internalTagIds = ["923", "924"]; -const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag const shopName = "Test Shop"; -const internalCatalogItemIds = ["999", "222"]; -const mockCatalogItems = [ - { - _id: "999", - product: { - _id: "999", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, +const mockTag = Factory.Tag.makeOne({ + featuredProductIds: [ + "501", + "503", + "505", + "506", + "504", + "500", + "501", + "502", + "507", + "508", + "509", + "512", + "511", + "513", + "510", + "506", + "514" + ], + shopId: internalShopId, + slug: "2" +}); + +const mockCatalogItems = Factory.Catalog.makeMany(15, { + _id: (iterator) => (iterator + 500).toString(), + product: (iterator) => + Factory.CatalogProduct.makeOne({ + _id: (iterator + 500).toString(), + productId: (iterator + 500).toString(), + isDeleted: false, isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, + tagIds: [mockTag._id], + shopId: internalShopId, pricing: { - USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } - }, - productId: "999", - media: [ - { - priority: 1, - productId: "999", - variantId: null, - URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } - } - ], - primaryImage: { - priority: 1, - productId: "999", - variantId: null, - URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } - }, - productType: "productType", - shopId: "123", - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["923", "924"], - title: "Fake Product Title", - type: "product-simple", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "875", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "874", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { compareAtPrice: null, displayPrice: "5.99", maxPrice: 5.99, minPrice: 5.99, price: 5.99 } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "874", - weight: 2, - width: 2 - }, - { - _id: "873", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { compareAtPrice: null, displayPrice: "2.99", maxPrice: 2.99, minPrice: 2.99, price: 2.99 } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "873", - weight: 2, - width: 2 - } - ], - optionTitle: "Untitled Option", - originCountry: "US", - pricing: { - USD: { compareAtPrice: 10, displayPrice: "2.99 - 5.99", maxPrice: 5.99, minPrice: 2.99, price: null } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "875", - weight: 0, - width: 0 + USD: { + compareAtPrice: 6.0 + (iterator + 10), + displayPrice: `${0.99 + iterator} - ${1.99 + iterator}`, + maxPrice: 1.99 + iterator, + minPrice: 0.99 + iterator, + price: null } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 - }, - shopId: "123", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z" - }, - { - _id: "222", - product: { - _id: "222", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: { - USD: { compareAtPrice: 35, displayPrice: "16.99 - 25.99", maxPrice: 25.99, minPrice: 16.99, price: null } }, - productId: "222", media: [ { priority: 1, - productId: "222", + productId: (iterator + 500).toString(), variantId: null, URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } } ], - primaryImage: { - priority: 1, - productId: "222", - variantId: null, - URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } - }, - productType: "productType", - shopId: "123", - sku: "ABC123", - slug: "another-fake-product", socialMetadata: [ { service: "twitter", message: "twitterMessage" }, { service: "facebook", message: "facebookMessage" }, { service: "googleplus", message: "googlePlusMessage" }, { service: "pinterest", message: "pinterestMessage" } ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["923", "924"], - title: "Another Fake Product Title", - type: "product-simple", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - }, - shopId: "123", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z" - } -]; - -const mockUnsortedCatalogItemsResponse = { - catalogItems: { - nodes: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - weight: 2, - width: 2 - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", - weight: 2, - width: 2 - } - ], - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - weight: 0, - width: 0 - } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 - } - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 35 }, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Another Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } - } - ] - } -}; - -const mockSortedByPriceHigh2LowCatalogItemsResponse = { - catalogItems: { - nodes: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 35 }, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Another Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - weight: 2, - width: 2 - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", - weight: 2, - width: 2 - } - ], - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - weight: 0, - width: 0 - } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 + variants: Factory.CatalogProductVariant.makeMany(1, { + options: null, + shopId: internalShopId, + pricing: { + USD: { + compareAtPrice: 6.0 + (iterator + 10), + displayPrice: `${0.99 + iterator} - ${1.99 + iterator}`, + maxPrice: 1.99 + iterator, + minPrice: 0.99 + iterator, + price: null + } } - } - ] - } -}; - -const mockSortedByPriceLow2HighCatalogItemsResponse = { - catalogItems: { - nodes: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - weight: 2, - width: 2 - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", - weight: 2, - width: 2 - } - ], - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - weight: 0, - width: 0 - } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 - } - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 35 }, - displayPrice: "16.99 - 25.99", - maxPrice: 25.99, - minPrice: 16.99, - price: null - } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - media: [ - { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDoyMjI=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "another-fake-product", - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Another Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [], - vendor: "another vendor", - weight: 15.6, - width: 8.4 - } - } - ] - } -}; + }) + }), + shopId: internalShopId +}); +const opaqueCatalogItemIds = mockCatalogItems.map((item) => encodeOpaqueId("reaction/catalogProduct", item._id)); jest.setTimeout(300000); @@ -1214,15 +101,14 @@ beforeAll(async () => { query = testApp.query(CatalogProductItemsFullQuery); paginatedQuery = testApp.query(CatalogProductItemsFullQueryPaginated); await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); - await Promise.all(internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` }))); - await Promise.all(mockCatalogItems.map((mockCatalogItem) => testApp.collections.Catalog.insertOne(mockCatalogItem))); + await testApp.collections.Tags.insertOne(mockTag); + await Promise.all(mockCatalogItems.map((mockItem) => testApp.collections.Catalog.insertOne(mockItem))); }); afterAll(async () => { await testApp.collections.Shops.deleteOne({ _id: internalShopId }); - await testApp.collections.Tags.deleteMany({ _id: { $in: internalTagIds } }); - await testApp.collections.Catalog.deleteOne({ _id: internalCatalogItemIds[0] }); - await testApp.collections.Catalog.deleteOne({ _id: internalCatalogItemIds[1] }); + await testApp.collections.Tags.deleteOne({ _id: mockTag._id }); + await Promise.all(mockCatalogItems.map((mockItem) => testApp.collections.Catalog.deleteOne({ _id: mockItem._id }))); await testApp.stop(); }); @@ -1235,7 +121,11 @@ test("get all items for shop", async () => { return; } - expect(result).toEqual(mockUnsortedCatalogItemsResponse); + expect(result.catalogItems.nodes.length).toEqual(15); + + result.catalogItems.nodes.forEach(({ product }) => { + expect(opaqueCatalogItemIds).toContain(product._id); + }); }); // expect CatalogItems sorted by minPrice form high to low @@ -1248,10 +138,25 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when return; } - expect(result).toEqual(mockSortedByPriceHigh2LowCatalogItemsResponse); + const firstCatalogItem = mockCatalogItems[0]; + const lastCatalogItem = mockCatalogItems[mockCatalogItems.length - 1]; + + const firstResultItem = result.catalogItems.nodes[0]; + const lastResultItem = result.catalogItems.nodes[result.catalogItems.nodes.length - 1]; + + const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); + + expect(result.catalogItems.nodes.length).toEqual(15); + + expect(firstResultItem.product.pricing[0].minPrice).toEqual(lastCatalogItem.product.pricing.USD.minPrice); + expect(firstResultItem.product._id).toEqual(opaqueCatalogItemIds[opaqueCatalogItemIds.length - 1]); + + expect(lastResultItem.product.pricing[0].minPrice).toEqual(firstCatalogItem.product.pricing.USD.minPrice); + expect(lastResultItem.product._id).toEqual(opaqueCatalogItemIds[0]); + expect(resultProductIds).toEqual(opaqueCatalogItemIds.reverse()); }); -test("expect CatalogItemProducts with offset 0 to return first item", async () => { +test("expect CatalogItemProducts with offset 0 to return all items", async () => { let result; try { result = await paginatedQuery({ @@ -1262,10 +167,10 @@ test("expect CatalogItemProducts with offset 0 to return first item", async () = expect(error).toBeUndefined(); return; } - - expect(result.catalogItems.totalCount).toBe(2); - expect(result.catalogItems.nodes.length).toBe(2); - expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[0].product._id); + expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); + expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(false); + expect(result.catalogItems.totalCount).toBe(15); + expect(result.catalogItems.nodes.length).toBe(15); }); // expect CatalogItems with offset to skip items @@ -1283,8 +188,7 @@ test("expect CatalogitemProducts with offset to skip items", async () => { expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(true); - expect(result.catalogItems.nodes.length).toBe(1); - expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[1].product._id); + expect(result.catalogItems.nodes.length).toBe(14); }); // expect CatalogItems with feature sortBy and offset to skip items correctly @@ -1295,17 +199,19 @@ test("expect CatalogitemProducts with offset and featured sort to skip items", a shopIds: [opaqueShopId], offset: 1, sortBy: "featured", - tagIds: [opaqueTagIds[0]] + tagIds: [encodeOpaqueId("reaction/tag", mockTag._id)] }); } catch (error) { expect(error).toBeUndefined(); return; } - + const ids = result.catalogItems.nodes.map((n) => decodeCatalogProductOpaqueId(n.product._id)); + // console.log(result.catalogItems.totalCount); + // console.log({ ids }); expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); + // @TODO: debug this expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(true); expect(result.catalogItems.nodes.length).toBe(1); - expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[0].product._id); }); // expect CatalogItems sorted by minPrice form high to low when sortOrder is desc @@ -1322,8 +228,9 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when expect(error).toBeUndefined(); return; } + const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); - expect(result).toEqual(mockSortedByPriceHigh2LowCatalogItemsResponse); + expect(resultProductIds).toEqual(opaqueCatalogItemIds); }); // expect CatalogItems sorted by minPrice form low to high when sortOrder is asc @@ -1340,8 +247,9 @@ test("expect CatalogItemProducts sorted by minPrice from lowest to highest when expect(error).toBeUndefined(); return; } + const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); - expect(result).toEqual(mockSortedByPriceLow2HighCatalogItemsResponse); + expect(resultProductIds).toEqual(opaqueCatalogItemIds.reverse()); }); // expect error when invalid currency code is provided diff --git a/tests/mocks/mockCatalogItems.js b/tests/mocks/mockCatalogItems.js deleted file mode 100644 index 2b95389bc9c..00000000000 --- a/tests/mocks/mockCatalogItems.js +++ /dev/null @@ -1,90 +0,0 @@ -import { cloneDeep } from "lodash"; -import { internalShopId } from "./mockShop"; -import { - internalCatalogItemIds, - mockExternalCatalogProducts, - mockInternalCatalogProducts -} from "./mockCatalogProducts"; - -/** - * - * @todo TEMP mocks this will be removed in favor of a fixture/factory solution - */ - -const createdAt = new Date("2018-04-16T15:34:28.043Z"); -const updatedAt = new Date("2018-04-17T15:34:28.043Z"); - -/** - * mock internal catalog items - */ -export const mockCatalogItems = [ - { - _id: internalCatalogItemIds[0], - product: mockInternalCatalogProducts[0], - shopId: internalShopId, - createdAt, - updatedAt - }, - { - _id: internalCatalogItemIds[1], - product: mockInternalCatalogProducts[1], - shopId: internalShopId, - createdAt, - updatedAt - } -]; - -/** - * Mock absolute URLs in catalog products when returned from GraphQL - */ -export const mockExternalCatalogProductNodes = []; -const siteURL = "https://shop.fake.site"; - -function mockMediaURLsResponse(URLs) { - const { large, medium, original, small, thumbnail } = URLs; - return { - thumbnail: `${siteURL}${thumbnail}`, - small: `${siteURL}${small}`, - medium: `${siteURL}${medium}`, - large: `${siteURL}${large}`, - original: `${siteURL}${original}` - }; -} - -mockExternalCatalogProducts.forEach((mockExternalCatalogProduct) => { - const cloned = cloneDeep(mockExternalCatalogProduct); - cloned.product.primaryImage.URLs = mockMediaURLsResponse(cloned.product.primaryImage.URLs); - cloned.product.media.forEach((media) => { - media.URLs = mockMediaURLsResponse(media.URLs); - }); - - mockExternalCatalogProductNodes.push(cloned); -}); - -/** - * mock unsorted catalogItems query response - */ -export const mockUnsortedCatalogItemsResponse = { - catalogItems: { - nodes: mockExternalCatalogProductNodes - } -}; - - -/** - * mock sorted by minPrice high to low catalogItems query response - */ -export const mockSortedByPriceHigh2LowCatalogItemsResponse = { - catalogItems: { - nodes: [mockExternalCatalogProductNodes[1], mockExternalCatalogProductNodes[0]] - } -}; - -/** - * mock sorted by minPrice low to high catalogItems query response - */ -export const mockSortedByPriceLow2HighCatalogItemsResponse = { - catalogItems: { - nodes: [mockExternalCatalogProductNodes[0], mockExternalCatalogProductNodes[1]] - } -}; From e97cbf9f43912f1ed5d3fbc00aa1c4d4f3462d91 Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 18:13:29 +0530 Subject: [PATCH 7/9] test: fix linting errors for catalogItems test Signed-off-by: trojanh --- .../api/queries/catalogItems/catalogItems.test.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index 07463c12bce..f69a68d9dea 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,4 +1,3 @@ -import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import Factory from "/tests/util/factory.js"; @@ -7,8 +6,6 @@ import TestApp from "/tests/util/TestApp.js"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); -const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); - const internalShopId = "123"; const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; const shopName = "Test Shop"; @@ -144,7 +141,7 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when const firstResultItem = result.catalogItems.nodes[0]; const lastResultItem = result.catalogItems.nodes[result.catalogItems.nodes.length - 1]; - const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); + const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); expect(result.catalogItems.nodes.length).toEqual(15); @@ -205,9 +202,7 @@ test("expect CatalogitemProducts with offset and featured sort to skip items", a expect(error).toBeUndefined(); return; } - const ids = result.catalogItems.nodes.map((n) => decodeCatalogProductOpaqueId(n.product._id)); - // console.log(result.catalogItems.totalCount); - // console.log({ ids }); + expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); // @TODO: debug this expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(true); @@ -228,7 +223,7 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when expect(error).toBeUndefined(); return; } - const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); + const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); expect(resultProductIds).toEqual(opaqueCatalogItemIds); }); @@ -247,7 +242,7 @@ test("expect CatalogItemProducts sorted by minPrice from lowest to highest when expect(error).toBeUndefined(); return; } - const resultProductIds = result.catalogItems.nodes.map((n) => n.product._id); + const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); expect(resultProductIds).toEqual(opaqueCatalogItemIds.reverse()); }); From b24d8f0434e0b7cace25c9315fb05cb6054bff7d Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 18:14:30 +0530 Subject: [PATCH 8/9] test: fix test cases for catalogItemProduct query Signed-off-by: trojanh --- .../catalogItemProduct.test.js | 541 ++++-------------- 1 file changed, 98 insertions(+), 443 deletions(-) diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index 9cb0d66a533..8864588fb0b 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,468 +1,80 @@ +import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; +import Factory from "/tests/util/factory.js"; import TestApp from "/tests/util/TestApp.js"; -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); -jest.setTimeout(300000); +const decodeCatalogProductOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProduct"); +const decodeCatalogItemOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogItem"); +const decodeCatalogProductVariantOpaqueId = decodeOpaqueIdForNamespace("reaction/catalogProductVariant"); const internalShopId = "123"; -const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const internalTagIds = ["923", "924"]; -const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag const shopName = "Test Shop"; -const mockCatalogItem = { - _id: "999", - product: { - _id: "999", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - isVisible: true, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { - containers: "containers", - length: 4.44, - width: 5.55, - height: 6.66, - weight: 7.77 - }, - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - productId: "999", - media: [ - { - priority: 1, - productId: "999", - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - } - ], - primaryImage: { - priority: 1, - productId: "999", - variantId: null, - URLs: { - thumbnail: "/thumbnail", - small: "/small", - medium: "/medium", - large: "/large", - original: "/original" - } - }, - productType: "productType", - shopId: "123", - sku: "ABC123", - slug: "fake-product", - socialMetadata: [ - { - service: "twitter", - message: "twitterMessage" - }, - { - service: "facebook", - message: "facebookMessage" - }, - { - service: "googleplus", - message: "googlePlusMessage" - }, - { - service: "pinterest", - message: "pinterestMessage" - } - ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["923", "924"], - title: "Fake Product Title", - type: "product-simple", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "875", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "874", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "874", - weight: 2, - width: 2 - }, - { - _id: "873", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "873", - weight: 2, - width: 2 - } - ], - optionTitle: "Untitled Option", - originCountry: "US", - pricing: { - USD: { - compareAtPrice: 10, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - }, - shopId: "123", - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "875", - weight: 0, - width: 0 - } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 - }, - shopId: "123", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z" -}; +const mockTag = Factory.Tag.makeOne({ + shopId: internalShopId, + slug: "2" +}); -const expectedItemsResponse = { - catalogItemProduct: { - _id: "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", - createdAt: "2018-04-16T15:34:28.043Z", - updatedAt: "2018-04-17T15:34:28.043Z", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - product: { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - description: "description", - height: 11.23, - isBackorder: false, - isLowQuantity: false, - isSoldOut: false, - length: 5.67, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - metaDescription: "metaDescription", - minOrderQuantity: 5, - originCountry: "originCountry", - pageTitle: "pageTitle", - parcel: { containers: "containers", length: 4.44, width: 5.55, height: 6.66, weight: 7.77 }, - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, +const mockCatalogItem = Factory.Catalog.makeOne({ + _id: "400", + product: () => + Factory.CatalogProduct.makeOne({ + _id: "500", + productId: "500", + isDeleted: false, + isVisible: true, + tagIds: [mockTag._id], + shopId: internalShopId, + pricing: { + USD: { + compareAtPrice: 6.0, + displayPrice: "2.99 - 4.99", + maxPrice: 4.99, minPrice: 2.99, price: null } - ], - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + }, media: [ { priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", + productId: "500", variantId: null, URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" } } ], - primaryImage: { - priority: 1, - productId: "cmVhY3Rpb24vcHJvZHVjdDo5OTk=", - variantId: null, - URLs: { - thumbnail: "https://shop.fake.site/thumbnail", - small: "https://shop.fake.site/small", - medium: "https://shop.fake.site/medium", - large: "https://shop.fake.site/large", - original: "https://shop.fake.site/original" - } - }, - productType: "productType", - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "ABC123", - slug: "fake-product", socialMetadata: [ { service: "twitter", message: "twitterMessage" }, { service: "facebook", message: "facebookMessage" }, { service: "googleplus", message: "googlePlusMessage" }, { service: "pinterest", message: "pinterestMessage" } ], - supportedFulfillmentTypes: ["shipping"], - tagIds: ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="], - tags: { nodes: [{ _id: "cmVhY3Rpb24vdGFnOjkyMw==" }, { _id: "cmVhY3Rpb24vdGFnOjkyNA==" }] }, - title: "Fake Product Title", - updatedAt: "2018-04-17T15:34:28.043Z", - variants: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", - barcode: "barcode", - createdAt: "2018-04-16T15:34:28.043Z", - height: 0, - index: 0, - isLowQuantity: false, - isSoldOut: true, - isTaxable: true, - length: 0, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - options: [ - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "5.99", - maxPrice: 5.99, - minPrice: 5.99, - price: 5.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Two pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", - weight: 2, - width: 2 - }, - { - _id: "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==", - barcode: "barcode", - createdAt: null, - height: 2, - index: 0, - isLowQuantity: false, - isSoldOut: false, - isTaxable: true, - length: 2, - metafields: [ - { - value: "value", - namespace: "namespace", - description: "description", - valueType: "valueType", - scope: "scope", - key: "key" - } - ], - minOrderQuantity: 0, - optionTitle: "Another Awesome Soft Bike", - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: null, - displayPrice: "2.99", - maxPrice: 2.99, - minPrice: 2.99, - price: 2.99 - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "One pound bag", - updatedAt: null, - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzM=", - weight: 2, - width: 2 - } - ], - originCountry: "US", - pricing: [ - { - currency: { _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", code: "USD" }, - compareAtPrice: { amount: 10 }, - displayPrice: "2.99 - 5.99", - maxPrice: 5.99, - minPrice: 2.99, - price: null - } - ], - shop: { _id: "cmVhY3Rpb24vc2hvcDoxMjM=" }, - sku: "sku", - taxCode: "0000", - taxDescription: "taxDescription", - title: "Small Concrete Pizza", - updatedAt: "2018-04-17T15:34:28.043Z", - variantId: "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", - weight: 0, - width: 0 + variants: Factory.CatalogProductVariant.makeMany(1, { + options: null, + shopId: internalShopId, + pricing: { + USD: { + compareAtPrice: 6.0, + displayPrice: "2.99 - 4.99", + maxPrice: 4.99, + minPrice: 2.99, + price: null + } } - ], - vendor: "vendor", - weight: 15.6, - width: 8.4 - } - } -}; + }) + }), + shopId: internalShopId +}); + +jest.setTimeout(300000); let testApp; let query; @@ -471,15 +83,13 @@ beforeAll(async () => { await testApp.start(); query = testApp.query(CatalogItemProductFullQuery); await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); - await Promise.all( - internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` })) - ); + await testApp.collections.Tags.insertOne(mockTag); await testApp.collections.Catalog.insertOne(mockCatalogItem); }); afterAll(async () => { await testApp.collections.Shops.deleteOne({ _id: internalShopId }); - await testApp.collections.Tags.deleteMany({ _id: { $in: internalTagIds } }); + await testApp.collections.Tags.deleteOne(mockTag); await testApp.collections.Catalog.deleteOne({ _id: mockCatalogItem._id }); await testApp.stop(); }); @@ -492,7 +102,31 @@ test("get a catalog product by slug", async () => { expect(error).toBeUndefined(); return; } - expect(result).toEqual(expectedItemsResponse); + + expect(decodeCatalogItemOpaqueId(result.catalogItemProduct._id)).toEqual(mockCatalogItem._id); + expect(decodeCatalogProductOpaqueId(result.catalogItemProduct.product._id)).toEqual(mockCatalogItem.product._id); + expect(decodeCatalogProductVariantOpaqueId(result.catalogItemProduct.product.variants[0]._id)) + .toEqual(mockCatalogItem.product.variants[0]._id); + expect(result.catalogItemProduct.product.socialMetadata).toEqual([ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ]); + expect(result.catalogItemProduct.product.media).toEqual([ + { + priority: 1, + productId: result.catalogItemProduct.product.productId, + variantId: null, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ]); }); test("get a catalog product by ID", async () => { @@ -504,5 +138,26 @@ test("get a catalog product by ID", async () => { return; } - expect(result).toEqual(expectedItemsResponse); + expect(decodeCatalogItemOpaqueId(result.catalogItemProduct._id)).toEqual(mockCatalogItem._id); + expect(decodeCatalogProductOpaqueId(result.catalogItemProduct.product._id)).toEqual(mockCatalogItem.product._id); + expect(decodeCatalogProductVariantOpaqueId(result.catalogItemProduct.product.variants[0]._id)) + .toEqual(mockCatalogItem.product.variants[0]._id); + expect(result.catalogItemProduct.product.socialMetadata).toEqual([ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ]); + expect(result.catalogItemProduct.product.media).toMatchObject([ + { + productId: result.catalogItemProduct.product.productId, + URLs: { + thumbnail: "https://shop.fake.site/thumbnail", + small: "https://shop.fake.site/small", + medium: "https://shop.fake.site/medium", + large: "https://shop.fake.site/large", + original: "https://shop.fake.site/original" + } + } + ]); }); From 4810617e83eb51115d771a5d64ad1ac66c01ed74 Mon Sep 17 00:00:00 2001 From: trojanh Date: Tue, 17 Dec 2019 20:56:14 +0530 Subject: [PATCH 9/9] tests: revert catalogItems tests Signed-off-by: trojanh --- .../queries/catalogItems/catalogItems.test.js | 148 +--- tests/mocks/mockCatalogItems.js | 90 +++ tests/mocks/mockCatalogProducts.js | 715 ++++++++++++++++++ tests/mocks/mockShop.js | 8 + tests/mocks/mockTags.js | 7 + 5 files changed, 848 insertions(+), 120 deletions(-) create mode 100644 tests/mocks/mockCatalogItems.js create mode 100644 tests/mocks/mockCatalogProducts.js create mode 100644 tests/mocks/mockShop.js create mode 100644 tests/mocks/mockTags.js diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index f69a68d9dea..daa315a7485 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,111 +1,39 @@ -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; import importAsString from "@reactioncommerce/api-utils/importAsString.js"; -import Factory from "/tests/util/factory.js"; import TestApp from "/tests/util/TestApp.js"; +// temp mocks +import { internalShopId, opaqueShopId, shopName } from "../../../../mocks/mockShop"; +import { internalTagIds, opaqueTagIds } from "../../../../mocks/mockTags"; +import { internalCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; +import { + mockCatalogItems, + mockUnsortedCatalogItemsResponse, + mockSortedByPriceHigh2LowCatalogItemsResponse, + mockSortedByPriceLow2HighCatalogItemsResponse +} from "../../../../mocks/mockCatalogItems"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); -const internalShopId = "123"; -const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; -const shopName = "Test Shop"; - -const mockTag = Factory.Tag.makeOne({ - featuredProductIds: [ - "501", - "503", - "505", - "506", - "504", - "500", - "501", - "502", - "507", - "508", - "509", - "512", - "511", - "513", - "510", - "506", - "514" - ], - shopId: internalShopId, - slug: "2" -}); - -const mockCatalogItems = Factory.Catalog.makeMany(15, { - _id: (iterator) => (iterator + 500).toString(), - product: (iterator) => - Factory.CatalogProduct.makeOne({ - _id: (iterator + 500).toString(), - productId: (iterator + 500).toString(), - isDeleted: false, - isVisible: true, - tagIds: [mockTag._id], - shopId: internalShopId, - pricing: { - USD: { - compareAtPrice: 6.0 + (iterator + 10), - displayPrice: `${0.99 + iterator} - ${1.99 + iterator}`, - maxPrice: 1.99 + iterator, - minPrice: 0.99 + iterator, - price: null - } - }, - media: [ - { - priority: 1, - productId: (iterator + 500).toString(), - variantId: null, - URLs: { thumbnail: "/thumbnail", small: "/small", medium: "/medium", large: "/large", original: "/original" } - } - ], - socialMetadata: [ - { service: "twitter", message: "twitterMessage" }, - { service: "facebook", message: "facebookMessage" }, - { service: "googleplus", message: "googlePlusMessage" }, - { service: "pinterest", message: "pinterestMessage" } - ], - variants: Factory.CatalogProductVariant.makeMany(1, { - options: null, - shopId: internalShopId, - pricing: { - USD: { - compareAtPrice: 6.0 + (iterator + 10), - displayPrice: `${0.99 + iterator} - ${1.99 + iterator}`, - maxPrice: 1.99 + iterator, - minPrice: 0.99 + iterator, - price: null - } - } - }) - }), - shopId: internalShopId -}); - -const opaqueCatalogItemIds = mockCatalogItems.map((item) => encodeOpaqueId("reaction/catalogProduct", item._id)); - jest.setTimeout(300000); let testApp; let query; let paginatedQuery; - beforeAll(async () => { testApp = new TestApp(); await testApp.start(); query = testApp.query(CatalogProductItemsFullQuery); paginatedQuery = testApp.query(CatalogProductItemsFullQueryPaginated); await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); - await testApp.collections.Tags.insertOne(mockTag); - await Promise.all(mockCatalogItems.map((mockItem) => testApp.collections.Catalog.insertOne(mockItem))); + await Promise.all(internalTagIds.map((_id) => testApp.collections.Tags.insertOne({ _id, shopId: internalShopId, slug: `slug${_id}` }))); + await Promise.all(mockCatalogItems.map((mockCatalogItem) => testApp.collections.Catalog.insertOne(mockCatalogItem))); }); afterAll(async () => { await testApp.collections.Shops.deleteOne({ _id: internalShopId }); - await testApp.collections.Tags.deleteOne({ _id: mockTag._id }); - await Promise.all(mockCatalogItems.map((mockItem) => testApp.collections.Catalog.deleteOne({ _id: mockItem._id }))); + await testApp.collections.Tags.deleteMany({ _id: { $in: internalTagIds } }); + await testApp.collections.Catalog.deleteOne({ _id: internalCatalogItemIds[0] }); + await testApp.collections.Catalog.deleteOne({ _id: internalCatalogItemIds[1] }); await testApp.stop(); }); @@ -118,11 +46,7 @@ test("get all items for shop", async () => { return; } - expect(result.catalogItems.nodes.length).toEqual(15); - - result.catalogItems.nodes.forEach(({ product }) => { - expect(opaqueCatalogItemIds).toContain(product._id); - }); + expect(result).toEqual(mockUnsortedCatalogItemsResponse); }); // expect CatalogItems sorted by minPrice form high to low @@ -135,25 +59,10 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when return; } - const firstCatalogItem = mockCatalogItems[0]; - const lastCatalogItem = mockCatalogItems[mockCatalogItems.length - 1]; - - const firstResultItem = result.catalogItems.nodes[0]; - const lastResultItem = result.catalogItems.nodes[result.catalogItems.nodes.length - 1]; - - const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); - - expect(result.catalogItems.nodes.length).toEqual(15); - - expect(firstResultItem.product.pricing[0].minPrice).toEqual(lastCatalogItem.product.pricing.USD.minPrice); - expect(firstResultItem.product._id).toEqual(opaqueCatalogItemIds[opaqueCatalogItemIds.length - 1]); - - expect(lastResultItem.product.pricing[0].minPrice).toEqual(firstCatalogItem.product.pricing.USD.minPrice); - expect(lastResultItem.product._id).toEqual(opaqueCatalogItemIds[0]); - expect(resultProductIds).toEqual(opaqueCatalogItemIds.reverse()); + expect(result).toEqual(mockSortedByPriceHigh2LowCatalogItemsResponse); }); -test("expect CatalogItemProducts with offset 0 to return all items", async () => { +test("expect CatalogItemProducts with offset 0 to return first item", async () => { let result; try { result = await paginatedQuery({ @@ -164,10 +73,10 @@ test("expect CatalogItemProducts with offset 0 to return all items", async () => expect(error).toBeUndefined(); return; } - expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); - expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(false); - expect(result.catalogItems.totalCount).toBe(15); - expect(result.catalogItems.nodes.length).toBe(15); + + expect(result.catalogItems.totalCount).toBe(2); + expect(result.catalogItems.nodes.length).toBe(2); + expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[0].product._id); }); // expect CatalogItems with offset to skip items @@ -185,7 +94,8 @@ test("expect CatalogitemProducts with offset to skip items", async () => { expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(true); - expect(result.catalogItems.nodes.length).toBe(14); + expect(result.catalogItems.nodes.length).toBe(1); + expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[1].product._id); }); // expect CatalogItems with feature sortBy and offset to skip items correctly @@ -196,7 +106,7 @@ test("expect CatalogitemProducts with offset and featured sort to skip items", a shopIds: [opaqueShopId], offset: 1, sortBy: "featured", - tagIds: [encodeOpaqueId("reaction/tag", mockTag._id)] + tagIds: [opaqueTagIds[0]] }); } catch (error) { expect(error).toBeUndefined(); @@ -204,9 +114,9 @@ test("expect CatalogitemProducts with offset and featured sort to skip items", a } expect(result.catalogItems.pageInfo.hasNextPage).toBe(false); - // @TODO: debug this expect(result.catalogItems.pageInfo.hasPreviousPage).toBe(true); expect(result.catalogItems.nodes.length).toBe(1); + expect(result.catalogItems.nodes[0].product._id).toEqual(mockUnsortedCatalogItemsResponse.catalogItems.nodes[0].product._id); }); // expect CatalogItems sorted by minPrice form high to low when sortOrder is desc @@ -223,9 +133,8 @@ test("expect CatalogItemProducts sorted by minPrice from highest to lowest when expect(error).toBeUndefined(); return; } - const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); - expect(resultProductIds).toEqual(opaqueCatalogItemIds); + expect(result).toEqual(mockSortedByPriceHigh2LowCatalogItemsResponse); }); // expect CatalogItems sorted by minPrice form low to high when sortOrder is asc @@ -242,9 +151,8 @@ test("expect CatalogItemProducts sorted by minPrice from lowest to highest when expect(error).toBeUndefined(); return; } - const resultProductIds = result.catalogItems.nodes.map((node) => node.product._id); - expect(resultProductIds).toEqual(opaqueCatalogItemIds.reverse()); + expect(result).toEqual(mockSortedByPriceLow2HighCatalogItemsResponse); }); // expect error when invalid currency code is provided diff --git a/tests/mocks/mockCatalogItems.js b/tests/mocks/mockCatalogItems.js new file mode 100644 index 00000000000..2b95389bc9c --- /dev/null +++ b/tests/mocks/mockCatalogItems.js @@ -0,0 +1,90 @@ +import { cloneDeep } from "lodash"; +import { internalShopId } from "./mockShop"; +import { + internalCatalogItemIds, + mockExternalCatalogProducts, + mockInternalCatalogProducts +} from "./mockCatalogProducts"; + +/** + * + * @todo TEMP mocks this will be removed in favor of a fixture/factory solution + */ + +const createdAt = new Date("2018-04-16T15:34:28.043Z"); +const updatedAt = new Date("2018-04-17T15:34:28.043Z"); + +/** + * mock internal catalog items + */ +export const mockCatalogItems = [ + { + _id: internalCatalogItemIds[0], + product: mockInternalCatalogProducts[0], + shopId: internalShopId, + createdAt, + updatedAt + }, + { + _id: internalCatalogItemIds[1], + product: mockInternalCatalogProducts[1], + shopId: internalShopId, + createdAt, + updatedAt + } +]; + +/** + * Mock absolute URLs in catalog products when returned from GraphQL + */ +export const mockExternalCatalogProductNodes = []; +const siteURL = "https://shop.fake.site"; + +function mockMediaURLsResponse(URLs) { + const { large, medium, original, small, thumbnail } = URLs; + return { + thumbnail: `${siteURL}${thumbnail}`, + small: `${siteURL}${small}`, + medium: `${siteURL}${medium}`, + large: `${siteURL}${large}`, + original: `${siteURL}${original}` + }; +} + +mockExternalCatalogProducts.forEach((mockExternalCatalogProduct) => { + const cloned = cloneDeep(mockExternalCatalogProduct); + cloned.product.primaryImage.URLs = mockMediaURLsResponse(cloned.product.primaryImage.URLs); + cloned.product.media.forEach((media) => { + media.URLs = mockMediaURLsResponse(media.URLs); + }); + + mockExternalCatalogProductNodes.push(cloned); +}); + +/** + * mock unsorted catalogItems query response + */ +export const mockUnsortedCatalogItemsResponse = { + catalogItems: { + nodes: mockExternalCatalogProductNodes + } +}; + + +/** + * mock sorted by minPrice high to low catalogItems query response + */ +export const mockSortedByPriceHigh2LowCatalogItemsResponse = { + catalogItems: { + nodes: [mockExternalCatalogProductNodes[1], mockExternalCatalogProductNodes[0]] + } +}; + +/** + * mock sorted by minPrice low to high catalogItems query response + */ +export const mockSortedByPriceLow2HighCatalogItemsResponse = { + catalogItems: { + nodes: [mockExternalCatalogProductNodes[0], mockExternalCatalogProductNodes[1]] + } +}; diff --git a/tests/mocks/mockCatalogProducts.js b/tests/mocks/mockCatalogProducts.js new file mode 100644 index 00000000000..60e0aac2869 --- /dev/null +++ b/tests/mocks/mockCatalogProducts.js @@ -0,0 +1,715 @@ +import { internalShopId, opaqueShopId } from "./mockShop"; +import { internalTagIds, opaqueTagIds } from "./mockTags"; + +/** + * + * @todo TEMP mocks these will be removed in favor of a fixture/factory solution + */ + +export const internalProductIds = ["999", "222"]; +export const opaqueProductIds = ["cmVhY3Rpb24vcHJvZHVjdDo5OTk=", "cmVhY3Rpb24vcHJvZHVjdDoyMjI="]; // reaction/product + +export const internalVariantIds = ["875", "874", "873"]; +export const opaqueVariantIds = [ + "cmVhY3Rpb24vcHJvZHVjdDo4NzU=", + "cmVhY3Rpb24vcHJvZHVjdDo4NzQ=", + "cmVhY3Rpb24vcHJvZHVjdDo4NzM=" +]; // reaction/product + +export const internalCatalogProductIds = ["999", "222"]; +export const opaqueCatalogProductIds = ["cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6OTk5", "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3Q6MjIy"]; // reaction/catalogProduct + +export const opaqueCatalogVariantIds = [ + "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NQ==", + "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3NA==", + "cmVhY3Rpb24vY2F0YWxvZ1Byb2R1Y3RWYXJpYW50Ojg3Mw==" +]; // reaction/catalogProductVariant + +export const internalCatalogItemIds = ["999", "222"]; +export const opaqueCatalogItemIds = ["cmVhY3Rpb24vY2F0YWxvZ0l0ZW06OTk5", "cmVhY3Rpb24vY2F0YWxvZ0l0ZW06MjIy"]; // reaction/catalogItem + +export const createdAt = new Date("2018-04-16T15:34:28.043Z"); +export const updatedAt = new Date("2018-04-17T15:34:28.043Z"); + +/** + * mock internal catalog product variant options + */ +export const mockInternalCatalogOptions = [ + { + _id: internalVariantIds[1], + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + }, + shopId: internalShopId, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: internalVariantIds[1], + weight: 2, + width: 2 + }, + { + _id: internalVariantIds[2], + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + }, + shopId: internalShopId, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: internalVariantIds[2], + weight: 2, + width: 2 + } +]; + +/** + * mock external catalog product variant options + */ +export const mockExternalCatalogOptions = [ + { + _id: opaqueCatalogVariantIds[1], + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { + _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", + code: "USD" + }, + compareAtPrice: null, + displayPrice: "5.99", + maxPrice: 5.99, + minPrice: 5.99, + price: 5.99 + } + ], + shop: { + _id: opaqueShopId + }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Two pound bag", + updatedAt: null, + variantId: opaqueVariantIds[1], + weight: 2, + width: 2 + }, + { + _id: opaqueCatalogVariantIds[2], + barcode: "barcode", + createdAt: null, + height: 2, + index: 0, + isLowQuantity: false, + isSoldOut: false, + isTaxable: true, + length: 2, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + optionTitle: "Another Awesome Soft Bike", + originCountry: "US", + pricing: [ + { + currency: { + _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", + code: "USD" + }, + compareAtPrice: null, + displayPrice: "2.99", + maxPrice: 2.99, + minPrice: 2.99, + price: 2.99 + } + ], + shop: { + _id: opaqueShopId + }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "One pound bag", + updatedAt: null, + variantId: opaqueVariantIds[2], + weight: 2, + width: 2 + } +]; + +/** + * mock internal catalog product variants + */ +export const mockInternalCatalogVariants = [ + { + _id: internalVariantIds[0], + barcode: "barcode", + createdAt: createdAt.toISOString(), + height: 0, + index: 0, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: mockInternalCatalogOptions, + optionTitle: "Untitled Option", + originCountry: "US", + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + shopId: internalShopId, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: updatedAt.toISOString(), + variantId: internalVariantIds[0], + weight: 0, + width: 0 + } +]; + +/** + * mock external catalog product variants + */ +export const mockExternalCatalogVariants = [ + { + _id: opaqueCatalogVariantIds[0], + barcode: "barcode", + createdAt: createdAt.toISOString(), + height: 0, + index: 0, + isLowQuantity: false, + isSoldOut: true, + isTaxable: true, + length: 0, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + minOrderQuantity: 0, + options: mockExternalCatalogOptions, + originCountry: "US", + pricing: [ + { + currency: { + _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", + code: "USD" + }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + shop: { + _id: opaqueShopId + }, + sku: "sku", + taxCode: "0000", + taxDescription: "taxDescription", + title: "Small Concrete Pizza", + updatedAt: updatedAt.toISOString(), + variantId: opaqueVariantIds[0], + weight: 0, + width: 0 + } +]; + +/** + * mock internal catalog products + */ +export const mockInternalCatalogProducts = [ + { + _id: internalCatalogProductIds[0], + barcode: "barcode", + createdAt: createdAt.toISOString(), + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: { + USD: { + compareAtPrice: 10, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + }, + productId: internalProductIds[0], + media: [ + { + priority: 1, + productId: internalProductIds[0], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: internalProductIds[0], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shopId: internalShopId, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: internalTagIds, + title: "Fake Product Title", + type: "product-simple", + updatedAt: updatedAt.toISOString(), + variants: mockInternalCatalogVariants, + vendor: "vendor", + weight: 15.6, + width: 8.4 + }, + { + _id: internalCatalogProductIds[1], + barcode: "barcode", + createdAt: createdAt.toISOString(), + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + isVisible: true, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: { + USD: { + compareAtPrice: 35, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + }, + productId: internalProductIds[1], + media: [ + { + priority: 1, + productId: internalProductIds[1], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: internalProductIds[1], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shopId: internalShopId, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: internalTagIds, + title: "Another Fake Product Title", + type: "product-simple", + updatedAt: updatedAt.toISOString(), + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } +]; + +/** + * mock external catalog products + */ +export const mockExternalCatalogProducts = [ + { + _id: opaqueCatalogItemIds[0], + createdAt: createdAt.toISOString(), + updatedAt: updatedAt.toISOString(), + shop: { + _id: opaqueShopId + }, + product: { + _id: opaqueCatalogProductIds[0], + barcode: "barcode", + createdAt: createdAt.toISOString(), + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: [ + { + currency: { + _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", + code: "USD" + }, + compareAtPrice: { amount: 10 }, + displayPrice: "2.99 - 5.99", + maxPrice: 5.99, + minPrice: 2.99, + price: null + } + ], + productId: opaqueProductIds[0], + media: [ + { + priority: 1, + productId: opaqueProductIds[0], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: opaqueProductIds[0], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shop: { + _id: opaqueShopId + }, + sku: "ABC123", + slug: "fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: opaqueTagIds, + tags: { + nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] + }, + title: "Fake Product Title", + updatedAt: updatedAt.toISOString(), + variants: mockExternalCatalogVariants, + vendor: "vendor", + weight: 15.6, + width: 8.4 + } + }, + { + _id: opaqueCatalogItemIds[1], + createdAt: createdAt.toISOString(), + updatedAt: updatedAt.toISOString(), + shop: { + _id: opaqueShopId + }, + product: { + _id: opaqueCatalogProductIds[1], + barcode: "barcode", + createdAt: createdAt.toISOString(), + description: "description", + height: 11.23, + isBackorder: false, + isLowQuantity: false, + isSoldOut: false, + length: 5.67, + metafields: [ + { + value: "value", + namespace: "namespace", + description: "description", + valueType: "valueType", + scope: "scope", + key: "key" + } + ], + metaDescription: "metaDescription", + minOrderQuantity: 5, + originCountry: "originCountry", + pageTitle: "pageTitle", + parcel: { + containers: "containers", + length: 4.44, + width: 5.55, + height: 6.66, + weight: 7.77 + }, + pricing: [ + { + currency: { + _id: "cmVhY3Rpb24vY3VycmVuY3k6VVNE", + code: "USD" + }, + compareAtPrice: { amount: 35 }, + displayPrice: "16.99 - 25.99", + maxPrice: 25.99, + minPrice: 16.99, + price: null + } + ], + productId: opaqueProductIds[1], + media: [ + { + priority: 1, + productId: opaqueProductIds[1], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + } + ], + primaryImage: { + priority: 1, + productId: opaqueProductIds[1], + variantId: null, + URLs: { + thumbnail: "/thumbnail", + small: "/small", + medium: "/medium", + large: "/large", + original: "/original" + } + }, + productType: "productType", + shop: { + _id: opaqueShopId + }, + sku: "ABC123", + slug: "another-fake-product", + socialMetadata: [ + { service: "twitter", message: "twitterMessage" }, + { service: "facebook", message: "facebookMessage" }, + { service: "googleplus", message: "googlePlusMessage" }, + { service: "pinterest", message: "pinterestMessage" } + ], + supportedFulfillmentTypes: ["shipping"], + tagIds: opaqueTagIds, + tags: { + nodes: [{ _id: opaqueTagIds[0] }, { _id: opaqueTagIds[1] }] + }, + title: "Another Fake Product Title", + updatedAt: updatedAt.toISOString(), + variants: [], + vendor: "another vendor", + weight: 15.6, + width: 8.4 + } + } +]; diff --git a/tests/mocks/mockShop.js b/tests/mocks/mockShop.js new file mode 100644 index 00000000000..f22324288fb --- /dev/null +++ b/tests/mocks/mockShop.js @@ -0,0 +1,8 @@ +/** + * + * @todo TEMP Mocks these will be removed in favor of a fixture/factory solution + */ + +export const internalShopId = "123"; +export const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; // reaction/shop:123 +export const shopName = "Test Shop"; diff --git a/tests/mocks/mockTags.js b/tests/mocks/mockTags.js new file mode 100644 index 00000000000..63632bd1b5e --- /dev/null +++ b/tests/mocks/mockTags.js @@ -0,0 +1,7 @@ +/** + * + * @todo TEMP mocks these will be removed in favor of a fixture/factory solution + */ + +export const internalTagIds = ["923", "924"]; +export const opaqueTagIds = ["cmVhY3Rpb24vdGFnOjkyMw==", "cmVhY3Rpb24vdGFnOjkyNA=="]; // reaction/tag