Skip to content

Commit

Permalink
Test for custom-dir feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmx committed Sep 4, 2024
1 parent 8ef3a92 commit 0316a98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/configurations/config-production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"info": "production-custom-dir",
"database": {
"host": "db.prod.com",
"user": "ENCRYPTED|5cf569c8229d05034f173119795158fd|1d71ad3d86e402d2ebb8b2a1ef796862",
"password": "ENCRYPTED|9a4e5fdbbfe10b1d2b81a9ec9d46c6d1|95bf57f6ef988b80fa75577ed2da04c3b4549ac2de03c45fbbb8b4033b58b415"
},
"filestorage": {
"type": "local",
"params": {
"folder": "/tmp/storage",
"storagepass": "ENCRYPTED|7a7e87414b68919f70604e9e71d38f52|872dba2abe6f3a4bc4fa89b93234a86fbb4577f4ba5aa89949e4e4d0b16111e2"
}
},
"testarray": [
{
"arrayItemKey": "ENCRYPTED|ad271fa483d82796e021a9c199e8b52b|420cf1c6e90590fa360a1a6fe8fb559c"
},
{
"arrayItemKey": "ENCRYPTED|33ef4527795eafd1019bc9d00d4a4ad2|e2aa1207886da4fcc33916610d082d4b"
}
]
}
17 changes: 17 additions & 0 deletions test/secure-config-multiconf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
expect(myconf.database.password).toBe('SecretPassword-Prod');
});

it('tests a successful production configuration retrieval with custom directory', () => {
process.env['CONFIG_ENCRYPTION_KEY'] = confKey;
process.env['NODE_ENV'] = 'production';
const conf = require('../secure-config')({ directory: path.join(process.cwd(), 'test/configurations') });
expect(conf.info).toEqual('production-custom-dir');
expect(conf.database.host).toBe('db.prod.com');
expect(conf.database.user).toBe('SecretUser-Prod');
expect(conf.database.password).toBe('SecretPassword-Prod');
expect(conf.filestorage.type).toBe('local');
expect(conf.filestorage.params.folder).toBe('/tmp/storage');
expect(conf.filestorage.params.storagepass).toBe('StoragePassword-Prod');
expect(conf.testarray.length).toEqual(2);
expect(conf.testarray[0].arrayItemKey).toEqual('itemValue1');
expect(conf.testarray[1].arrayItemKey).toEqual('itemValue2');

});

it('tests a successful production configuration retrieval with custom file prefix and custom directory', () => {
process.env['CONFIG_ENCRYPTION_KEY'] = myconfKey;
const conf = require('../secure-config')({ prefix: 'myconf', directory: path.join(process.cwd(), 'test/configurations') });
Expand Down

0 comments on commit 0316a98

Please sign in to comment.