From a35b6bcae6d1f6db7f1cdd7cd4cae6aa0f295e60 Mon Sep 17 00:00:00 2001 From: Will Lopez Date: Thu, 12 Dec 2019 11:22:53 -0600 Subject: [PATCH] chore: add systemInformation query integration test Signed-off-by: Will Lopez --- .../SystemInformationQuery.graphql | 10 +++ .../systemInformation.test.js.snap | 28 ++++++++ .../systemInformation.test.js | 65 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/integration/api/queries/systemInformation/SystemInformationQuery.graphql create mode 100644 tests/integration/api/queries/systemInformation/__snapshots__/systemInformation.test.js.snap create mode 100644 tests/integration/api/queries/systemInformation/systemInformation.test.js diff --git a/tests/integration/api/queries/systemInformation/SystemInformationQuery.graphql b/tests/integration/api/queries/systemInformation/SystemInformationQuery.graphql new file mode 100644 index 00000000000..7bfa64ccbb1 --- /dev/null +++ b/tests/integration/api/queries/systemInformation/SystemInformationQuery.graphql @@ -0,0 +1,10 @@ + +query ($shopId: ID!) { + systemInformation(shopId: $shopId){ + apiVersion + plugins { + name + version + } + } +} diff --git a/tests/integration/api/queries/systemInformation/__snapshots__/systemInformation.test.js.snap b/tests/integration/api/queries/systemInformation/__snapshots__/systemInformation.test.js.snap new file mode 100644 index 00000000000..b1e34bac11a --- /dev/null +++ b/tests/integration/api/queries/systemInformation/__snapshots__/systemInformation.test.js.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`an anonymous user should no be able to view system information 1`] = ` +Array [ + Object { + "extensions": Object { + "code": "FORBIDDEN", + "exception": Object { + "details": Object {}, + "error": "access-denied", + "eventData": Object {}, + "isClientSafe": true, + "reason": "Access Denied", + }, + }, + "locations": Array [ + Object { + "column": 3, + "line": 2, + }, + ], + "message": "Access Denied", + "path": Array [ + "systemInformation", + ], + }, +] +`; diff --git a/tests/integration/api/queries/systemInformation/systemInformation.test.js b/tests/integration/api/queries/systemInformation/systemInformation.test.js new file mode 100644 index 00000000000..bdc0ad39ef7 --- /dev/null +++ b/tests/integration/api/queries/systemInformation/systemInformation.test.js @@ -0,0 +1,65 @@ +import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; +import importAsString from "@reactioncommerce/api-utils/importAsString.js"; +import Factory from "/tests/util/factory.js"; +import TestApp from "/tests/util/TestApp.js"; + +const SystemInformationQuery = importAsString("./SystemInformationQuery.graphql"); + +jest.setTimeout(300000); + +const internalShopId = "123"; +const opaqueShopId = encodeOpaqueId("reaction/shop", internalShopId); // reaction/shop:123 +const shopName = "Test Shop"; +let testApp; +let systemInformation; + +const mockAdminAccount = Factory.Account.makeOne({ + roles: { + [internalShopId]: ["admin"] + }, + shopId: internalShopId +}); + +beforeAll(async () => { + testApp = new TestApp(); + await testApp.start(); + + await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName }); + await testApp.createUserAndAccount(mockAdminAccount); + systemInformation = testApp.query(SystemInformationQuery); +}); + +afterAll(async () => { + await testApp.collections.Accounts.deleteMany({}); + await testApp.collections.Shops.deleteMany({}); + await testApp.stop(); +}); + +test("an anonymous user should no be able to view system information", async () => { + try { + await systemInformation({ + shopId: opaqueShopId + }); + } catch (error) { + expect(error).toMatchSnapshot(); + return; + } +}); + +test("an admin user should be able to view system information", async () => { + let result; + await testApp.setLoggedInUser(mockAdminAccount); + + try { + result = await systemInformation({ + shopId: opaqueShopId + }); + } catch (error) { + expect(error).toBeUndefined(); + return; + } + + expect(result.systemInformation.apiVersion).toEqual("0.0.0-test"); + expect(result.systemInformation.plugins[0].name).toEqual("reaction-email"); + expect(result.systemInformation.plugins[0].version).toEqual("1.0.0"); +});