Feat(order): return reason and transaction methods (#7303)

This commit is contained in:
Carlos R. L. Rodrigues
2024-05-13 16:15:25 +00:00
committed by GitHub
parent 8958214350
commit 6c94d0205c
23 changed files with 1036 additions and 6 deletions
@@ -0,0 +1,94 @@
import { Modules } from "@medusajs/modules-sdk"
import { IOrderModuleService } from "@medusajs/types"
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(100000)
moduleIntegrationTestRunner({
moduleName: Modules.ORDER,
testSuite: ({ service }: SuiteOptions<IOrderModuleService>) => {
describe("Order Module Service - Returns", () => {
it("should create return reasons", async function () {
const reason = await service.createReturnReasons({
value: "test",
label: "label test",
description: "description test",
})
expect(reason).toEqual({
id: expect.any(String),
value: "test",
label: "label test",
description: "description test",
return_reason_children: [],
metadata: null,
deleted_at: null,
})
})
it("should create return reasons with parent", async function () {
const reason = await service.createReturnReasons({
value: "test",
label: "label test",
description: "description test",
})
const reason2 = await service.createReturnReasons({
value: "test 2.0",
label: "child",
parent_return_reason_id: reason.id,
})
const reason3 = await service.createReturnReasons({
value: "test 3.0",
label: "child 3",
parent_return_reason_id: reason.id,
})
const getChild = await service.retrieveReturnReason(reason2.id, {
relations: ["parent_return_reason"],
})
expect(getChild).toEqual(
expect.objectContaining({
id: reason2.id,
value: "test 2.0",
label: "child",
parent_return_reason_id: reason.id,
parent_return_reason: expect.objectContaining({
id: reason.id,
value: "test",
label: "label test",
description: "description test",
parent_return_reason_id: null,
}),
})
)
const getParent = await service.retrieveReturnReason(reason.id, {
relations: ["return_reason_children"],
})
expect(getParent).toEqual(
expect.objectContaining({
id: reason.id,
value: "test",
label: "label test",
description: "description test",
return_reason_children: [
expect.objectContaining({
id: reason2.id,
value: "test 2.0",
label: "child",
parent_return_reason_id: reason.id,
}),
expect.objectContaining({
id: reason3.id,
value: "test 3.0",
label: "child 3",
parent_return_reason_id: reason.id,
}),
],
})
)
})
})
},
})