chore: Migrate modules to use the Module util (#7964)

**What**
Apply the `Module` util to each module to handle the export and provide the linkable configuration object.

- Most joiner config that does not have any special config are removed/cleaned up in favor of the autogenerated one or simpler one
- linkable are now available in all modules
- cleaned up the dependencies of the modules

FIXES CORE-2410
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-07-05 13:00:40 +00:00
1 parent eafa3560ae
commit b368251ca3
99 files changed
+1267 -488

No files matched your search

@@ -1,7 +1,8 @@
import { ICartModuleService } from "@medusajs/types"
import { BigNumber, Modules } from "@medusajs/utils"
import { BigNumber, Module, Modules } from "@medusajs/utils"
import { CheckConstraintViolationException } from "@mikro-orm/core"
import { moduleIntegrationTestRunner } from "medusa-test-utils"
import { CartModuleService } from "@services"
jest.setTimeout(50000)
@@ -9,6 +10,112 @@ moduleIntegrationTestRunner<ICartModuleService>({
moduleName: Modules.CART,
testSuite: ({ service }) => {
describe("Cart Module Service", () => {
it(`should export the appropriate linkable configuration`, () => {
const linkable = Module(Modules.CART, {
service: CartModuleService,
}).linkable
expect(Object.keys(linkable)).toEqual([
"address",
"adjustmentLine",
"cart",
"lineItemAdjustment",
"lineItemTaxLine",
"lineItem",
"shippingMethodAdjustment",
"shippingMethodTaxLine",
"shippingMethod",
"taxLine",
])
Object.keys(linkable).forEach((key) => {
delete linkable[key].toJSON
})
expect(linkable).toEqual({
address: {
id: {
linkable: "address_id",
primaryKey: "id",
serviceName: "cart",
field: "address",
},
},
adjustmentLine: {
id: {
linkable: "adjustment_line_id",
primaryKey: "id",
serviceName: "cart",
field: "adjustmentLine",
},
},
cart: {
id: {
linkable: "cart_id",
primaryKey: "id",
serviceName: "cart",
field: "cart",
},
},
lineItemAdjustment: {
id: {
linkable: "line_item_adjustment_id",
primaryKey: "id",
serviceName: "cart",
field: "lineItemAdjustment",
},
},
lineItemTaxLine: {
id: {
linkable: "line_item_tax_line_id",
primaryKey: "id",
serviceName: "cart",
field: "lineItemTaxLine",
},
},
lineItem: {
id: {
linkable: "line_item_id",
primaryKey: "id",
serviceName: "cart",
field: "lineItem",
},
},
shippingMethodAdjustment: {
id: {
linkable: "shipping_method_adjustment_id",
primaryKey: "id",
serviceName: "cart",
field: "shippingMethodAdjustment",
},
},
shippingMethodTaxLine: {
id: {
linkable: "shipping_method_tax_line_id",
primaryKey: "id",
serviceName: "cart",
field: "shippingMethodTaxLine",
},
},
shippingMethod: {
id: {
linkable: "shipping_method_id",
primaryKey: "id",
serviceName: "cart",
field: "shippingMethod",
},
},
taxLine: {
id: {
linkable: "tax_line_id",
primaryKey: "id",
serviceName: "cart",
field: "taxLine",
},
},
})
})
describe("create", () => {
it("should throw an error when required params are not passed", async () => {
const error = await service