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
7 changes: 7 additions & 0 deletions tests/integration/api/queries/taxCodes/TaxCodesQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

query ($shopId: ID!) {
taxCodes(shopId: $shopId){
code
label
}
}
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 codes 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 [
"taxCodes",
],
},
]
`;
72 changes: 72 additions & 0 deletions tests/integration/api/queries/taxCodes/taxCodes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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 TaxCodesQuery = importAsString("./TaxCodesQuery.graphql");

jest.setTimeout(300000);

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

const mockGlobalSetting = {
shopId,
primaryTaxServiceName: "custom-rates"
};

const mockAdminAccount = Factory.Account.makeOne({
roles: {
[shopId]: ["owner"]
},
shopId
});

beforeAll(async () => {
testApp = new TestApp();

await testApp.start();
await testApp.insertPrimaryShop({ _id: shopId, name: shopName });
await testApp.createUserAndAccount(mockAdminAccount);
await testApp.collections.AppSettings.insertOne(mockGlobalSetting);

taxCodes = testApp.query(TaxCodesQuery);
});

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

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

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

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

expect(result.taxCodes[0].code).toEqual("RC_TAX");
expect(result.taxCodes[0].label).toEqual("Taxable (RC_TAX)");
});