Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move shipping and surcharges from server/no-meteor to node-app #5632

Merged
merged 20 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f92872
refactor: move surcharges files from `no-meteor` to `node-app`
kieckhafer Sep 30, 2019
8697e05
refactor: more shipping package from `no-meteor` to `node-app`
kieckhafer Sep 30, 2019
483a801
refactor: move `shipping` into `core-services` instead of `plugins`
kieckhafer Sep 30, 2019
4e6850a
Merge remote-tracking branch 'origin/develop' into refactor-kieckhafe…
kieckhafer Sep 30, 2019
75af3b3
refactor: use new getCommonOrderForCartGroup instead of xformCartGrou…
kieckhafer Sep 30, 2019
d3d8462
Merge branch 'develop' into refactor-kieckhafer-movePackageToNodeApp-…
kieckhafer Sep 30, 2019
a5d045a
refactor: add alias for temporary import of new api-utils (remove onc…
kieckhafer Sep 30, 2019
f277323
refactor: move shipping into registerPlugins node-app area
kieckhafer Sep 30, 2019
f92bdd6
feat: add CommonOrder to Graphql schema
kieckhafer Sep 30, 2019
592d73d
refactor: fix import paths for moved files
kieckhafer Sep 30, 2019
32aea13
refactor: update getCommonOrderForCartGroup to pass in full cart and …
kieckhafer Sep 30, 2019
f6a233c
fix: import shipping from core-services, not plugins
kieckhafer Oct 1, 2019
a2c71ef
tests: add mockCollection and mockContext test utils
kieckhafer Oct 1, 2019
d38ff75
refactor: revert xformCommGroupToCommonORder removal
kieckhafer Oct 1, 2019
ca49505
chore: update package-lock.json
kieckhafer Oct 1, 2019
4eb6cc3
tests:add new code to tests
kieckhafer Oct 1, 2019
377174b
refactor: remove query from resolver
kieckhafer Oct 1, 2019
ba89486
refactor: update error messaging
kieckhafer Oct 1, 2019
3b17964
refactor: remove unused CommonOrder schema
kieckhafer Oct 1, 2019
56c63f6
Merge branch 'develop' into refactor-kieckhafer-movePackageToNodeApp-…
kieckhafer Oct 1, 2019
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
@@ -1,8 +1,8 @@
import i18n from "./i18n";
import mutations from "./mutations";
import queries from "./queries";
import resolvers from "./resolvers";
import schemas from "./schemas";
import i18n from "./i18n/index.js";
import mutations from "./mutations/index.js";
import queries from "./queries/index.js";
import resolvers from "./resolvers/index.js";
import schemas from "./schemas/index.js";

/**
* @summary Import and call this function to add this plugin to your API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup";
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup.js";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup.js";

export default {
selectFulfillmentOptionForGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import getCartById from "../util/getCartById";
import getCartById from "../util/getCartById.js";

const inputSchema = new SimpleSchema({
cartId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mockContext from "/imports/test-utils/helpers/mockContext";
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup.js";

jest.mock("../util/getCartById", () => jest.fn().mockImplementation(() => Promise.resolve({
_id: "cartId",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isEqual } from "lodash";
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import xformCartGroupToCommonOrder from "/imports/plugins/core/cart/server/no-meteor/util/xformCartGroupToCommonOrder";
import getCartById from "../util/getCartById";
import getCartById from "../util/getCartById.js";

const inputSchema = new SimpleSchema({
cartId: String,
Expand Down Expand Up @@ -71,7 +70,7 @@ export default async function updateFulfillmentOptionsForGroup(context, input) {
const fulfillmentGroup = (cart.shipping || []).find((group) => group._id === fulfillmentGroupId);
if (!fulfillmentGroup) throw new ReactionError("not-found", `Fulfillment group with ID ${fulfillmentGroupId} not found in cart with ID ${cartId}`);

const commonOrder = await xformCartGroupToCommonOrder(cart, fulfillmentGroup, context);
const commonOrder = await context.queries.getCommonOrderForCartGroup(context, { cartId: cart._id, fulfillmentGroupId: fulfillmentGroup._id });

// In the future we want to do this async and subscribe to the results
const rates = await context.queries.getFulfillmentMethodsWithQuotes(commonOrder, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Factory from "/imports/test-utils/helpers/factory";
import mockContext from "/imports/test-utils/helpers/mockContext";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup";
import Factory from "/imports/test-utils/helpers/factory.js";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup.js";

jest.mock("../util/getCartById", () => jest.fn().mockImplementation(() => Promise.resolve({
_id: "cartId",
Expand All @@ -26,10 +26,12 @@ jest.mock("../util/getCartById", () => jest.fn().mockImplementation(() => Promis
const fakeCart = Factory.Cart.makeOne();
const fakeQuote = Factory.ShipmentQuote.makeOne();
const mockGetFulfillmentMethodsWithQuotes = jest.fn().mockName("getFulfillmentMethodsWithQuotes");
const mockGetCommonOrderForCartGroup = jest.fn().mockName("getCommonOrderForCartGroup");

beforeAll(() => {
mockContext.queries = {
getFulfillmentMethodsWithQuotes: mockGetFulfillmentMethodsWithQuotes
getFulfillmentMethodsWithQuotes: mockGetFulfillmentMethodsWithQuotes,
getCommonOrderForCartGroup: mockGetCommonOrderForCartGroup
};
if (!mockContext.mutations.saveCart) {
mockContext.mutations.saveCart = jest.fn().mockName("context.mutations.saveCart").mockImplementation(async (_, cart) => cart);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Logger from "@reactioncommerce/logger";
import extendCommonOrder from "../util/extendCommonOrder";
import extendCommonOrder from "../util/extendCommonOrder.js";

/**
* @name getFulfillmentMethodsWithQuotes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getFulfillmentMethodsWithQuotes from "./getFulfillmentMethodsWithQuotes";
import getFulfillmentMethodsWithQuotes from "./getFulfillmentMethodsWithQuotes.js";

export default {
getFulfillmentMethodsWithQuotes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup";
import selectFulfillmentOptionForGroup from "./selectFulfillmentOptionForGroup.js";
import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup.js";

export default {
selectFulfillmentOptionForGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeCartOpaqueId, decodeFulfillmentGroupOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/cart";
import { decodeFulfillmentMethodOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/fulfillment";
import selectFulfillmentOptionForGroupMutation from "../../mutations/selectFulfillmentOptionForGroup";
import selectFulfillmentOptionForGroupMutation from "../../mutations/selectFulfillmentOptionForGroup.js";

/**
* @name Mutation/selectFulfillmentOptionForGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decodeCartOpaqueId, decodeFulfillmentGroupOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/cart";
import updateFulfillmentOptionsForGroupMutation from "../../mutations/updateFulfillmentOptionsForGroup";
import updateFulfillmentOptionsForGroupMutation from "../../mutations/updateFulfillmentOptionsForGroup.js";

/**
* @name Mutation/updateFulfillmentOptionsForGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FulfillmentMethod from "./FulfillmentMethod";
import Mutation from "./Mutation";
import FulfillmentMethod from "./FulfillmentMethod/index.js";
import Mutation from "./Mutation/index.js";

/**
* Fulfillment related GraphQL resolvers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "/imports/node-app/core/util/hashLoginToken";
import hashLoginToken from "../../../core/util/hashLoginToken";

/**
* @summary Gets a cart from the db by ID. If there is an account for the request, verifies that the
Expand Down
2 changes: 1 addition & 1 deletion imports/node-app/core/util/buildContext.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mockContext from "/imports/test-utils/helpers/mockContext";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import buildContext from "./buildContext";

const fakeUser = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Random from "@reactioncommerce/random";
import extendCommonOrder from "/imports/plugins/core/shipping/server/no-meteor/util/extendCommonOrder";
import { surchargeCheck } from "./util/surchargeCheck";
import extendCommonOrder from "/imports/node-app/core-services/shipping/util/extendCommonOrder"; // TODO: remove cross-plugin import (https://github.com/reactioncommerce/reaction/issues/5633)
import { surchargeCheck } from "./util/surchargeCheck.js";


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import getSurcharges from "./getSurcharges";
import mutations from "./mutations";
import queries from "./queries";
import resolvers from "./resolvers";
import schemas from "./schemas";
import setSurchargesOnCart from "./util/setSurchargesOnCart";
import getSurcharges from "./getSurcharges.js";
import mutations from "./mutations/index.js";
import queries from "./queries/index.js";
import resolvers from "./resolvers/index.js";
import schemas from "./schemas/index.js";
import setSurchargesOnCart from "./util/setSurchargesOnCart.js";

/**
* @summary Import and call this function to add this plugin to your API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SimpleSchema from "simpl-schema";
import Random from "@reactioncommerce/random";
import ReactionError from "@reactioncommerce/reaction-error";
import surchargeSchema from "../util/surchargeSchema";
import surchargeSchema from "../util/surchargeSchema.js";

const inputSchema = new SimpleSchema({
surcharge: surchargeSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mockContext, { mockCollection } from "/imports/test-utils/helpers/mockContext";
import createSurchargeMutation from "./createSurcharge";
import mockCollection from "@reactioncommerce/api-utils/tests/mockCollection.js";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import createSurchargeMutation from "./createSurcharge.js";


// Create mock context with Surcharges collection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mockContext, { mockCollection } from "/imports/test-utils/helpers/mockContext";
import deleteSurchargeMutation from "./deleteSurcharge";
import mockCollection from "@reactioncommerce/api-utils/tests/mockCollection.js";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import deleteSurchargeMutation from "./deleteSurcharge.js";


// Create mock context with Surcharges collection
Expand Down
9 changes: 9 additions & 0 deletions imports/node-app/plugins/surcharges/mutations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import createSurcharge from "./createSurcharge.js";
import deleteSurcharge from "./deleteSurcharge.js";
import updateSurcharge from "./updateSurcharge.js";

export default {
createSurcharge,
deleteSurcharge,
updateSurcharge
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import surchargeSchema from "../util/surchargeSchema";
import surchargeSchema from "../util/surchargeSchema.js";

const inputSchema = new SimpleSchema({
shopId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mockContext, { mockCollection } from "/imports/test-utils/helpers/mockContext";
import updateSurchargeMutation from "./updateSurcharge";
import mockCollection from "@reactioncommerce/api-utils/tests/mockCollection.js";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import updateSurchargeMutation from "./updateSurcharge.js";


// Create mock context with Surcharges collection
Expand Down
7 changes: 7 additions & 0 deletions imports/node-app/plugins/surcharges/queries/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import surchargeById from "./surchargeById.js";
import surcharges from "./surcharges.js";

export default {
surchargeById,
surcharges
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encodeSurchargeOpaqueId } from "../../xforms/surcharge";
import xformSurchargeAmount from "../../xforms/xformSurchargeAmount";
import getSurchargeMessageForLanguage from "../../util/getSurchargeMessageForLanguage";
import { encodeSurchargeOpaqueId } from "../../xforms/surcharge.js";
import xformSurchargeAmount from "../../xforms/xformSurchargeAmount.js";
import getSurchargeMessageForLanguage from "../../util/getSurchargeMessageForLanguage.js";

export default {
_id: (node) => encodeSurchargeOpaqueId(node._id),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeFulfillmentMethodOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/fulfillment";
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop";
import createSurchargeMutation from "../../mutations/createSurcharge";
import createSurchargeMutation from "../../mutations/createSurcharge.js";

/**
* @name Mutation/createSurcharge
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge";
import deleteSurchargeMutation from "../../mutations/deleteSurcharge";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge.js";
import deleteSurchargeMutation from "../../mutations/deleteSurcharge.js";

/**
* @name Mutation/deleteSurcharge
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import createSurcharge from "./createSurcharge.js";
import deleteSurcharge from "./deleteSurcharge.js";
import updateSurcharge from "./updateSurcharge.js";

export default {
createSurcharge,
deleteSurcharge,
updateSurcharge
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { decodeFulfillmentMethodOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/fulfillment";
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge";
import updateSurchargeMutation from "../../mutations/updateSurcharge";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge.js";
import updateSurchargeMutation from "../../mutations/updateSurcharge.js";

/**
* @name Mutation/updateSurcharge
Expand Down
7 changes: 7 additions & 0 deletions imports/node-app/plugins/surcharges/resolvers/Query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import surchargeById from "./surchargeById.js";
import surcharges from "./surcharges.js";

export default {
surchargeById,
surcharges
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge";
import { decodeSurchargeOpaqueId } from "../../xforms/surcharge.js";

/**
* @name Query/surchargeById
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { encodeFulfillmentMethodOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/fulfillment";
import { encodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop";
import { encodeSurchargeOpaqueId } from "../../xforms/surcharge";
import xformSurchargeAmount from "../../xforms/xformSurchargeAmount";
import getSurchargeMessageForLanguage from "../../util/getSurchargeMessageForLanguage";
import { encodeSurchargeOpaqueId } from "../../xforms/surcharge.js";
import xformSurchargeAmount from "../../xforms/xformSurchargeAmount.js";
import getSurchargeMessageForLanguage from "../../util/getSurchargeMessageForLanguage.js";

export default {
_id: (node) => encodeSurchargeOpaqueId(node._id),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getConnectionTypeResolvers } from "@reactioncommerce/reaction-graphql-utils";
import AppliedSurcharge from "./AppliedSurcharge";
import Surcharge from "./Surcharge";
import Mutation from "./Mutation";
import Query from "./Query";
import AppliedSurcharge from "./AppliedSurcharge/index.js";
import Surcharge from "./Surcharge/index.js";
import Mutation from "./Mutation/index.js";
import Query from "./Query/index.js";

export default {
...getConnectionTypeResolvers("Surcharge"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getSurcharges from "../getSurcharges";
import getSurcharges from "../getSurcharges.js";

/**
* @summary Cart transformation function that sets surcharges on cart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import operators from "/imports/utils/operators";
import propertyTypes from "/imports/utils/propertyTypes";
import operators from "@reactioncommerce/api-utils/operators.js";
import propertyTypes from "@reactioncommerce/api-utils/propertyTypes.js";

/**
* @summary Filter surcharges based on surcharge restriction data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { surchargeCheck } from "./surchargeCheck";
import mockContext, { mockCollection } from "/imports/test-utils/helpers/mockContext";
import mockCollection from "@reactioncommerce/api-utils/tests/mockCollection.js";
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js";
import { surchargeCheck } from "./surchargeCheck.js";

// Create mock context with Surcharges collection
mockContext.collections.Surcharges = mockCollection("Surcharges");
Expand Down
4 changes: 2 additions & 2 deletions imports/node-app/registerPlugins.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* node-app imports */
/* core-services */
import registerSettingsPlugin from "./core-services/settings/index.js";
import registerShippingPlugin from "./core-services/shipping/index.js";

/* plugins */
import registerAddressPlugin from "./plugins/address/index.js";
import registerSurchargesPlugin from "./plugins/surcharges/index.js";
import registerSystemInfoPlugin from "./plugins/system-info/index.js";
import registerTemplatesPlugin from "./plugins/templates/index.js";

Expand Down Expand Up @@ -31,15 +33,13 @@ import registerPaymentsPlugin from "/imports/plugins/core/payments/server/no-met
import registerProductPlugin from "/imports/plugins/core/product/server/no-meteor/register";
import registerProductVariantPlugin from "/imports/plugins/included/product-variant/server/no-meteor/register";
import registerProductAdminPlugin from "/imports/plugins/included/product-admin/server/no-meteor/register";
import registerShippingPlugin from "/imports/plugins/core/shipping/server/no-meteor/register";
import registerShippingRatesPlugin from "/imports/plugins/included/shipping-rates/server/no-meteor/register";
import registerShopPlugin from "/imports/plugins/core/shop/server/register";
import registerSimpleInventoryPlugin from "/imports/plugins/included/simple-inventory/server/no-meteor/register";
import registerSimplePricingPlugin from "/imports/plugins/included/simple-pricing/server/no-meteor/register";
import registerSitemapGeneratorPlugin from "/imports/plugins/included/sitemap-generator/server/no-meteor/register";
import registerSMTPEmailPlugin from "/imports/plugins/included/email-smtp/server/no-meteor/register";
import registerStripePaymentsPlugin from "/imports/plugins/included/payments-stripe/server/no-meteor/register";
import registerSurchargesPlugin from "/imports/plugins/included/surcharges/server/no-meteor/register";
import registerTagsPlugin from "/imports/plugins/core/tags/server/no-meteor/register";
import registerTaxesPlugin from "/imports/plugins/core/taxes/server/no-meteor/register";
import registerTaxesRatesPlugin from "/imports/plugins/included/taxes-rates/server/no-meteor/register";
Expand Down
Loading