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:
@@ -1,7 +1,8 @@
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { ITaxModuleService } from "@medusajs/types"
|
||||
import { setupTaxStructure } from "../utils/setup-tax-structure"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { TaxModuleService } from "@services"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -9,6 +10,58 @@ moduleIntegrationTestRunner<ITaxModuleService>({
|
||||
moduleName: Modules.TAX,
|
||||
testSuite: ({ service }) => {
|
||||
describe("TaxModuleService", function () {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.TAX, {
|
||||
service: TaxModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual([
|
||||
"taxProvider",
|
||||
"taxRateRule",
|
||||
"taxRate",
|
||||
"taxRegion",
|
||||
])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
taxProvider: {
|
||||
id: {
|
||||
linkable: "tax_provider_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxProvider",
|
||||
},
|
||||
},
|
||||
taxRateRule: {
|
||||
id: {
|
||||
linkable: "tax_rate_rule_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRateRule",
|
||||
},
|
||||
},
|
||||
taxRate: {
|
||||
id: {
|
||||
linkable: "tax_rate_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRate",
|
||||
},
|
||||
},
|
||||
taxRegion: {
|
||||
id: {
|
||||
linkable: "tax_region_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "tax",
|
||||
field: "taxRegion",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should create tax rates and update them", async () => {
|
||||
const region = await service.createTaxRegions({
|
||||
country_code: "US",
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
@@ -45,13 +46,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.9",
|
||||
"@medusajs/types": "^1.11.14",
|
||||
"@medusajs/utils": "^1.11.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
"awilix": "^8.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { TaxModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
const service = TaxModuleService
|
||||
const loaders = [loadProviders]
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
export default Module(Modules.TAX, {
|
||||
service: TaxModuleService,
|
||||
loaders: [loadProviders],
|
||||
})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.TAX)
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
InternalModuleDeclaration,
|
||||
ITaxModuleService,
|
||||
ITaxProvider,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
TaxRegionDTO,
|
||||
TaxTypes,
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { TaxProvider, TaxRate, TaxRateRule, TaxRegion } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -75,10 +73,6 @@ export default class TaxModuleService
|
||||
this.taxProviderService_ = taxProviderService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
async createTaxRates(
|
||||
data: TaxTypes.CreateTaxRateDTO[],
|
||||
|
||||
Reference in New Issue
Block a user