Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 104 additions & 24 deletions integration-tests/http/slack-service.workflow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,119 @@
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import { slackServiceWorkflow } from "../../src/workflows/mpn-builder-services/slack-service"

type SlackTemplateCase = {
name: string
templateId: string
data: Record<string, any>
}

const backendUrl = "http://localhost:9000"

const cases: SlackTemplateCase[] = [
{
name: "inventory level",
templateId: "system_inventory-level",
data: {
backendUrl,
inventory_level: {
inventory_item: { id: "ii_123" },
stock_locations: [{ name: "Main" }],
},
},
},
{
name: "product",
templateId: "system_product",
data: {
backendUrl,
product: { id: "prod_123" },
},
},
{
name: "product variant",
templateId: "system_product-variant",
data: {
backendUrl,
product_variant: {
id: "variant_123",
product: { id: "prod_123" },
},
},
},
{
name: "order placed",
templateId: "system_order-placed",
data: {
backendUrl,
order: { id: "order_123" },
},
},
{
name: "order completed",
templateId: "system_order-completed",
data: {
backendUrl,
order: { id: "order_123" },
},
},
{
name: "order updated",
templateId: "system_order-updated",
data: {
backendUrl,
order: { id: "order_123" },
},
},
{
name: "order canceled",
templateId: "system_order-canceled",
data: {
backendUrl,
order: { id: "order_123" },
},
},
{
name: "order archived",
templateId: "system_order-archived",
data: {
backendUrl,
order: { id: "order_123" },
},
},
]

medusaIntegrationTestRunner({
moduleName: "notification-emails",
medusaConfigFile: process.cwd(),
testSuite: ({ getContainer }) => {
describe("slackServiceWorkflow", () => {
describe("slackServiceWorkflow templates", () => {
jest.setTimeout(60 * 1000)

it("renders a system Slack template", async () => {
const { result } = await slackServiceWorkflow(
getContainer()
).run({
input: {
template_id: "system_order-placed",
data: {
backendUrl: "http://localhost:9000",
order: {
id: "order_123",
name: "Test Order",
display_id: "123",
test.each(cases)(
"renders $name",
async ({ templateId, data }) => {
const { result } = await slackServiceWorkflow(
getContainer()
).run({
input: {
template_id: templateId,
data,
options: {
locale: "en",
theme: {},
translations: {},
backendUrl,
},
},
options: {
locale: "en",
theme: {},
translations: {},
backendUrl: "http://localhost:9000",
},
},
})
})

expect(Array.isArray(result.blocks)).toBe(true)
expect(result.blocks.length).toBeGreaterThan(0)
})
expect(Array.isArray(result.blocks)).toBe(true)
expect(result.blocks.length).toBeGreaterThan(0)
result.blocks.forEach((block: any) => {
expect(block.type).toBeTruthy()
})
}
)
})
},
})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"publish-package": "dotenv npm publish --access public",
"email:dev": "email dev --dir emails-previews",
"test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent",
"test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
"test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
"test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
"test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
"test:db:up": "docker compose -f docker-compose.test.yml up -d",
"test:db:down": "docker compose -f docker-compose.test.yml down -v",
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
Expand Down
2 changes: 1 addition & 1 deletion src/templates/slack/inventory-level/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const templateBlocks = [
type: "plain_text",
text: "Open in Panel",
},
url: `{{data.backend_url}}/app/inventory/{{data.inventory_level.inventory_item.id}}`,
url: `{{data.backendUrl}}/app/inventory/{{data.inventory_level.inventory_item.id}}`,
style: "primary",
},
],
Expand Down
2 changes: 0 additions & 2 deletions src/workflows/mpn-builder-services/steps/slack-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export const slackServiceStep = createStep(
},
})

console.log("renderedBlocks", renderedBlocks)

return new StepResponse({
blocks: renderedBlocks,
})
Expand Down