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:
+25
-1
@@ -1,7 +1,8 @@
|
||||
import { INotificationModuleService } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { resolve } from "path"
|
||||
import { NotificationModuleService } from "@services"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
@@ -26,6 +27,29 @@ moduleIntegrationTestRunner({
|
||||
moduleOptions,
|
||||
testSuite: ({ service }: SuiteOptions<INotificationModuleService>) =>
|
||||
describe("Notification Module Service", () => {
|
||||
it(`should export the appropriate linkable configuration`, () => {
|
||||
const linkable = Module(Modules.NOTIFICATION, {
|
||||
service: NotificationModuleService,
|
||||
}).linkable
|
||||
|
||||
expect(Object.keys(linkable)).toEqual(["notification"])
|
||||
|
||||
Object.keys(linkable).forEach((key) => {
|
||||
delete linkable[key].toJSON
|
||||
})
|
||||
|
||||
expect(linkable).toEqual({
|
||||
notification: {
|
||||
id: {
|
||||
linkable: "notification_id",
|
||||
primaryKey: "id",
|
||||
serviceName: "notification",
|
||||
field: "notification",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("sends a notification and stores it in the database", async () => {
|
||||
const notification = {
|
||||
to: "admin@medusa.com",
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@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.11",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@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,10 +1,8 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { NotificationModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
import { Module, Modules } from "@medusajs/utils"
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
export default Module(Modules.NOTIFICATION, {
|
||||
service: NotificationModuleService,
|
||||
loaders: [loadProviders],
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.NOTIFICATION, {
|
||||
models: [{ name: "Notification" }],
|
||||
})
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
InferEntityType,
|
||||
INotificationModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
NotificationTypes,
|
||||
} from "@medusajs/types"
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { Notification } from "@models"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import NotificationProviderService from "./notification-provider"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -55,10 +53,6 @@ export default class NotificationModuleService
|
||||
this.notificationProviderService_ = notificationProviderService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
createNotifications(
|
||||
data: NotificationTypes.CreateNotificationDTO[],
|
||||
|
||||
Reference in New Issue
Block a user