@autofleet/node-common 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/settings/example.js +1 -1
- package/settings/index.js +2 -2
- package/settings/index.test.js +20 -0
package/package.json
CHANGED
package/settings/example.js
CHANGED
package/settings/index.js
CHANGED
|
@@ -8,7 +8,7 @@ require('dotenv').config();
|
|
|
8
8
|
const fiveMinutes = 60 * 5;
|
|
9
9
|
|
|
10
10
|
module.exports = class SettingsManager {
|
|
11
|
-
constructor({ serviceUrl, ttl = fiveMinutes }) {
|
|
11
|
+
constructor({ serviceUrl, ttl = fiveMinutes } = {}) {
|
|
12
12
|
const localServiceUrl = serviceUrl || process.env.SETTING_MS_SERVICE_HOST;
|
|
13
13
|
|
|
14
14
|
this.ttl = ttl;
|
|
@@ -31,7 +31,7 @@ module.exports = class SettingsManager {
|
|
|
31
31
|
|
|
32
32
|
let networkValue;
|
|
33
33
|
try {
|
|
34
|
-
const networkReponse = await this.network.get(`/api/v1/
|
|
34
|
+
const networkReponse = await this.network.get(`/api/v1/settings/get-setting/${key}`, {
|
|
35
35
|
params: {
|
|
36
36
|
labels,
|
|
37
37
|
},
|
package/settings/index.test.js
CHANGED
|
@@ -9,6 +9,26 @@ const mockSetting = (key, value, labels, response = 200) => nock(serviceUrl)
|
|
|
9
9
|
.reply(response, { value });
|
|
10
10
|
|
|
11
11
|
describe('Settings', () => {
|
|
12
|
+
it('Throws exeption if there is no defualt value', async () => {
|
|
13
|
+
const settings = new Settings({
|
|
14
|
+
serviceUrl,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(settings.get('key1'))
|
|
18
|
+
.rejects.toEqual(new Error('Can\'t get a key without defaultValue'));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('Uses env.SETTING_MS_SERVICE_HOST as serivce host if no one defind', async () => {
|
|
22
|
+
const m = mockSetting('key1', 'value1');
|
|
23
|
+
process.env.SETTING_MS_SERVICE_HOST = serviceUrl;
|
|
24
|
+
const settings = new Settings();
|
|
25
|
+
|
|
26
|
+
const value = await settings.get('key1', 'dv');
|
|
27
|
+
expect(value).toEqual('value1');
|
|
28
|
+
expect(m.isDone()).toBeTruthy();
|
|
29
|
+
process.env.SETTING_MS_SERVICE_HOST = '';
|
|
30
|
+
});
|
|
31
|
+
|
|
12
32
|
it('Get a key from server', async () => {
|
|
13
33
|
const m = mockSetting('key1', 'value1');
|
|
14
34
|
const settings = new Settings({
|