-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Adjust inventory on shipment #1240
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0ba077f
Trap order-completed change
brent-hoover 446ab91
Add missing import
brent-hoover f83293a
Merge branch 'development' into brent-adjust-inventory-on-shippment
brent-hoover b9ebb58
Merge branch 'development' into brent-adjust-inventory-on-shippment
brent-hoover 9d38116
Add cartItemId field to order so that we can modify inventory
brent-hoover e466f49
Add new "inventory/sold" method
brent-hoover c7c3131
Explicitly set from and to statuses
brent-hoover a42bd26
Handle order insert hook to move ordered inventory to "sold" status
brent-hoover ddca7d2
Handle moving inventory from "reserved" to "sold" status
brent-hoover 19156ec
Fix email import
brent-hoover 73f782c
Fix tests
brent-hoover 8ae2e64
Not so much logging
brent-hoover 34f8983
Call status change method with explicit values
brent-hoover eef767b
Add test for moving inventory from "reserved" to "sold"
brent-hoover edcc4b4
Add test for moving inventory from "sold" to "shipped"
brent-hoover 473fccd
Merge branch 'development' into brent-adjust-inventory-on-shippment
brent-hoover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
imports/plugins/included/inventory/server/startup/inventory-hooks.app-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* eslint dot-notation: 0 */ | ||
import { Meteor } from "meteor/meteor"; | ||
import { Inventory, Orders } from "/lib/collections"; | ||
import { Reaction } from "/server/api"; | ||
import { expect } from "meteor/practicalmeteor:chai"; | ||
import { sinon } from "meteor/practicalmeteor:sinon"; | ||
import Fixtures from "/server/imports/fixtures"; | ||
import { getShop } from "/server/imports/fixtures/shops"; | ||
|
||
Fixtures(); | ||
|
||
describe("Inventory Hooks", function () { | ||
let originals; | ||
let sandbox; | ||
|
||
before(function () { | ||
originals = { | ||
mergeCart: Meteor.server.method_handlers["cart/mergeCart"], | ||
createCart: Meteor.server.method_handlers["cart/createCart"], | ||
copyCartToOrder: Meteor.server.method_handlers["cart/copyCartToOrder"], | ||
addToCart: Meteor.server.method_handlers["cart/addToCart"], | ||
setShipmentAddress: Meteor.server.method_handlers["cart/setShipmentAddress"], | ||
setPaymentAddress: Meteor.server.method_handlers["cart/setPaymentAddress"] | ||
}; | ||
}); | ||
|
||
beforeEach(function () { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
function spyOnMethod(method, id) { | ||
return sandbox.stub(Meteor.server.method_handlers, `cart/${method}`, function () { | ||
check(arguments, [Match.Any]); // to prevent audit_arguments from complaining | ||
this.userId = id; | ||
return originals[method].apply(this, arguments); | ||
}); | ||
} | ||
|
||
it("should move allocated inventory to 'sold' when an order is created", function () { | ||
this.timeout(50000); | ||
Inventory.direct.remove({}); | ||
const cart = Factory.create("cartToOrder"); | ||
sandbox.stub(Reaction, "getShopId", function () { | ||
return cart.shopId; | ||
}); | ||
sandbox.stub(Meteor.server.method_handlers, "orders/sendNotification", function () { | ||
check(arguments, [Match.Any]); | ||
}); | ||
let shop = getShop(); | ||
let product = cart.items[0]; | ||
const inventoryItem = Inventory.insert({ | ||
productId: product.productId, | ||
variantId: product.variants._id, | ||
shopId: shop._id, | ||
workflow: { | ||
status: "reserved" | ||
}, | ||
orderItemId: product._id | ||
}); | ||
expect(inventoryItem).to.not.be.undefined; | ||
Inventory.update(inventoryItem._id, | ||
{ | ||
$set: { | ||
"workflow.status": "reserved", | ||
"orderItemId": product._id | ||
} | ||
}); | ||
spyOnMethod("copyCartToOrder", cart.userId); | ||
Meteor.call("cart/copyCartToOrder", cart._id); | ||
let updatedInventoryItem = Inventory.findOne({ | ||
productId: product.productId, | ||
variantId: product.variants._id, | ||
shopId: shop._id, | ||
orderItemId: product._id | ||
}); | ||
expect(updatedInventoryItem.workflow.status).to.equal("sold"); | ||
}); | ||
|
||
it("should move allocated inventory to 'shipped' when an order is shipped", function () { | ||
this.timeout(50000); | ||
Inventory.direct.remove({}); | ||
const cart = Factory.create("cartToOrder"); | ||
sandbox.stub(Reaction, "getShopId", function () { | ||
return cart.shopId; | ||
}); | ||
sandbox.stub(Reaction, "hasPermission", () => true); | ||
sandbox.stub(Meteor.server.method_handlers, "orders/sendNotification", function () { | ||
check(arguments, [Match.Any]); | ||
}); | ||
let shop = getShop(); | ||
let product = cart.items[0]; | ||
const inventoryItem = Inventory.insert({ | ||
productId: product.productId, | ||
variantId: product.variants._id, | ||
shopId: shop._id, | ||
workflow: { | ||
status: "reserved" | ||
}, | ||
orderItemId: product._id | ||
}); | ||
expect(inventoryItem).to.not.be.undefined; | ||
Inventory.update(inventoryItem._id, | ||
{ | ||
$set: { | ||
"workflow.status": "reserved", | ||
"orderItemId": product._id | ||
} | ||
}); | ||
spyOnMethod("copyCartToOrder", cart.userId); | ||
const orderId = Meteor.call("cart/copyCartToOrder", cart._id); | ||
const order = Orders.findOne(orderId); | ||
const shipping = { items: [] }; | ||
Meteor.call("orders/shipmentShipped", order, shipping); | ||
const shippedInventoryItem = Inventory.findOne(inventoryItem._id); | ||
expect(shippedInventoryItem.workflow.status).to.equal("shipped"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these functions could be exported and then tested independent of the hooks