Skip to content

Commit 95e8e37

Browse files
committed
cds v9 wip test 1
1 parent 8dec52f commit 95e8e37

File tree

8 files changed

+65
-28
lines changed

8 files changed

+65
-28
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"roles": ["internal-user"]
1010
}
1111
}
12-
}
12+
},
13+
"toggles": true
1314
}
1415
}

test/cds-test-service/__snapshots__/cds-test-service.test.js.snap renamed to test/cds-test-services/__snapshots__/cds-test-services.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`cds-test-service endpoints state response no change 1`] = `
3+
exports[`cds-test feature-service state response no change 1`] = `
44
{
55
"test/feature_a": {
66
"config": {
@@ -100,7 +100,7 @@ exports[`cds-test-service endpoints state response no change 1`] = `
100100
}
101101
`;
102102

103-
exports[`cds-test-service endpoints state response with changes 1`] = `
103+
exports[`cds-test feature-service state response with changes 1`] = `
104104
{
105105
"test/feature_a": {
106106
"config": {

test/cds-test-service/cds-test-service.test.js renamed to test/cds-test-services/cds-test-services.test.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,10 @@ const toggles = require("../../src");
55

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

8-
const server = cds.test("test/cds-test-service");
8+
const server = cds.test("test/cds-test-services");
99
const systemCall = { validateStatus: () => true, auth: { username: "system", password: "system" } };
1010

11-
describe("cds-test-service", () => {
12-
const featureBChanges = [
13-
{
14-
key: FEATURE.B,
15-
value: 2,
16-
},
17-
{
18-
key: FEATURE.B,
19-
value: 20,
20-
scope: {
21-
tenant: "a",
22-
},
23-
},
24-
{
25-
key: FEATURE.B,
26-
value: 30,
27-
scope: {
28-
tenant: "b",
29-
},
30-
},
31-
];
32-
11+
describe("cds-test", () => {
3312
beforeEach(async () => {
3413
toggles._reset();
3514
await toggles.initializeFeatures({ config });
@@ -38,7 +17,28 @@ describe("cds-test-service", () => {
3817
jest.clearAllMocks();
3918
});
4019

41-
describe("endpoints", () => {
20+
describe("feature-service", () => {
21+
const featureBChanges = [
22+
{
23+
key: FEATURE.B,
24+
value: 2,
25+
},
26+
{
27+
key: FEATURE.B,
28+
value: 20,
29+
scope: {
30+
tenant: "a",
31+
},
32+
},
33+
{
34+
key: FEATURE.B,
35+
value: 30,
36+
scope: {
37+
tenant: "b",
38+
},
39+
},
40+
];
41+
4242
test.each(["/rest/feature/redisSendCommand"])("%s is forbidden for system", async (endpoint) => {
4343
const response = await server.post(endpoint, {}, systemCall);
4444
expect(response.status).toBe(403);
@@ -119,4 +119,17 @@ describe("cds-test-service", () => {
119119
`);
120120
});
121121
});
122+
123+
describe("check-service", () => {
124+
test("priority endpoint with no feature is false", async () => {
125+
const response = await server.get("/rest/check/priority", systemCall);
126+
expect(response.status).toBe(200);
127+
expect(response.data).toBe(false);
128+
});
129+
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+
// });
134+
});
122135
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using { CheckService } from '../../srv/check-service';
2+
3+
annotate CheckService.priority with @marked;
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@protocol: 'rest'
2+
3+
service CheckService {
4+
function priority() returns String;
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
const priorityHandler = (srv) => async (context) => {
4+
// NOTE: srv.model is the base service model without extensions, context.model is the extended service model if
5+
// features are active otherwise undefined.
6+
const { "CheckService.priority": priority } = (context.model ?? srv.model).definitions;
7+
const isFtsToggled = Boolean(priority["@marked"]);
8+
return context.reply(isFtsToggled);
9+
};
10+
11+
module.exports = async (srv) => {
12+
const { priority } = srv.operations;
13+
srv.on(priority, priorityHandler(srv));
14+
};
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
using from '../../../src/service/feature-service';
21
using from './change-service-impl';
2+
using from '../../../src/service/feature-service';
3+
using from './check-service';

0 commit comments

Comments
 (0)