Skip to content

Commit 5403cd4

Browse files
committed
cds v9 wip test 2
1 parent 95e8e37 commit 5403cd4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

test/cds-test-services/cds-test-services.test.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
const cds = require("@sap/cds");
44
const toggles = require("../../src");
5+
const { pluginExport } = require("../../src/plugin");
56

67
const { FEATURE, mockConfig: config } = require("../__common__/mockdata");
78

89
const server = cds.test("test/cds-test-services");
910
const systemCall = { validateStatus: () => true, auth: { username: "system", password: "system" } };
1011

1112
describe("cds-test", () => {
12-
beforeEach(async () => {
13-
toggles._reset();
14-
await toggles.initializeFeatures({ config });
15-
});
1613
afterEach(() => {
1714
jest.clearAllMocks();
1815
});
1916

2017
describe("feature-service", () => {
18+
beforeEach(async () => {
19+
toggles._reset();
20+
await toggles.initializeFeatures({ config });
21+
});
22+
2123
const featureBChanges = [
2224
{
2325
key: FEATURE.B,
@@ -121,15 +123,27 @@ describe("cds-test", () => {
121123
});
122124

123125
describe("check-service", () => {
126+
beforeAll(async () => {
127+
toggles._reset();
128+
jest.spyOn(process, "cwd").mockReturnValue(__dirname);
129+
await pluginExport();
130+
});
131+
124132
test("priority endpoint with no feature is false", async () => {
133+
const i = toggles.getFeaturesInfos();
134+
expect(toggles.getFeatureValue("/fts/check-service-extension")).toBe(false);
125135
const response = await server.get("/rest/check/priority", systemCall);
126136
expect(response.status).toBe(200);
127137
expect(response.data).toBe(false);
128138
});
129139

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+
});
134148
});
135149
});

0 commit comments

Comments
 (0)