Skip to content

Commit 8e41965

Browse files
authored
Fb/service test (#74)
* make cds service work without failed http calls in no_redis mode * make integration tests use common config * basic tests for cds-service * upgrade lock * update snaps * stop console time logs
1 parent 8601c02 commit 8e41965

12 files changed

+361
-72
lines changed

Diff for: jest.setupAfterEnv.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ jest.spyOn(console, "log").mockImplementation();
55
jest.spyOn(console, "info").mockImplementation();
66
jest.spyOn(console, "warn").mockImplementation();
77
jest.spyOn(console, "error").mockImplementation();
8+
jest.spyOn(console, "time").mockImplementation();
89
jest.spyOn(process.stdout, "write").mockImplementation();
910
jest.spyOn(process.stderr, "write").mockImplementation();

Diff for: package-lock.json

+95-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"@sap/cds": "^8.2.3",
37+
"axios": "^1.7.7",
3738
"eslint": "^8.57.1",
3839
"eslint-config-prettier": "^9.1.0",
3940
"eslint-plugin-jest": "^28.8.3",

Diff for: src/featureToggles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ class FeatureToggles {
920920
async getRemoteFeaturesInfos() {
921921
this._ensureInitialized();
922922
if ((await redis.getIntegrationMode()) === REDIS_INTEGRATION_MODE.NO_REDIS) {
923-
return null;
923+
return {};
924924
}
925925

926926
const remoteStateScopedValues = await redis.hashGetAllObjects(this.__redisKey);

Diff for: test/__common__/mockdata.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const mockConfig = {
4141
[FEATURE.E]: {
4242
fallbackValue: 5,
4343
type: "number",
44-
validations: [{ regex: "^\\d{1}$" }],
44+
validations: [{ scopes: ["component", "layer", "tenant"] }, { regex: "^\\d{1}$" }],
4545
},
4646
[FEATURE.F]: {
4747
fallbackValue: "best",

Diff for: test/__snapshots__/featureToggles.test.js.snap

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ exports[`feature toggles test basic apis getFeaturesInfos 1`] = `
8585
"SOURCE": "RUNTIME",
8686
"TYPE": "number",
8787
"VALIDATIONS": [
88+
{
89+
"scopes": [
90+
"component",
91+
"layer",
92+
"tenant",
93+
],
94+
},
8895
{
8996
"regex": "^\\d{1}$",
9097
},
@@ -194,13 +201,25 @@ exports[`feature toggles test basic apis initializeFeatureToggles 1`] = `
194201
"SOURCE": "RUNTIME",
195202
"TYPE": "number",
196203
"VALIDATIONS": [
204+
{
205+
"scopes": [
206+
"component",
207+
"layer",
208+
"tenant",
209+
],
210+
},
197211
{
198212
"regex": "^\\d{1}$",
199213
},
200214
],
201215
"VALIDATIONS_REGEX": [
202216
/\\^\\\\d\\{1\\}\\$/,
203217
],
218+
"VALIDATIONS_SCOPES_MAP": {
219+
"component": true,
220+
"layer": true,
221+
"tenant": true,
222+
},
204223
},
205224
"test/feature_f": {
206225
"SOURCE": "RUNTIME",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`cds-service endpoints state response 1`] = `
4+
{
5+
"test/feature_a": {
6+
"config": {
7+
"SOURCE": "RUNTIME",
8+
"TYPE": "boolean",
9+
},
10+
"fallbackValue": false,
11+
},
12+
"test/feature_aa": {
13+
"config": {
14+
"SOURCE": "RUNTIME",
15+
"TYPE": "boolean",
16+
"VALIDATIONS": [
17+
{
18+
"scopes": [
19+
"tenant",
20+
"user",
21+
],
22+
},
23+
],
24+
},
25+
"fallbackValue": false,
26+
},
27+
"test/feature_b": {
28+
"config": {
29+
"SOURCE": "RUNTIME",
30+
"TYPE": "number",
31+
},
32+
"fallbackValue": 1,
33+
},
34+
"test/feature_c": {
35+
"config": {
36+
"SOURCE": "RUNTIME",
37+
"TYPE": "string",
38+
},
39+
"fallbackValue": "best",
40+
},
41+
"test/feature_d": {
42+
"config": {
43+
"SOURCE": "RUNTIME",
44+
"TYPE": "boolean",
45+
"VALIDATIONS": [
46+
{
47+
"regex": "^(?:true)$",
48+
},
49+
],
50+
},
51+
"fallbackValue": true,
52+
},
53+
"test/feature_e": {
54+
"config": {
55+
"SOURCE": "RUNTIME",
56+
"TYPE": "number",
57+
"VALIDATIONS": [
58+
{
59+
"scopes": [
60+
"component",
61+
"layer",
62+
"tenant",
63+
],
64+
},
65+
{
66+
"regex": "^\\d{1}$",
67+
},
68+
],
69+
},
70+
"fallbackValue": 5,
71+
},
72+
"test/feature_f": {
73+
"config": {
74+
"SOURCE": "RUNTIME",
75+
"TYPE": "string",
76+
"VALIDATIONS": [
77+
{
78+
"regex": "^(?:best|worst)$",
79+
},
80+
],
81+
},
82+
"fallbackValue": "best",
83+
},
84+
"test/feature_g": {
85+
"config": {
86+
"ACTIVE": false,
87+
"SOURCE": "RUNTIME",
88+
"TYPE": "string",
89+
},
90+
"fallbackValue": "activeTest",
91+
},
92+
"test/feature_h": {
93+
"config": {
94+
"APP_URL": "\\.cfapps\\.sap\\.hana\\.ondemand\\.com$",
95+
"SOURCE": "RUNTIME",
96+
"TYPE": "string",
97+
},
98+
"fallbackValue": "appUrlTest",
99+
},
100+
}
101+
`;

0 commit comments

Comments
 (0)