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
4 changes: 2 additions & 2 deletions src/plugins/surcharges/util/surchargeSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Message = new SimpleSchema({
language: String
});

const surchargeSchema = new SimpleSchema({
export const Surcharge = new SimpleSchema({
"amount": {
type: Number
},
Expand Down Expand Up @@ -98,4 +98,4 @@ const surchargeSchema = new SimpleSchema({
}
});

export default surchargeSchema;
export default Surcharge;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

query ($shopId: ID!, $surchargeId: ID!){
surchargeById(shopId: $shopId, surchargeId: $surchargeId){
amount {
amount
}
}
}
54 changes: 54 additions & 0 deletions tests/integration/api/queries/surchargeById/surchargeById.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 SurchargeByIdQuery = importAsString("./SurchargeByIdQuery.graphql");

jest.setTimeout(300000);

const internalShopId = "123";
const internalSurchargeId = "456";
const opaqueShopId = encodeOpaqueId("reaction/shop", internalShopId); // reaction/shop:123
const opaqueSurchargeId = encodeOpaqueId("reaction/surcharge", internalSurchargeId); // reaction/surcharge:456
const shopName = "Test Shop";
let testApp;
let surchargeById;

const mockSurcharge = Factory.Surcharge.makeOne({
_id: internalSurchargeId,
shopId: internalShopId,
amount: 20
});

beforeAll(async () => {
testApp = new TestApp();
await testApp.start();

await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName });
await testApp.collections.Surcharges.insertOne(mockSurcharge);
surchargeById = testApp.query(SurchargeByIdQuery);
});

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

test("retrieve a surcharge by its id", async () => {
let result;

try {
result = await surchargeById({
shopId: opaqueShopId,
surchargeId: opaqueSurchargeId
});
} catch (error) {
expect(error).toBeUndefined();
return;
}

expect(result.surchargeById.amount.amount).toEqual(20);
});
10 changes: 10 additions & 0 deletions tests/integration/api/queries/surcharges/SurchargesQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

query ($shopId: ID!, $first: ConnectionLimitInt){
surcharges(shopId: $shopId, first: $first){
nodes {
amount {
amount
}
}
}
}
52 changes: 52 additions & 0 deletions tests/integration/api/queries/surcharges/surcharges.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 SurchargesQuery = importAsString("./SurchargesQuery.graphql");

jest.setTimeout(300000);

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

beforeAll(async () => {
testApp = new TestApp();
await testApp.start();

await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName });
mockSurcharges = Factory.Surcharge.makeMany(3, {
shopId: internalShopId,
amount: 10
});
await testApp.collections.Surcharges.insertMany(mockSurcharges);
surcharges = testApp.query(SurchargesQuery);
});

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

test("retrieve a list of surcharges", async () => {
let result;

try {
result = await surcharges({
shopId: opaqueShopId,
first: 3
});
} catch (error) {
expect(error).toBeUndefined();
return;
}

expect(result.surcharges.nodes[0].amount.amount).toEqual(10);
expect(result.surcharges.nodes.length).toEqual(3);
});
5 changes: 5 additions & 0 deletions tests/util/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ import {
Shop
} from "../../src/core-services/shop/simpleSchemas.js";

import {
Surcharge
} from "../../src/plugins/surcharges/util/surchargeSchema.js";

import {
Tag
} from "../../src/core-services/tags/simpleSchemas.js";
Expand Down Expand Up @@ -107,6 +111,7 @@ const schemasToAddToFactory = {
ProductVariant,
ShipmentQuote,
Shop,
Surcharge,
Tag,
TaxRates
};
Expand Down