corrected tests
This commit is contained in:
11
packages/medusa/.vscode/settings.json
vendored
Normal file
11
packages/medusa/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"editor.formatOnSave": true,
|
||||
"[javascript]": {
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"eslint.format.enable": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export default (app, container, config) => {
|
||||
returnRoutes(route)
|
||||
variantRoutes(route)
|
||||
draftOrderRoutes(route)
|
||||
collectionRoutes(route) //test
|
||||
collectionRoutes(route)
|
||||
notificationRoutes(route)
|
||||
returnReasonRoutes(route)
|
||||
|
||||
|
||||
@@ -43,8 +43,7 @@ describe("POST /admin/orders/:id/fulfillment", () => {
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
undefined,
|
||||
undefined
|
||||
{"metadata": undefined, "noNotification": undefined}
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -17,13 +17,20 @@ const defaultRelations = [
|
||||
"returns.items.reason",
|
||||
"gift_cards",
|
||||
"gift_card_transactions",
|
||||
"items",
|
||||
"items.variant",
|
||||
"items.variant.product",
|
||||
"claims",
|
||||
"claims.return_order",
|
||||
"claims.shipping_methods",
|
||||
"claims.shipping_address",
|
||||
"claims.additional_items",
|
||||
"claims.additional_items.variant",
|
||||
"claims.additional_items.variant.product",
|
||||
"claims.fulfillments",
|
||||
"claims.claim_items",
|
||||
"claims.claim_items.variant",
|
||||
"claims.claim_items.variant.product",
|
||||
"claims.claim_items.images",
|
||||
"swaps",
|
||||
"swaps.return_order",
|
||||
|
||||
@@ -215,19 +215,21 @@ describe("ClaimService", () => {
|
||||
it.each(
|
||||
[
|
||||
[false, false],
|
||||
[undefined, true]
|
||||
[undefined, true],
|
||||
],
|
||||
"passes correct no_notification status to event bus", async (input, expected) => {
|
||||
"passes correct no_notification status to event bus",
|
||||
async (input, expected) => {
|
||||
await claimService.create({
|
||||
...testClaim,
|
||||
no_notification: input,
|
||||
})
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
||||
id: expect.any(String),
|
||||
no_notification: expected
|
||||
...testClaim,
|
||||
no_notification: input,
|
||||
})
|
||||
})
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe("retrieve", () => {
|
||||
@@ -314,7 +316,9 @@ describe("ClaimService", () => {
|
||||
})
|
||||
|
||||
it("successfully creates fulfillment", async () => {
|
||||
await claimService.createFulfillment("claim_id", { meta: "data" })
|
||||
await claimService.createFulfillment("claim_id", {
|
||||
metadata: { meta: "data" },
|
||||
})
|
||||
|
||||
expect(withTransactionMock).toHaveBeenCalledTimes(3)
|
||||
expect(withTransactionMock).toHaveBeenCalledWith("eventBus")
|
||||
@@ -434,7 +438,10 @@ describe("ClaimService", () => {
|
||||
)
|
||||
|
||||
await claimService.createShipment("claim", "ful_123", ["track1234"], {
|
||||
meta: "data",
|
||||
metadata: {
|
||||
meta: "data",
|
||||
},
|
||||
noNotification: false,
|
||||
})
|
||||
|
||||
expect(withTransactionMock).toHaveBeenCalledTimes(3)
|
||||
@@ -446,7 +453,12 @@ describe("ClaimService", () => {
|
||||
expect(fulfillmentService.createShipment).toHaveBeenCalledWith(
|
||||
"ful_123",
|
||||
["track1234"],
|
||||
{ meta: "data" }
|
||||
{
|
||||
metadata: {
|
||||
meta: "data",
|
||||
},
|
||||
noNotification: false,
|
||||
}
|
||||
)
|
||||
|
||||
expect(lineItemService.update).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -866,27 +866,28 @@ describe("OrderService", () => {
|
||||
[true, true],
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
])("emits correct no_notification option with '%s'", async (input, expected) => {
|
||||
await orderService.createFulfillment(
|
||||
"test-order",
|
||||
[
|
||||
{
|
||||
item_id: "item_1",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
input
|
||||
)
|
||||
])(
|
||||
"emits correct no_notification option with '%s'",
|
||||
async (input, expected) => {
|
||||
await orderService.createFulfillment(
|
||||
"test-order",
|
||||
[
|
||||
{
|
||||
item_id: "item_1",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
{ noNotification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
})
|
||||
})
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
|
||||
describe("registerReturnReceived", () => {
|
||||
const order = {
|
||||
items: [
|
||||
@@ -1023,7 +1024,11 @@ describe("OrderService", () => {
|
||||
}
|
||||
|
||||
const fulfillmentService = {
|
||||
retrieve: () => Promise.resolve({ order_id: IdMap.getId("test") }),
|
||||
retrieve: () =>
|
||||
Promise.resolve({
|
||||
order_id: IdMap.getId("test"),
|
||||
no_notification: true,
|
||||
}),
|
||||
createShipment: jest
|
||||
.fn()
|
||||
.mockImplementation((shipmentId, tracking, meta) => {
|
||||
@@ -1063,10 +1068,12 @@ describe("OrderService", () => {
|
||||
)
|
||||
|
||||
expect(fulfillmentService.createShipment).toHaveBeenCalledTimes(1)
|
||||
expect(fulfillmentService.createShipment).toHaveBeenCalledWith(
|
||||
expect(
|
||||
fulfillmentService.createShipment
|
||||
).toHaveBeenCalledWith(
|
||||
IdMap.getId("fulfillment"),
|
||||
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||
{}
|
||||
{ metadata: undefined, noNotification: true }
|
||||
)
|
||||
|
||||
expect(orderRepo.save).toHaveBeenCalledTimes(1)
|
||||
@@ -1080,20 +1087,22 @@ describe("OrderService", () => {
|
||||
[true, true],
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
])("2emits correct no_notification option with '%s'", async (input, expected) => {
|
||||
await orderService.createShipment(
|
||||
IdMap.getId("test"),
|
||||
IdMap.getId("fulfillment"),
|
||||
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||
input,
|
||||
{}
|
||||
)
|
||||
])(
|
||||
"emits correct no_notification option with '%s'",
|
||||
async (input, expected) => {
|
||||
await orderService.createShipment(
|
||||
IdMap.getId("test"),
|
||||
IdMap.getId("fulfillment"),
|
||||
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||
{ noNotification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
})
|
||||
})
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe("createRefund", () => {
|
||||
@@ -1180,20 +1189,23 @@ describe("OrderService", () => {
|
||||
it.each([
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
])("emits correct no_notification option with '%s'", async (input, expected) => {
|
||||
await orderService.createRefund(
|
||||
IdMap.getId("order_123"),
|
||||
100,
|
||||
"discount",
|
||||
"note",
|
||||
input
|
||||
)
|
||||
])(
|
||||
"emits correct no_notification option with '%s'",
|
||||
async (input, expected) => {
|
||||
await orderService.createRefund(
|
||||
IdMap.getId("order_123"),
|
||||
100,
|
||||
"discount",
|
||||
"note",
|
||||
{ noNotification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String),{
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
refund_id: expect.any(String)
|
||||
} )
|
||||
})
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
id: expect.any(String),
|
||||
no_notification: expected,
|
||||
refund_id: expect.any(String),
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -355,7 +355,7 @@ describe("SwapService", () => {
|
||||
id: IdMap.getId("return-shipping"),
|
||||
price: 20,
|
||||
},
|
||||
input
|
||||
{noNotification: input}
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(
|
||||
|
||||
@@ -459,7 +459,7 @@ class ClaimService extends BaseService {
|
||||
}
|
||||
|
||||
async createShipment(id, fulfillmentId, trackingLinks, config = {
|
||||
metadata: [],
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
}) {
|
||||
const { metadata, noNotification } = config
|
||||
@@ -503,7 +503,7 @@ class ClaimService extends BaseService {
|
||||
.emit(ClaimService.Events.SHIPMENT_CREATED, {
|
||||
id,
|
||||
fulfillment_id: shipment.id,
|
||||
no_notification: result.no_notification
|
||||
no_notification: evaluatedNoNotification
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { metadata } from "core-js/fn/reflect"
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
@@ -312,7 +311,6 @@ class OrderService extends BaseService {
|
||||
* @return {Promise<Order>} the order document
|
||||
*/
|
||||
async retrieve(orderId, config = {}) {
|
||||
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
const validatedId = this.validateId_(orderId)
|
||||
|
||||
@@ -409,7 +407,7 @@ class OrderService extends BaseService {
|
||||
OrderService.Events.COMPLETED,
|
||||
{
|
||||
id: orderId,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -510,7 +508,6 @@ class OrderService extends BaseService {
|
||||
|
||||
toCreate.draft_order_id = draft.id
|
||||
toCreate.no_notification = draft.no_notification_order
|
||||
|
||||
}
|
||||
|
||||
const o = await orderRepo.create(toCreate)
|
||||
@@ -557,7 +554,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.emit(OrderService.Events.PLACED, {
|
||||
id: result.id,
|
||||
no_notification: result.no_notification
|
||||
no_notification: result.no_notification,
|
||||
})
|
||||
|
||||
return result
|
||||
@@ -576,10 +573,15 @@ class OrderService extends BaseService {
|
||||
* the fulfillment
|
||||
* @return {order} the resulting order following the update.
|
||||
*/
|
||||
async createShipment(orderId, fulfillmentId, trackingLinks, config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
}) {
|
||||
async createShipment(
|
||||
orderId,
|
||||
fulfillmentId,
|
||||
trackingLinks,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
@@ -593,11 +595,15 @@ class OrderService extends BaseService {
|
||||
)
|
||||
}
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : shipment.no_notification
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : shipment.no_notification
|
||||
|
||||
const shipmentRes = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
.createShipment(fulfillmentId, trackingLinks, {metadata, noNotification: evaluatedNoNotification})
|
||||
.createShipment(fulfillmentId, trackingLinks, {
|
||||
metadata,
|
||||
noNotification: evaluatedNoNotification,
|
||||
})
|
||||
|
||||
order.fulfillment_status = "shipped"
|
||||
for (const item of order.items) {
|
||||
@@ -626,7 +632,7 @@ class OrderService extends BaseService {
|
||||
.emit(OrderService.Events.SHIPMENT_CREATED, {
|
||||
id: orderId,
|
||||
fulfillment_id: shipmentRes.id,
|
||||
no_notification: evaluatedNoNotification
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
|
||||
return result
|
||||
@@ -647,7 +653,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.emit(OrderService.Events.PLACED, {
|
||||
id: result.id,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
})
|
||||
return result
|
||||
})
|
||||
@@ -815,7 +821,7 @@ class OrderService extends BaseService {
|
||||
await this.updateBillingAddress_(order, update.billing_address)
|
||||
}
|
||||
|
||||
if("no_notification" in update){
|
||||
if ("no_notification" in update) {
|
||||
order.no_notification = update.no_notification
|
||||
}
|
||||
|
||||
@@ -839,7 +845,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.emit(OrderService.Events.UPDATED, {
|
||||
id: orderId,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
})
|
||||
return result
|
||||
})
|
||||
@@ -890,7 +896,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.emit(OrderService.Events.CANCELED, {
|
||||
id: order.id,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
})
|
||||
return result
|
||||
})
|
||||
@@ -919,7 +925,7 @@ class OrderService extends BaseService {
|
||||
id: orderId,
|
||||
payment_id: p.id,
|
||||
error: err,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -945,7 +951,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.emit(OrderService.Events.PAYMENT_CAPTURED, {
|
||||
id: result.id,
|
||||
no_notification: order.no_notification
|
||||
no_notification: order.no_notification,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -992,10 +998,14 @@ class OrderService extends BaseService {
|
||||
* @param {string} orderId - id of order to cancel.
|
||||
* @return {Promise} result of the update operation.
|
||||
*/
|
||||
async createFulfillment(orderId, itemsToFulfill, config = {
|
||||
async createFulfillment(
|
||||
orderId,
|
||||
itemsToFulfill,
|
||||
config = {
|
||||
noNotification: undefined,
|
||||
metadata: {},
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
@@ -1031,7 +1041,6 @@ class OrderService extends BaseService {
|
||||
"Cannot fulfill an order that lacks shipping methods"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
const fulfillments = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
@@ -1077,7 +1086,8 @@ class OrderService extends BaseService {
|
||||
order.fulfillments = [...order.fulfillments, ...fulfillments]
|
||||
const result = await orderRepo.save(order)
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : order.no_notification
|
||||
|
||||
for (const fulfillment of fulfillments) {
|
||||
await this.eventBus_
|
||||
@@ -1085,7 +1095,7 @@ class OrderService extends BaseService {
|
||||
.emit(OrderService.Events.FULFILLMENT_CREATED, {
|
||||
id: orderId,
|
||||
fulfillment_id: fulfillment.id,
|
||||
no_notification: evaluatedNoNotification
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1141,9 +1151,15 @@ class OrderService extends BaseService {
|
||||
/**
|
||||
* Refunds a given amount back to the customer.
|
||||
*/
|
||||
async createRefund(orderId, refundAmount, reason, note, config = {
|
||||
noNotification: undefined,
|
||||
}) {
|
||||
async createRefund(
|
||||
orderId,
|
||||
refundAmount,
|
||||
reason,
|
||||
note,
|
||||
config = {
|
||||
noNotification: undefined,
|
||||
}
|
||||
) {
|
||||
const { noNotification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
@@ -1165,12 +1181,13 @@ class OrderService extends BaseService {
|
||||
|
||||
const result = await this.retrieve(orderId)
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : order.no_notification
|
||||
|
||||
this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
|
||||
id: result.id,
|
||||
refund_id: refund.id,
|
||||
no_notification: evaluatedNoNotification
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
return result
|
||||
})
|
||||
@@ -1274,7 +1291,7 @@ class OrderService extends BaseService {
|
||||
.emit(OrderService.Events.RETURN_ACTION_REQUIRED, {
|
||||
id: result.id,
|
||||
return_id: receivedReturn.id,
|
||||
no_notification: receivedReturn.no_notification
|
||||
no_notification: receivedReturn.no_notification,
|
||||
})
|
||||
return result
|
||||
}
|
||||
@@ -1306,7 +1323,7 @@ class OrderService extends BaseService {
|
||||
.emit(OrderService.Events.ITEMS_RETURNED, {
|
||||
id: order.id,
|
||||
return_id: receivedReturn.id,
|
||||
no_notification: receivedReturn.no_notification
|
||||
no_notification: receivedReturn.no_notification,
|
||||
})
|
||||
return result
|
||||
})
|
||||
|
||||
@@ -215,9 +215,11 @@ class SwapService extends BaseService {
|
||||
returnItems,
|
||||
additionalItems,
|
||||
returnShipping,
|
||||
custom = {}
|
||||
) {
|
||||
|
||||
custom = {
|
||||
noNotification: undefined
|
||||
}
|
||||
){
|
||||
const { noNotification, ...rest } = custom
|
||||
return this.atomicPhase_(async manager => {
|
||||
if (
|
||||
order.fulfillment_status === "not_fulfilled" ||
|
||||
@@ -239,8 +241,6 @@ class SwapService extends BaseService {
|
||||
})
|
||||
)
|
||||
|
||||
const { noNotification, ...rest } = custom
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
||||
|
||||
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
||||
@@ -746,9 +746,11 @@ class SwapService extends BaseService {
|
||||
|
||||
await this.eventBus_
|
||||
.withTransaction(manager)
|
||||
.emit(SwapService.Events.FULFILLMENT_CREATED, {
|
||||
.emit(SwapService.Events.FULFILLMENT_CREATED,
|
||||
|
||||
{
|
||||
id: swapId,
|
||||
fulfillment_id: shipment.id,
|
||||
fulfillment_id: result.id,
|
||||
no_notification: evaluatedNoNotification
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user