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): remove meteor-collection-hooks dependency for orders #3639

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion imports/plugins/core/orders/server/startup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Meteor } from "meteor/meteor";
import { Hooks } from "/server/api";
import { AnalyticsEvents, Orders } from "/lib/collections";


Orders.before.insert((userId, order) => {
Hooks.Events.add("afterOrderInsert", (order) => {
const analyticsEvent = {
eventType: "buy",
value: order._id,
label: "bought products"
};
AnalyticsEvents.insert(analyticsEvent);

return order;
});

/**
Expand Down
3 changes: 0 additions & 3 deletions server/imports/fixtures/fixtures.app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ describe("Fixtures:", function () {
});

it("Order fixture should create an order", function () {
// Order has analytics hooks on it that need to be turned off
sandbox.stub(Collections.Orders._hookAspects.insert.before[0], "aspect");
sandbox.stub(Collections.Orders._hookAspects.update.before[0], "aspect");
sandbox.stub(Reaction, "hasPermission", () => true);
sandbox.stub(Meteor.server.method_handlers, "inventory/register", function () {
check(arguments, [Match.Any]);
Expand Down
3 changes: 2 additions & 1 deletion server/methods/core/cartToOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Meteor } from "meteor/meteor";
import { check } from "meteor/check";
import { Roles } from "meteor/alanning:roles";
import * as Collections from "/lib/collections";
import { Logger, Reaction } from "/server/api";
import { Hooks, Logger, Reaction } from "/server/api";


/**
Expand Down Expand Up @@ -171,6 +171,7 @@ export function copyCartToOrder(cartId) {

// insert new reaction order
const orderId = Collections.Orders.insert(order);
Hooks.Events.run("afterOrderInsert", order);

if (orderId) {
Collections.Cart.remove({
Expand Down
3 changes: 0 additions & 3 deletions server/methods/core/orders.app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ describe("orders test", function () {

beforeEach(function (done) {
sandbox = sinon.sandbox.create();
// });
sandbox.stub(Orders._hookAspects.insert.before[0], "aspect");
sandbox.stub(Orders._hookAspects.update.before[0], "aspect");
sandbox.stub(Meteor.server.method_handlers, "inventory/register", function () {
check(arguments, [Match.Any]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ describe("Order Publication", function () {

describe("Orders", () => {
it("should return shop orders for an admin", function (done) {
sandbox.stub(Collections.Orders._hookAspects.insert.before[0], "aspect");
sandbox.stub(Collections.Orders._hookAspects.update.before[0], "aspect");
sandbox.stub(Reaction, "hasPermission", () => true);
sandbox.stub(Meteor.server.method_handlers, "inventory/register", function () {
check(arguments, [Match.Any]);
Expand All @@ -72,8 +70,6 @@ describe("Order Publication", function () {
});

it("should not return shop orders for a non-admin", function (done) {
sandbox.stub(Collections.Orders._hookAspects.insert.before[0], "aspect");
sandbox.stub(Collections.Orders._hookAspects.update.before[0], "aspect");
sandbox.stub(Reaction, "hasPermission", () => true);
sandbox.stub(Meteor.server.method_handlers, "inventory/register", function () {
check(arguments, [Match.Any]);
Expand Down