From 5ddccb3ce363cf5043bff05c0e7856f0b5a982aa Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 11:23:59 +0530 Subject: [PATCH 1/3] test: Use raw catalogItem and catalogItemProduct objects for tests Signed-off-by: trojanh --- .../catalogItemProduct.test.js | 468 ++++++- .../queries/catalogItems/catalogItems.test.js | 1209 ++++++++++++++++- tests/mocks/mockCatalogItems.js | 90 -- tests/mocks/mockCatalogProducts.js | 715 ---------- tests/mocks/mockShop.js | 8 - tests/mocks/mockTags.js | 7 - 6 files changed, 1658 insertions(+), 839 deletions(-) delete mode 100644 tests/mocks/mockCatalogItems.js delete mode 100644 tests/mocks/mockCatalogProducts.js delete mode 100644 tests/mocks/mockShop.js 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 4f16e9c8f19..9cb0d66a533 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,18 +1,467 @@ 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"; +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); jest.setTimeout(300000); -const mockCatalogItem = mockCatalogItems[0]; +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 expectedItemsResponse = { - catalogItemProduct: mockExternalCatalogProductNodes[0] + 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; @@ -22,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); }); @@ -41,14 +492,13 @@ test("get a catalog product by slug", async () => { expect(error).toBeUndefined(); return; } - expect(result).toEqual(expectedItemsResponse); }); 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; diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index daa315a7485..f4e53d0e5f9 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,24 +1,1213 @@ 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 { - mockCatalogItems, - mockUnsortedCatalogItemsResponse, - mockSortedByPriceHigh2LowCatalogItemsResponse, - mockSortedByPriceLow2HighCatalogItemsResponse -} from "../../../../mocks/mockCatalogItems"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); +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, + 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(); await testApp.start(); 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]] - } -}; 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 - } - } -]; 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"; 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 c60a00fab82b45c9c0ecd2a14abb37d2dff9aae6 Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 19:48:40 +0530 Subject: [PATCH 2/3] test: delete documents in afterAll Signed-off-by: trojanh --- .../addAccountToGroup.test.js | 4 + .../addOrderFulfillmentGroup.test.js | 2 + .../api/mutations/addTag/addTag.test.js | 4 + .../discountCodes/discountCodes.test.js | 2 + .../publishProductsToCatalog.test.js | 1 + .../api/mutations/removeTag/removeTag.test.js | 2 + .../splitOrderItem/splitOrderItem.test.js | 2 + .../updateOrderFulfillmentGroup.test.js | 2 + .../api/mutations/updateTag/updateTag.test.js | 2 + .../verifySMTPEmailSettings.test.js | 1 + .../api/queries/account/account.test.js | 6 +- .../api/queries/account/accounts.test.js | 1 + .../administrators/administrators.test.js | 7 +- .../catalogItemProduct.test.js | 468 +------ .../queries/catalogItems/catalogItems.test.js | 1209 +---------------- .../discountCodes/discountCodes.test.js | 2 + .../emailTemplates/emailTemplates.test.js | 2 + .../getFlatRateFulfillmentRestriction.test.js | 7 +- ...getFlatRateFulfillmentRestrictions.test.js | 1 + .../api/queries/group/group.test.js | 9 +- .../api/queries/groups/groups.test.js | 8 +- .../navigationItemsByShopId.test.js | 2 + .../navigation/navigationTreeById.test.js | 2 + .../api/queries/orderById/orderById.test.js | 7 +- .../ordersByAccountId.test.js | 1 + .../paymentMethods/paymentMethods.test.js | 1 + .../queries/primaryShop/primaryShop.test.js | 7 +- .../primaryShopId/primaryShopId.test.js | 5 +- .../productsByTagId/productsByTagId.test.js | 4 +- .../api/queries/roles/roles.test.js | 1 + .../integration/api/queries/shop/shop.test.js | 5 +- .../queries/shopSettings/shopSettings.test.js | 3 +- .../simpleInventory/simpleInventory.test.js | 2 + .../integration/api/queries/tags/tag.test.js | 1 + .../integration/api/queries/tags/tags.test.js | 6 +- .../api/queries/taxRates/taxRates.test.js | 2 + 36 files changed, 119 insertions(+), 1672 deletions(-) diff --git a/tests/integration/api/mutations/addAccountToGroup/addAccountToGroup.test.js b/tests/integration/api/mutations/addAccountToGroup/addAccountToGroup.test.js index a48f2a0aecc..5c9138b2ba0 100644 --- a/tests/integration/api/mutations/addAccountToGroup/addAccountToGroup.test.js +++ b/tests/integration/api/mutations/addAccountToGroup/addAccountToGroup.test.js @@ -78,6 +78,10 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + await testApp.collections.Groups.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/mutations/addOrderFulfillmentGroup/addOrderFulfillmentGroup.test.js b/tests/integration/api/mutations/addOrderFulfillmentGroup/addOrderFulfillmentGroup.test.js index 98fd3639917..d213a0b86e2 100644 --- a/tests/integration/api/mutations/addOrderFulfillmentGroup/addOrderFulfillmentGroup.test.js +++ b/tests/integration/api/mutations/addOrderFulfillmentGroup/addOrderFulfillmentGroup.test.js @@ -113,6 +113,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Catalog.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/mutations/addTag/addTag.test.js b/tests/integration/api/mutations/addTag/addTag.test.js index a82638ccba4..3e99382621a 100644 --- a/tests/integration/api/mutations/addTag/addTag.test.js +++ b/tests/integration/api/mutations/addTag/addTag.test.js @@ -30,9 +30,12 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); + beforeEach(async () => { tagInput = { displayTitle: "Tag: Display Title", @@ -67,6 +70,7 @@ describe("unauthorized user", () => { } }); }); + describe("authorized user", () => { beforeAll(async () => { await testApp.setLoggedInUser(mockTagsAccount); diff --git a/tests/integration/api/mutations/discountCodes/discountCodes.test.js b/tests/integration/api/mutations/discountCodes/discountCodes.test.js index 9030762117f..9a0088fdbf0 100644 --- a/tests/integration/api/mutations/discountCodes/discountCodes.test.js +++ b/tests/integration/api/mutations/discountCodes/discountCodes.test.js @@ -40,6 +40,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Discounts.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/mutations/publishProductsToCatalog/publishProductsToCatalog.test.js b/tests/integration/api/mutations/publishProductsToCatalog/publishProductsToCatalog.test.js index ab90efb083d..eff54351d48 100644 --- a/tests/integration/api/mutations/publishProductsToCatalog/publishProductsToCatalog.test.js +++ b/tests/integration/api/mutations/publishProductsToCatalog/publishProductsToCatalog.test.js @@ -109,6 +109,7 @@ afterAll(async () => { await testApp.collections.Products.deleteOne({ _id: internalVariantIds[0] }); await testApp.collections.Products.deleteOne({ _id: internalVariantIds[1] }); await testApp.collections.Products.deleteOne({ _id: internalVariantIds[2] }); + await testApp.collections.Tags.deleteMany({}); await testApp.clearLoggedInUser(); await testApp.stop(); }); diff --git a/tests/integration/api/mutations/removeTag/removeTag.test.js b/tests/integration/api/mutations/removeTag/removeTag.test.js index 379349c55d0..a24e1308284 100644 --- a/tests/integration/api/mutations/removeTag/removeTag.test.js +++ b/tests/integration/api/mutations/removeTag/removeTag.test.js @@ -43,6 +43,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/mutations/splitOrderItem/splitOrderItem.test.js b/tests/integration/api/mutations/splitOrderItem/splitOrderItem.test.js index 537e6da684d..049d3862f1b 100644 --- a/tests/integration/api/mutations/splitOrderItem/splitOrderItem.test.js +++ b/tests/integration/api/mutations/splitOrderItem/splitOrderItem.test.js @@ -74,6 +74,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Catalog.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/mutations/updateOrderFulfillmentGroup/updateOrderFulfillmentGroup.test.js b/tests/integration/api/mutations/updateOrderFulfillmentGroup/updateOrderFulfillmentGroup.test.js index 282bdf90b0b..cfe999b8c05 100644 --- a/tests/integration/api/mutations/updateOrderFulfillmentGroup/updateOrderFulfillmentGroup.test.js +++ b/tests/integration/api/mutations/updateOrderFulfillmentGroup/updateOrderFulfillmentGroup.test.js @@ -38,6 +38,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Catalog.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/mutations/updateTag/updateTag.test.js b/tests/integration/api/mutations/updateTag/updateTag.test.js index 1a5b077954b..cbd84d53ea2 100644 --- a/tests/integration/api/mutations/updateTag/updateTag.test.js +++ b/tests/integration/api/mutations/updateTag/updateTag.test.js @@ -47,6 +47,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.collections.Tags.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/mutations/verifySMTPEmailSettings/verifySMTPEmailSettings.test.js b/tests/integration/api/mutations/verifySMTPEmailSettings/verifySMTPEmailSettings.test.js index 7a9e9a1a6f0..499c883d7c3 100644 --- a/tests/integration/api/mutations/verifySMTPEmailSettings/verifySMTPEmailSettings.test.js +++ b/tests/integration/api/mutations/verifySMTPEmailSettings/verifySMTPEmailSettings.test.js @@ -40,6 +40,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/account/account.test.js b/tests/integration/api/queries/account/account.test.js index 0785115ee0c..7c9d24ffdb1 100644 --- a/tests/integration/api/queries/account/account.test.js +++ b/tests/integration/api/queries/account/account.test.js @@ -39,7 +39,11 @@ beforeAll(async () => { accountQuery = testApp.query(AccountFullQuery); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + testApp.stop(); +}); test("unauthenticated", async () => { try { diff --git a/tests/integration/api/queries/account/accounts.test.js b/tests/integration/api/queries/account/accounts.test.js index 468defb9d65..7b006f7a08f 100644 --- a/tests/integration/api/queries/account/accounts.test.js +++ b/tests/integration/api/queries/account/accounts.test.js @@ -84,6 +84,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Groups.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/queries/administrators/administrators.test.js b/tests/integration/api/queries/administrators/administrators.test.js index 6e332b7d329..e7cc4632147 100644 --- a/tests/integration/api/queries/administrators/administrators.test.js +++ b/tests/integration/api/queries/administrators/administrators.test.js @@ -85,7 +85,12 @@ beforeAll(async () => { administratorsQuery = testApp.query(AdministratorsFullQuery); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + await testApp.stop(); +}); test("unauthenticated", async () => { try { diff --git a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js index 9cb0d66a533..4f16e9c8f19 100644 --- a/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js +++ b/tests/integration/api/queries/catalogItemProduct/catalogItemProduct.test.js @@ -1,467 +1,18 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; import TestApp from "/tests/util/TestApp.js"; -import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; +import { internalShopId, shopName } from "../../../../mocks/mockShop"; +import { internalTagIds } from "../../../../mocks/mockTags"; +import { mockCatalogItems, mockExternalCatalogProductNodes } from "../../../../mocks/mockCatalogItems"; +import { opaqueCatalogItemIds } from "../../../../mocks/mockCatalogProducts"; const CatalogItemProductFullQuery = importAsString("./CatalogItemProductFullQuery.graphql"); jest.setTimeout(300000); -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 mockCatalogItem = mockCatalogItems[0]; 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 - } - } + catalogItemProduct: mockExternalCatalogProductNodes[0] }; let testApp; @@ -471,9 +22,7 @@ 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); }); @@ -492,13 +41,14 @@ test("get a catalog product by slug", async () => { expect(error).toBeUndefined(); return; } + expect(result).toEqual(expectedItemsResponse); }); test("get a catalog product by ID", async () => { let result; try { - result = await query({ slugOrId: encodeOpaqueId("reaction/catalogItem", mockCatalogItem._id) }); + result = await query({ slugOrId: opaqueCatalogItemIds[0] }); } catch (error) { expect(error).toBeUndefined(); return; diff --git a/tests/integration/api/queries/catalogItems/catalogItems.test.js b/tests/integration/api/queries/catalogItems/catalogItems.test.js index f4e53d0e5f9..daa315a7485 100644 --- a/tests/integration/api/queries/catalogItems/catalogItems.test.js +++ b/tests/integration/api/queries/catalogItems/catalogItems.test.js @@ -1,1213 +1,24 @@ 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 { + mockCatalogItems, + mockUnsortedCatalogItemsResponse, + mockSortedByPriceHigh2LowCatalogItemsResponse, + mockSortedByPriceLow2HighCatalogItemsResponse +} from "../../../../mocks/mockCatalogItems"; const CatalogProductItemsFullQuery = importAsString("./CatalogProductItemsFullQuery.graphql"); const CatalogProductItemsFullQueryPaginated = importAsString("./CatalogProductItemsFullQueryPaginated.graphql"); -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, - 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(); await testApp.start(); diff --git a/tests/integration/api/queries/discountCodes/discountCodes.test.js b/tests/integration/api/queries/discountCodes/discountCodes.test.js index 1ae72e36ccd..6c7c3fbd612 100644 --- a/tests/integration/api/queries/discountCodes/discountCodes.test.js +++ b/tests/integration/api/queries/discountCodes/discountCodes.test.js @@ -81,6 +81,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Discounts.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/queries/emailTemplates/emailTemplates.test.js b/tests/integration/api/queries/emailTemplates/emailTemplates.test.js index b1d8d710c41..4c0ec681971 100644 --- a/tests/integration/api/queries/emailTemplates/emailTemplates.test.js +++ b/tests/integration/api/queries/emailTemplates/emailTemplates.test.js @@ -99,6 +99,8 @@ beforeAll(async () => { }); afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Templates.deleteMany({}); await testApp.collections.Accounts.deleteMany({}); await testApp.collections.Shops.deleteMany({}); diff --git a/tests/integration/api/queries/getFlatRateFulfillmentRestriction/getFlatRateFulfillmentRestriction.test.js b/tests/integration/api/queries/getFlatRateFulfillmentRestriction/getFlatRateFulfillmentRestriction.test.js index b358ff0b2ee..ecb734c3c6a 100644 --- a/tests/integration/api/queries/getFlatRateFulfillmentRestriction/getFlatRateFulfillmentRestriction.test.js +++ b/tests/integration/api/queries/getFlatRateFulfillmentRestriction/getFlatRateFulfillmentRestriction.test.js @@ -29,7 +29,7 @@ const mockFulfillmentRestriction = { } }; -const mockOwenrAccount = Factory.Account.makeOne({ +const mockOwnerAccount = Factory.Account.makeOne({ roles: { [internalShopId]: ["owner"] }, @@ -43,12 +43,13 @@ beforeAll(async () => { await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); await testApp.collections.FlatRateFulfillmentRestrictions.insertOne(mockFulfillmentRestriction); - await testApp.createUserAndAccount(mockOwenrAccount); + await testApp.createUserAndAccount(mockOwnerAccount); getFlatRateFulfillmentRestriction = testApp.query(FlatRateFulfillmentRestrictionQuery); }); afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.FlatRateFulfillmentRestrictions.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); @@ -56,7 +57,7 @@ afterAll(async () => { test("a shop owner can query for a flat rate fulfillment restriction", async () => { let result; - await testApp.setLoggedInUser(mockOwenrAccount); + await testApp.setLoggedInUser(mockOwnerAccount); try { result = await getFlatRateFulfillmentRestriction({ diff --git a/tests/integration/api/queries/getFlatRateFulfillmentRestrictions/getFlatRateFulfillmentRestrictions.test.js b/tests/integration/api/queries/getFlatRateFulfillmentRestrictions/getFlatRateFulfillmentRestrictions.test.js index 709ffd7f47e..b508ed96861 100644 --- a/tests/integration/api/queries/getFlatRateFulfillmentRestrictions/getFlatRateFulfillmentRestrictions.test.js +++ b/tests/integration/api/queries/getFlatRateFulfillmentRestrictions/getFlatRateFulfillmentRestrictions.test.js @@ -47,6 +47,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.FlatRateFulfillmentRestrictions.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/queries/group/group.test.js b/tests/integration/api/queries/group/group.test.js index af1a26180ee..e80fc04d788 100644 --- a/tests/integration/api/queries/group/group.test.js +++ b/tests/integration/api/queries/group/group.test.js @@ -66,7 +66,14 @@ beforeAll(async () => { groupQuery = testApp.query(GroupFullQuery); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Groups.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + + testApp.stop(); +}); test("unauthenticated", async () => { try { diff --git a/tests/integration/api/queries/groups/groups.test.js b/tests/integration/api/queries/groups/groups.test.js index c8ccc28f872..8ad03aa8edf 100644 --- a/tests/integration/api/queries/groups/groups.test.js +++ b/tests/integration/api/queries/groups/groups.test.js @@ -68,7 +68,13 @@ beforeAll(async () => { groupsQuery = testApp.query(GroupsFullQuery); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Groups.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("unauthenticated", async () => { try { diff --git a/tests/integration/api/queries/navigation/navigationItemsByShopId.test.js b/tests/integration/api/queries/navigation/navigationItemsByShopId.test.js index 47f0df14708..119b79742d8 100644 --- a/tests/integration/api/queries/navigation/navigationItemsByShopId.test.js +++ b/tests/integration/api/queries/navigation/navigationItemsByShopId.test.js @@ -86,6 +86,8 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.NavigationItems.deleteMany({}); + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/navigation/navigationTreeById.test.js b/tests/integration/api/queries/navigation/navigationTreeById.test.js index 840f6d499fa..35f050030ca 100644 --- a/tests/integration/api/queries/navigation/navigationTreeById.test.js +++ b/tests/integration/api/queries/navigation/navigationTreeById.test.js @@ -259,6 +259,8 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.NavigationItems.deleteMany({}); await testApp.collections.NavigationTrees.deleteMany({}); + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/orderById/orderById.test.js b/tests/integration/api/queries/orderById/orderById.test.js index e79ceb0d86c..a823dcff955 100644 --- a/tests/integration/api/queries/orderById/orderById.test.js +++ b/tests/integration/api/queries/orderById/orderById.test.js @@ -68,7 +68,12 @@ beforeEach(async () => { await testApp.collections.Orders.deleteMany({}); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("get account order success", async () => { await testApp.collections.Orders.insertOne(order); diff --git a/tests/integration/api/queries/ordersByAccountId/ordersByAccountId.test.js b/tests/integration/api/queries/ordersByAccountId/ordersByAccountId.test.js index 5821a54f31c..c86330adc9b 100644 --- a/tests/integration/api/queries/ordersByAccountId/ordersByAccountId.test.js +++ b/tests/integration/api/queries/ordersByAccountId/ordersByAccountId.test.js @@ -144,6 +144,7 @@ beforeEach(async () => { afterAll(async () => { await testApp.collections.Orders.deleteMany({}); await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/paymentMethods/paymentMethods.test.js b/tests/integration/api/queries/paymentMethods/paymentMethods.test.js index 4c0c161aa2a..64ef3882d15 100644 --- a/tests/integration/api/queries/paymentMethods/paymentMethods.test.js +++ b/tests/integration/api/queries/paymentMethods/paymentMethods.test.js @@ -32,6 +32,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.collections.Packages.deleteMany({}); await testApp.stop(); diff --git a/tests/integration/api/queries/primaryShop/primaryShop.test.js b/tests/integration/api/queries/primaryShop/primaryShop.test.js index ae9e576795b..121e98b5d7d 100644 --- a/tests/integration/api/queries/primaryShop/primaryShop.test.js +++ b/tests/integration/api/queries/primaryShop/primaryShop.test.js @@ -19,7 +19,12 @@ beforeAll(async () => { }`); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("get primaryShop, no auth necessary", async () => { const result = await primaryShopQuery(); diff --git a/tests/integration/api/queries/primaryShopId/primaryShopId.test.js b/tests/integration/api/queries/primaryShopId/primaryShopId.test.js index 2e2dc0b86b3..37675e0e465 100644 --- a/tests/integration/api/queries/primaryShopId/primaryShopId.test.js +++ b/tests/integration/api/queries/primaryShopId/primaryShopId.test.js @@ -17,7 +17,10 @@ beforeAll(async () => { }`); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("get primaryShopId, no auth necessary", async () => { const result = await primaryShopIdQuery(); diff --git a/tests/integration/api/queries/productsByTagId/productsByTagId.test.js b/tests/integration/api/queries/productsByTagId/productsByTagId.test.js index 1f0cae56854..fc20873d631 100644 --- a/tests/integration/api/queries/productsByTagId/productsByTagId.test.js +++ b/tests/integration/api/queries/productsByTagId/productsByTagId.test.js @@ -61,7 +61,9 @@ beforeAll(async () => { }); afterAll(async () => { - await testApp.collections.Shops.deleteOne({ _id: internalShopId }); + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); await testApp.collections.Tags.deleteOne({ _id: mockTagWithFeatured._id }); await Promise.all(mockProductsWithTagAndFeaturedProducts.map((mockProduct) => testApp.collections.Products.deleteOne({ _id: mockProduct._id }))); await testApp.clearLoggedInUser(); diff --git a/tests/integration/api/queries/roles/roles.test.js b/tests/integration/api/queries/roles/roles.test.js index fff82d6854b..c87b8bafdcb 100644 --- a/tests/integration/api/queries/roles/roles.test.js +++ b/tests/integration/api/queries/roles/roles.test.js @@ -32,6 +32,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/shop/shop.test.js b/tests/integration/api/queries/shop/shop.test.js index d536b45bbec..93e136eac61 100644 --- a/tests/integration/api/queries/shop/shop.test.js +++ b/tests/integration/api/queries/shop/shop.test.js @@ -24,7 +24,10 @@ beforeAll(async () => { }`); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("get shop, no auth necessary", async () => { const opaqueShopId = encodeOpaqueId("reaction/shop", shopId); diff --git a/tests/integration/api/queries/shopSettings/shopSettings.test.js b/tests/integration/api/queries/shopSettings/shopSettings.test.js index bfa56d8a1c2..5bd05e152c0 100644 --- a/tests/integration/api/queries/shopSettings/shopSettings.test.js +++ b/tests/integration/api/queries/shopSettings/shopSettings.test.js @@ -38,8 +38,9 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); - await testApp.collections.AppSettings.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); + await testApp.collections.AppSettings.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/simpleInventory/simpleInventory.test.js b/tests/integration/api/queries/simpleInventory/simpleInventory.test.js index c8b61ba94f1..3aea4aa7ebf 100644 --- a/tests/integration/api/queries/simpleInventory/simpleInventory.test.js +++ b/tests/integration/api/queries/simpleInventory/simpleInventory.test.js @@ -93,6 +93,8 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Products.deleteMany({}); + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); diff --git a/tests/integration/api/queries/tags/tag.test.js b/tests/integration/api/queries/tags/tag.test.js index db212de32e8..d71c87266e5 100644 --- a/tests/integration/api/queries/tags/tag.test.js +++ b/tests/integration/api/queries/tags/tag.test.js @@ -50,6 +50,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.collections.Tags.deleteMany({}); await testApp.clearLoggedInUser(); diff --git a/tests/integration/api/queries/tags/tags.test.js b/tests/integration/api/queries/tags/tags.test.js index bfff02c9ed9..eede75c8786 100644 --- a/tests/integration/api/queries/tags/tags.test.js +++ b/tests/integration/api/queries/tags/tags.test.js @@ -45,7 +45,11 @@ beforeAll(async () => { await Promise.all(mockTags.map((tag) => testApp.collections.Tags.insertOne(tag))); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Tags.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + testApp.stop(); +}); test("get the first 20 tags when neither first or last is in query", async () => { let result; diff --git a/tests/integration/api/queries/taxRates/taxRates.test.js b/tests/integration/api/queries/taxRates/taxRates.test.js index ca0b292a380..ddb9ef427b0 100644 --- a/tests/integration/api/queries/taxRates/taxRates.test.js +++ b/tests/integration/api/queries/taxRates/taxRates.test.js @@ -60,6 +60,8 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Taxes.deleteMany({}); + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); await testApp.stop(); }); From d60dc26fed2ce36a533c9d06f4fa8193e0e0d8ee Mon Sep 17 00:00:00 2001 From: trojanh Date: Thu, 12 Dec 2019 20:54:38 +0530 Subject: [PATCH 3/3] test: include async await for afterAll stops methods Signed-off-by: trojanh --- .../api/queries/account/account.test.js | 2 +- .../api/queries/group/group.test.js | 2 +- .../api/queries/groups/groups.test.js | 2 +- .../api/queries/orderById/orderById.test.js | 2 +- .../integration/api/queries/ping/ping.test.js | 4 +- .../queries/primaryShop/primaryShop.test.js | 2 +- .../primaryShopId/primaryShopId.test.js | 2 +- .../integration/api/queries/shop/shop.test.js | 2 +- .../integration/api/queries/tags/tags.test.js | 2 +- .../api/queries/viewer/viewer.test.js | 4 +- tests/mocks/mockCatalogItems.js | 90 +++ tests/mocks/mockCatalogProducts.js | 715 ++++++++++++++++++ tests/mocks/mockShop.js | 8 + tests/mocks/mockTags.js | 7 + 14 files changed, 834 insertions(+), 10 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/account/account.test.js b/tests/integration/api/queries/account/account.test.js index 7c9d24ffdb1..91d69f51084 100644 --- a/tests/integration/api/queries/account/account.test.js +++ b/tests/integration/api/queries/account/account.test.js @@ -42,7 +42,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); await testApp.collections.users.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("unauthenticated", async () => { diff --git a/tests/integration/api/queries/group/group.test.js b/tests/integration/api/queries/group/group.test.js index e80fc04d788..5d11762a084 100644 --- a/tests/integration/api/queries/group/group.test.js +++ b/tests/integration/api/queries/group/group.test.js @@ -72,7 +72,7 @@ afterAll(async () => { await testApp.collections.Groups.deleteMany({}); await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("unauthenticated", async () => { diff --git a/tests/integration/api/queries/groups/groups.test.js b/tests/integration/api/queries/groups/groups.test.js index 8ad03aa8edf..d499a1181d4 100644 --- a/tests/integration/api/queries/groups/groups.test.js +++ b/tests/integration/api/queries/groups/groups.test.js @@ -73,7 +73,7 @@ afterAll(async () => { await testApp.collections.users.deleteMany({}); await testApp.collections.Groups.deleteMany({}); await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("unauthenticated", async () => { diff --git a/tests/integration/api/queries/orderById/orderById.test.js b/tests/integration/api/queries/orderById/orderById.test.js index a823dcff955..87cf14bef0c 100644 --- a/tests/integration/api/queries/orderById/orderById.test.js +++ b/tests/integration/api/queries/orderById/orderById.test.js @@ -72,7 +72,7 @@ afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("get account order success", async () => { diff --git a/tests/integration/api/queries/ping/ping.test.js b/tests/integration/api/queries/ping/ping.test.js index 2ec31eb090e..45a082974a1 100644 --- a/tests/integration/api/queries/ping/ping.test.js +++ b/tests/integration/api/queries/ping/ping.test.js @@ -13,7 +13,9 @@ beforeAll(async () => { }`); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.stop(); +}); test("simple test ping", async () => { const result = await pingQuery(); diff --git a/tests/integration/api/queries/primaryShop/primaryShop.test.js b/tests/integration/api/queries/primaryShop/primaryShop.test.js index 121e98b5d7d..e5f2ffe9467 100644 --- a/tests/integration/api/queries/primaryShop/primaryShop.test.js +++ b/tests/integration/api/queries/primaryShop/primaryShop.test.js @@ -23,7 +23,7 @@ afterAll(async () => { await testApp.collections.Accounts.deleteMany({}); await testApp.collections.users.deleteMany({}); await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("get primaryShop, no auth necessary", async () => { diff --git a/tests/integration/api/queries/primaryShopId/primaryShopId.test.js b/tests/integration/api/queries/primaryShopId/primaryShopId.test.js index 37675e0e465..d1ecd5f8245 100644 --- a/tests/integration/api/queries/primaryShopId/primaryShopId.test.js +++ b/tests/integration/api/queries/primaryShopId/primaryShopId.test.js @@ -19,7 +19,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("get primaryShopId, no auth necessary", async () => { diff --git a/tests/integration/api/queries/shop/shop.test.js b/tests/integration/api/queries/shop/shop.test.js index 93e136eac61..fc07b849c86 100644 --- a/tests/integration/api/queries/shop/shop.test.js +++ b/tests/integration/api/queries/shop/shop.test.js @@ -26,7 +26,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("get shop, no auth necessary", async () => { diff --git a/tests/integration/api/queries/tags/tags.test.js b/tests/integration/api/queries/tags/tags.test.js index eede75c8786..66f2c8b9a69 100644 --- a/tests/integration/api/queries/tags/tags.test.js +++ b/tests/integration/api/queries/tags/tags.test.js @@ -48,7 +48,7 @@ beforeAll(async () => { afterAll(async () => { await testApp.collections.Tags.deleteMany({}); await testApp.collections.Shops.deleteMany({}); - testApp.stop(); + await testApp.stop(); }); test("get the first 20 tags when neither first or last is in query", async () => { diff --git a/tests/integration/api/queries/viewer/viewer.test.js b/tests/integration/api/queries/viewer/viewer.test.js index 5107364915b..469dbe029c1 100644 --- a/tests/integration/api/queries/viewer/viewer.test.js +++ b/tests/integration/api/queries/viewer/viewer.test.js @@ -15,7 +15,9 @@ beforeAll(async () => { viewerQuery = testApp.query(ViewerFullQuery); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.stop(); +}); test("unauthenticated", async () => { const result = await viewerQuery(); 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