|
2 | 2 |
|
3 | 3 | const cds = require("@sap/cds"); |
4 | 4 | const toggles = require("../../src"); |
| 5 | +const { pluginExport } = require("../../src/plugin"); |
5 | 6 |
|
6 | 7 | const { FEATURE, mockConfig: config } = require("../__common__/mockdata"); |
7 | 8 |
|
8 | 9 | const server = cds.test("test/cds-test-services"); |
9 | 10 | const systemCall = { validateStatus: () => true, auth: { username: "system", password: "system" } }; |
10 | 11 |
|
11 | 12 | describe("cds-test", () => { |
12 | | - beforeEach(async () => { |
13 | | - toggles._reset(); |
14 | | - await toggles.initializeFeatures({ config }); |
15 | | - }); |
16 | 13 | afterEach(() => { |
17 | 14 | jest.clearAllMocks(); |
18 | 15 | }); |
19 | 16 |
|
20 | 17 | describe("feature-service", () => { |
| 18 | + beforeEach(async () => { |
| 19 | + toggles._reset(); |
| 20 | + await toggles.initializeFeatures({ config }); |
| 21 | + }); |
| 22 | + |
21 | 23 | const featureBChanges = [ |
22 | 24 | { |
23 | 25 | key: FEATURE.B, |
@@ -121,15 +123,27 @@ describe("cds-test", () => { |
121 | 123 | }); |
122 | 124 |
|
123 | 125 | describe("check-service", () => { |
| 126 | + beforeAll(async () => { |
| 127 | + toggles._reset(); |
| 128 | + jest.spyOn(process, "cwd").mockReturnValue(__dirname); |
| 129 | + await pluginExport(); |
| 130 | + }); |
| 131 | + |
124 | 132 | test("priority endpoint with no feature is false", async () => { |
| 133 | + const i = toggles.getFeaturesInfos(); |
| 134 | + expect(toggles.getFeatureValue("/fts/check-service-extension")).toBe(false); |
125 | 135 | const response = await server.get("/rest/check/priority", systemCall); |
126 | 136 | expect(response.status).toBe(200); |
127 | 137 | expect(response.data).toBe(false); |
128 | 138 | }); |
129 | 139 |
|
130 | | - // TODO cds.test does not load the plugin, so the middleware that acts as a feature vector provider is not active... |
131 | | - // test("priority endpoint with feature is true", async () => { |
132 | | - // const response = await server.get("/rest/check/priority", systemCall); |
133 | | - // }); |
| 140 | + test("priority endpoint with feature is true", async () => { |
| 141 | + await toggles.changeFeatureValue("/fts/check-service-extension", true); |
| 142 | + expect(toggles.getFeatureValue("/fts/check-service-extension")).toBe(true); |
| 143 | + // TODO this does not use cds.middlewares, so it will not work... |
| 144 | + const response = await server.get("/rest/check/priority", systemCall); |
| 145 | + expect(response.status).toBe(200); |
| 146 | + expect(response.data).toBe(true); |
| 147 | + }); |
134 | 148 | }); |
135 | 149 | }); |
0 commit comments