|
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
|
testSuite: ({ api, dbConnection }) => { |
|
12
|
describe("Resources loaded without feature flags", () => { |
|
13
|
it("should not load migration when feature flag is disabled and not run job", async () => { |
|
14
|
const migrationNotExecuted = await dbConnection.raw( |
|
15
|
`SELECT name FROM "mikro_orm_migrations" WHERE name = 'MigrationTest'` |
|
16
|
) |
|
17
|
expect(migrationNotExecuted.rows).toHaveLength(0) |
|
18
|
|
|
19
|
const migrationExecuted = await dbConnection.raw( |
|
20
|
`SELECT name FROM "mikro_orm_migrations" WHERE name = 'Noop'` |
|
21
|
) |
|
22
|
|
|
23
|
expect(migrationExecuted.rows).toHaveLength(1) |
|
24
|
expect(migrationExecuted.rows[0].name).toBe("Noop") |
|
25
|
|
|
26
|
await setTimeoutPromise(1000) |
|
27
|
|
|
28
|
expect(testJobHandler).toHaveBeenCalledTimes(0) |
|
29
|
}) |
|
30
|
|
|
31
|
it("should not load workflow when feature flag is disabled", async () => { |
|
32
|
expect(MedusaWorkflow.getWorkflow("test-workflow")).toBeUndefined() |
|
33
|
}) |
|
34
|
|
|
35
|
it("should not load scheduled job when feature flag is disabled", async () => { |
|
36
|
expect( |
|
37
|
MedusaWorkflow.getWorkflow("job-greeting-every-second") |
|
38
|
).toBeUndefined() |
|
39
|
}) |
|
40
|
|
|
41
|
it("should not load endpoint when feature flag is disabled", async () => { |
|
42
|
expect(api.get("/custom")).rejects.toThrow() |
|
43
|
}) |
|
44
|
|
|
45
|
it("should return 404 (not 400) for POST route with middleware when feature flag is disabled", async () => { |
|
46
|
const { response } = await api |
|
47
|
.post("/custom", { |
|
48
|
invalid: "test", |
|
49
|
}) |
|
50
|
.catch((e) => e) |
|
51
|
|
|
52
|
expect(response.status).toBe(404) |
|
53
|
}) |
|
54
|
}) |
|
55
|
}, |
|
56
|
}) |