Skip to content

Commit 8ef3a92

Browse files
committed
First test for custom-dir feature
1 parent 18b4760 commit 8ef3a92

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

test/configurations/myconf.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"info": "myconf-custom-dir",
3+
"database": {
4+
"host": "127.0.0.1",
5+
"user": "ENCRYPTED|28ddaa4fbf5eac1f9c7b050a8b82bf29|44d1ebbb6061a343ac5fc1372cbfcfc8",
6+
"password": "ENCRYPTED|7b78c16e0673ba6ecce5cff91295c80c|14f74d145744866f6da8ba503e08b123"
7+
},
8+
"filestorage": {
9+
"type": "local",
10+
"params": {
11+
"folder": "/tmp/storage",
12+
"storagepass": "ENCRYPTED|838bfe759ba8e81e406247dbbbabe734|b3a5dbb7630727173452fa81fff21c81"
13+
}
14+
},
15+
"testarray": [
16+
"one",
17+
"two",
18+
"three",
19+
{
20+
"arrayItemKey": "ENCRYPTED|02dde445bdf8a778d0c9e26ee3aaff9e|4cdbae5d24f59e9bb118da7a990d73c3",
21+
"additionalItem1": "value1"
22+
},
23+
{
24+
"arrayItemKey": "ENCRYPTED|425b976821766fab40a5139f5a5e432f|3d5154d7ed4c8ccb6f24edbcd2b8a035",
25+
"additionalItem1": "value1",
26+
"additionalItem2": 12
27+
},
28+
[
29+
{
30+
"subArrayItemKey": "ENCRYPTED|cbc2d78c8013012e31b77689a07856c3|6fe82c8c73e164e84f433e3acde6b02f9dddc22d33ec34144661c244d5ce53dc"
31+
}
32+
]
33+
],
34+
"nullvalue": null
35+
}

test/secure-config-multiconf.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
describe('secure-config multiconf feature test suite (v2 features)', () => {
24

35
const myconfKey = '11c4b6c3cdb7ebaff74a7a340d30c45fd2f7a49d6d0b56badb300dbe49f233ec';
@@ -95,4 +97,30 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
9597
expect(myconf.database.password).toBe('SecretPassword-Prod');
9698
});
9799

100+
it('tests a successful production configuration retrieval with custom file prefix and custom directory', () => {
101+
process.env['CONFIG_ENCRYPTION_KEY'] = myconfKey;
102+
const conf = require('../secure-config')({ prefix: 'myconf', directory: path.join(process.cwd(), 'test/configurations') });
103+
expect(conf.info).toEqual('myconf-custom-dir');
104+
expect(conf.database.host).toBe('127.0.0.1');
105+
expect(conf.database.user).toBe('SecretUser');
106+
expect(conf.database.password).toBe('SecretPassword');
107+
expect(conf.filestorage.type).toBe('local');
108+
expect(conf.filestorage.params.folder).toBe('/tmp/storage');
109+
expect(conf.filestorage.params.storagepass).toBe('StoragePassword');
110+
expect(conf.testarray).toBeDefined();
111+
expect(Array.isArray(conf.testarray)).toBeTruthy();
112+
expect(conf.testarray.length).toBe(6);
113+
expect(conf.testarray[0]).toEqual('one');
114+
expect(conf.testarray[1]).toEqual('two');
115+
expect(conf.testarray[2]).toEqual('three');
116+
expect(conf.testarray[3].arrayItemKey).toEqual('itemValue1');
117+
expect(conf.testarray[3].additionalItem1).toEqual('value1');
118+
expect(conf.testarray[4].arrayItemKey).toEqual('itemValue2');
119+
expect(conf.testarray[4].additionalItem1).toEqual('value1');
120+
expect(conf.testarray[4].additionalItem2).toEqual(12);
121+
expect(conf.testarray[5].length).toEqual(1);
122+
expect(conf.testarray[5][0].subArrayItemKey).toEqual('subArrayItemValue');
123+
expect(conf.nullvalue).toBe(null);
124+
});
125+
98126
});

0 commit comments

Comments
 (0)