feat: Add the basic implementation of notification module (#7282)
* feat: Add the basic implementation of notification module * fix: Minor fixes and introduction of idempotency key * fix: Changes based on PR review
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { INotificationModuleService } from "@medusajs/types"
|
||||
import {
|
||||
moduleIntegrationTestRunner,
|
||||
SuiteOptions,
|
||||
} from "medusa-test-utils/dist"
|
||||
import { resolve } from "path"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: {
|
||||
"test-provider": {
|
||||
name: "Test provider",
|
||||
channels: ["email"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.NOTIFICATION,
|
||||
moduleOptions,
|
||||
testSuite: ({ service }: SuiteOptions<INotificationModuleService>) =>
|
||||
describe("Notification Module Service", () => {
|
||||
it("sends a notification and stores it in the database", async () => {
|
||||
const notification = {
|
||||
to: "admin@medusa.com",
|
||||
template: "some-template",
|
||||
channel: "email",
|
||||
data: {},
|
||||
}
|
||||
|
||||
const result = await service.create(notification)
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
provider_id: "test-provider",
|
||||
external_id: "external_id",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("ensures the same notification is not sent twice", async () => {
|
||||
const notification = {
|
||||
to: "admin@medusa.com",
|
||||
template: "some-template",
|
||||
channel: "email",
|
||||
data: {},
|
||||
idempotency_key: "idempotency-key",
|
||||
}
|
||||
|
||||
const result = await service.create(notification)
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
provider_id: "test-provider",
|
||||
external_id: "external_id",
|
||||
})
|
||||
)
|
||||
|
||||
const secondResult = await service.create(notification)
|
||||
expect(secondResult).toBe(undefined)
|
||||
})
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user