Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

query ($shopId: ID!) {
systemInformation(shopId: $shopId){
apiVersion
plugins {
name
version
}
}
}
Original file line number Diff line number Diff line change
@@ -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",
],
},
]
`;
Original file line number Diff line number Diff line change
@@ -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");
});