@autofleet/node-common 1.1.21 → 1.1.22
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/events/index.js +5 -1
- package/package.json +1 -1
- package/settings/index.js +4 -0
- package/settings/index.test.js +12 -0
package/events/index.js
CHANGED
|
@@ -7,8 +7,12 @@ const publish = (eventType, eventObj, debug = false) => {
|
|
|
7
7
|
const projectId = process.env.PROJECT;
|
|
8
8
|
const topic = process.env.TOPIC;
|
|
9
9
|
|
|
10
|
+
if (!topic || !projectId) {
|
|
11
|
+
return 'Missing project/topic';
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
if (envv === 'development' && !debug) {
|
|
11
|
-
return '
|
|
15
|
+
return 'Not publishing in dev';
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
const pubsubClient = new PubSub({ projectId });
|
package/package.json
CHANGED
package/settings/index.js
CHANGED
|
@@ -27,6 +27,10 @@ module.exports = class SettingsManager {
|
|
|
27
27
|
throw new Error('Can\'t get a key without defaultValue');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
if (process.env.NODE_ENV === 'test') {
|
|
31
|
+
return defaultValue;
|
|
32
|
+
}
|
|
33
|
+
|
|
30
34
|
const cacheKey = `${key}_${JSON.stringify(labels)}`;
|
|
31
35
|
const cacheValue = this.settingsCache.get(cacheKey);
|
|
32
36
|
if (cacheValue !== undefined) {
|
package/settings/index.test.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const nock = require('nock');
|
|
2
2
|
const Settings = require('./index');
|
|
3
3
|
|
|
4
|
+
process.env.NODE_ENV = 'node-common-test';
|
|
5
|
+
|
|
4
6
|
const serviceUrl = 'localhost:8085';
|
|
5
7
|
|
|
6
8
|
const mockSetting = (key, value, labels, response = 200) => nock(`http://${serviceUrl}/`)
|
|
@@ -107,4 +109,14 @@ describe('Settings', () => {
|
|
|
107
109
|
expect(value2).toEqual('value2');
|
|
108
110
|
expect(m2.isDone()).toBeTruthy();
|
|
109
111
|
});
|
|
112
|
+
it('when NODE_ENV === test return the default value', async () => {
|
|
113
|
+
process.env.NODE_ENV = 'test';
|
|
114
|
+
const settings = new Settings({
|
|
115
|
+
serviceUrl: `http://${serviceUrl}/`,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const value = await settings.get('key1', 'dv');
|
|
119
|
+
expect(value).toEqual('dv');
|
|
120
|
+
process.env.NODE_ENV = 'node-common-test';
|
|
121
|
+
});
|
|
110
122
|
});
|