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,7 @@

query ($shopId: ID!) {
taxServices(shopId: $shopId){
name
pluginName
}
}
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 cannot view tax services 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 [
"taxServices",
],
},
]
`;
65 changes: 65 additions & 0 deletions tests/integration/api/queries/taxServices/taxServices.test.js
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 TaxServicesQuery = importAsString("./TaxServicesQuery.graphql");

jest.setTimeout(300000);

const internalShopId = "123";
const opaqueShopId = encodeOpaqueId("reaction/shop", internalShopId); // reaction/shop:123
const shopName = "Test Shop";
let testApp;
let taxServices;

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);

taxServices = testApp.query(TaxServicesQuery);
});

afterAll(async () => {
await testApp.collections.Accounts.deleteMany({});
await testApp.collections.Shops.deleteMany({});
await testApp.stop();
});

test("an anonymous user cannot view tax services", async () => {
try {
await taxServices({
shopId: opaqueShopId
});
} catch (error) {
expect(error).toMatchSnapshot();
return;
}
});

test("an admin user can view tax services", async () => {
let result;
await testApp.setLoggedInUser(mockAdminAccount);

try {
result = await taxServices({
shopId: opaqueShopId
});
} catch (error) {
expect(error).toBeUndefined();
return;
}

expect(result.taxServices[0].name).toEqual("custom-rates");
expect(result.taxServices[0].pluginName).toEqual("reaction-taxes-rates");
});