From 3768b5e22161313d08d9a12ed9cbdb2a43c2d0ba Mon Sep 17 00:00:00 2001 From: Maria Paktiti Date: Wed, 9 Oct 2019 17:21:01 +0300 Subject: [PATCH 1/5] test: add integration tests for shopBySlug Signed-off-by: Maria Paktiti --- .../api/queries/shop/shopBySlug.test.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/integration/api/queries/shop/shopBySlug.test.js diff --git a/tests/integration/api/queries/shop/shopBySlug.test.js b/tests/integration/api/queries/shop/shopBySlug.test.js new file mode 100644 index 00000000000..358f1a37bc1 --- /dev/null +++ b/tests/integration/api/queries/shop/shopBySlug.test.js @@ -0,0 +1,33 @@ +import { encodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop"; +import TestApp from "/imports/test-utils/helpers/TestApp"; + +jest.setTimeout(300000); + +let shopBySlagQuery; +let shopId; +let testApp; +const shopSlug = "integ-test-shop-slug"; + +beforeAll(async () => { + testApp = new TestApp(); + await testApp.start(); + shopId = await testApp.insertPrimaryShop({ slug: shopSlug }); + shopBySlagQuery = testApp.query(`query ($slug: String!) { + shopBySlug(slug: $slug) { + _id + name + } + }`); +}); + +afterAll(async () => { + await testApp.collections.Shops.deleteMany({}); + await testApp.stop(); +}); + +test("get shop, no auth necessary", async () => { + const opaqueShopId = encodeShopOpaqueId(shopId); + const result = await shopBySlagQuery({ slug: shopSlug }); + expect(result.shopBySlug.name).toBe("Primary Shop"); + expect(result.shopBySlug._id).toBe(opaqueShopId); +}); From bafa45e3ab3835b72c8b4e096083cfff42d54cef Mon Sep 17 00:00:00 2001 From: Maria Paktiti Date: Wed, 9 Oct 2019 17:21:42 +0300 Subject: [PATCH 2/5] fix: cleanup and await DB stop Signed-off-by: Maria Paktiti --- tests/integration/api/queries/shop/shop.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/api/queries/shop/shop.test.js b/tests/integration/api/queries/shop/shop.test.js index 9fa75ab894e..2ec1b6c389c 100644 --- a/tests/integration/api/queries/shop/shop.test.js +++ b/tests/integration/api/queries/shop/shop.test.js @@ -27,7 +27,10 @@ beforeAll(async () => { }`); }); -afterAll(() => testApp.stop()); +afterAll(async () => { + await testApp.collections.Shops.deleteMany({}); + await testApp.stop(); +}); test("get shop, no auth necessary", async () => { const opaqueShopId = encodeShopOpaqueId(shopId); From aa631820d1d08158ab7bc3a687fd85045b215d0e Mon Sep 17 00:00:00 2001 From: Maria Paktiti Date: Wed, 9 Oct 2019 17:40:13 +0300 Subject: [PATCH 3/5] fix: add fail test and cleanup code Signed-off-by: Maria Paktiti --- .../api/queries/shop/shopBySlug.test.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/integration/api/queries/shop/shopBySlug.test.js b/tests/integration/api/queries/shop/shopBySlug.test.js index 358f1a37bc1..9f18f1abd71 100644 --- a/tests/integration/api/queries/shop/shopBySlug.test.js +++ b/tests/integration/api/queries/shop/shopBySlug.test.js @@ -5,13 +5,16 @@ jest.setTimeout(300000); let shopBySlagQuery; let shopId; +const shopName = "Slug Integration Test"; let testApp; +let opaqueShopId; const shopSlug = "integ-test-shop-slug"; beforeAll(async () => { testApp = new TestApp(); await testApp.start(); - shopId = await testApp.insertPrimaryShop({ slug: shopSlug }); + shopId = await testApp.insertPrimaryShop({ slug: shopSlug, name: shopName }); + opaqueShopId = encodeShopOpaqueId(shopId); shopBySlagQuery = testApp.query(`query ($slug: String!) { shopBySlug(slug: $slug) { _id @@ -25,9 +28,13 @@ afterAll(async () => { await testApp.stop(); }); -test("get shop, no auth necessary", async () => { - const opaqueShopId = encodeShopOpaqueId(shopId); +test("get shop by slug success", async () => { const result = await shopBySlagQuery({ slug: shopSlug }); - expect(result.shopBySlug.name).toBe("Primary Shop"); + expect(result.shopBySlug.name).toBe(shopName); expect(result.shopBySlug._id).toBe(opaqueShopId); }); + +test("get shop by slug failure", async () => { + const result = await shopBySlagQuery({ slug: "does-not-exist" }); + expect(result.shopBySlug).toBeNull(); +}); From 9d20c119ca9085dcde7e8b97c99ad127f8d95e6d Mon Sep 17 00:00:00 2001 From: Maria Paktiti Date: Wed, 9 Oct 2019 17:44:34 +0300 Subject: [PATCH 4/5] test: add invalid params test Signed-off-by: Maria Paktiti --- tests/integration/api/queries/shop/shopBySlug.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/api/queries/shop/shopBySlug.test.js b/tests/integration/api/queries/shop/shopBySlug.test.js index 9f18f1abd71..5d87379af42 100644 --- a/tests/integration/api/queries/shop/shopBySlug.test.js +++ b/tests/integration/api/queries/shop/shopBySlug.test.js @@ -38,3 +38,11 @@ test("get shop by slug failure", async () => { const result = await shopBySlagQuery({ slug: "does-not-exist" }); expect(result.shopBySlug).toBeNull(); }); + +test("get invalid params error", async () => { + try { + await shopBySlagQuery({}); + } catch (error) { + expect(error[0].message).toBe("Variable \"$slug\" of required type \"String!\" was not provided."); + } +}); From a436e32f91010381f3b5a38f651e84287e989789 Mon Sep 17 00:00:00 2001 From: Maria Paktiti Date: Thu, 10 Oct 2019 17:51:10 +0300 Subject: [PATCH 5/5] (fix) typo (slag -> slug) Signed-off-by: Maria Paktiti --- tests/integration/api/queries/shop/shopBySlug.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/api/queries/shop/shopBySlug.test.js b/tests/integration/api/queries/shop/shopBySlug.test.js index 5d87379af42..81a9e79eb89 100644 --- a/tests/integration/api/queries/shop/shopBySlug.test.js +++ b/tests/integration/api/queries/shop/shopBySlug.test.js @@ -3,7 +3,7 @@ import TestApp from "/imports/test-utils/helpers/TestApp"; jest.setTimeout(300000); -let shopBySlagQuery; +let shopBySlugQuery; let shopId; const shopName = "Slug Integration Test"; let testApp; @@ -15,7 +15,7 @@ beforeAll(async () => { await testApp.start(); shopId = await testApp.insertPrimaryShop({ slug: shopSlug, name: shopName }); opaqueShopId = encodeShopOpaqueId(shopId); - shopBySlagQuery = testApp.query(`query ($slug: String!) { + shopBySlugQuery = testApp.query(`query ($slug: String!) { shopBySlug(slug: $slug) { _id name @@ -29,19 +29,19 @@ afterAll(async () => { }); test("get shop by slug success", async () => { - const result = await shopBySlagQuery({ slug: shopSlug }); + const result = await shopBySlugQuery({ slug: shopSlug }); expect(result.shopBySlug.name).toBe(shopName); expect(result.shopBySlug._id).toBe(opaqueShopId); }); test("get shop by slug failure", async () => { - const result = await shopBySlagQuery({ slug: "does-not-exist" }); + const result = await shopBySlugQuery({ slug: "does-not-exist" }); expect(result.shopBySlug).toBeNull(); }); test("get invalid params error", async () => { try { - await shopBySlagQuery({}); + await shopBySlugQuery({}); } catch (error) { expect(error[0].message).toBe("Variable \"$slug\" of required type \"String!\" was not provided."); }