|
1
|
import { MedusaWorkflow } from "@medusajs/framework/workflows-sdk" |
|
2
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
|
3
|
import path from "path" |
|
4
|
import { setTimeout as setTimeoutPromise } from "timers/promises" |
|
5
|
import { testJobHandler } from "../../__fixtures__/feature-flag/src/jobs/test-job" |
|
6
|
|
|
7
|
jest.setTimeout(100000) |
|
8
|
|
|
9
|
medusaIntegrationTestRunner({ |
|
10
|
cwd: path.join(__dirname, "../../__fixtures__/feature-flag"), |
|
11
|
env: { |
|
12
|
CUSTOM_FF: true, |
|
13
|
}, |
|
14
|
testSuite: ({ api, dbConnection }) => { |
|
15
|
describe("Resources loaded with feature flags", () => { |
|
16
|
it("should load migration when feature flag is enabled and run job", async () => { |
|
17
|
const migrationNotExecuted = await dbConnection.raw( |
|
18
|
`SELECT name FROM "mikro_orm_migrations" WHERE name = 'Noop'` |
|
19
|
) |
|
20
|
expect(migrationNotExecuted.rows).toHaveLength(0) |
|
21
|
|
|
22
|
const migrationExecuted = await dbConnection.raw( |
|
23
|
`SELECT name FROM "mikro_orm_migrations" WHERE name = 'MigrationTest'` |
|
24
|
) |
|
25
|
|
|
26
|
expect(migrationExecuted.rows).toHaveLength(1) |
|
27
|
expect(migrationExecuted.rows[0].name).toBe("MigrationTest") |
|
28
|
|
|
29
|
await setTimeoutPromise(1000) |
|
30
|
|
|
31
|
expect(testJobHandler).toHaveBeenCalledTimes(1) |
|
32
|
}) |
|
33
|
|
|
34
|
it("should load workflow when feature flag is enabled", async () => { |
|
35
|
expect(MedusaWorkflow.getWorkflow("test-workflow")).toBeDefined() |
|
36
|
}) |
|
37
|
|
|
38
|
it("should load scheduled job when feature flag is enabled", async () => { |
|
39
|
expect( |
|
40
|
MedusaWorkflow.getWorkflow("job-greeting-every-second") |
|
41
|
).toBeDefined() |
|
42
|
}) |
|
43
|
|
|
44
|
it("should load endpoint when feature flag is enabled", async () => { |
|
45
|
expect((await api.get("/custom")).status).toBe(200) |
|
46
|
expect( |
|
47
|
( |
|
48
|
await api.post("/custom", { |
|
49
|
foo: "test", |
|
50
|
}) |
|
51
|
).status |
|
52
|
).toBe(200) |
|
53
|
}) |
|
54
|
|
|
55
|
it("should return 400 for POST route with invalid body when feature flag is enabled", async () => { |
|
56
|
const response = await api |
|
57
|
.post("/custom", { |
|
58
|
invalid: 1, |
|
59
|
}) |
|
60
|
.catch((e) => e) |
|
61
|
|
|
62
|
expect(response.status).toBe(400) |
|
63
|
}) |
|
64
|
}) |
|
65
|
}, |
|
66
|
}) |