@autofleet/node-common 1.1.75 → 1.1.76
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/.npmignore +4 -0
- package/package.json +1 -1
- package/settings/index.js +7 -1
- package/settings/index.test.js +18 -0
package/.npmignore
ADDED
package/package.json
CHANGED
package/settings/index.js
CHANGED
|
@@ -82,7 +82,13 @@ class SettingsManager {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
this.networkEvents.emit(cacheKey, networkValue);
|
|
85
|
-
|
|
85
|
+
let returnValue;
|
|
86
|
+
try {
|
|
87
|
+
returnValue = SettingsManager.readNetworkValue(networkValue, defaultValue);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
this.settingsCache.del(cacheKey);
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
86
92
|
this.settingsCache.set(cacheKey, returnValue, this.ttl);
|
|
87
93
|
return returnValue;
|
|
88
94
|
}
|
package/settings/index.test.js
CHANGED
|
@@ -119,6 +119,24 @@ describe('Settings', () => {
|
|
|
119
119
|
.rejects.toEqual(new Error('Cannot find value from network or cache, default value is set to never'));
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
it('Throws an error if network error and no default value and success the next time', async (done) => {
|
|
123
|
+
const settings = new Settings({
|
|
124
|
+
serviceUrl: `http://${serviceUrl}/`,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const f = () => settings.get('key1', settings.NEVER_DEFAULT_VALUE);
|
|
128
|
+
expect(f())
|
|
129
|
+
.rejects.toEqual(new Error('Cannot find value from network or cache, default value is set to never'));
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
setTimeout(async () => {
|
|
133
|
+
const m = mockSetting('key1', 'value1');
|
|
134
|
+
expect(await settings.get('key1', settings.NEVER_DEFAULT_VALUE)).toEqual('value1');
|
|
135
|
+
expect(m.isDone());
|
|
136
|
+
done();
|
|
137
|
+
}, 100);
|
|
138
|
+
});
|
|
139
|
+
|
|
122
140
|
it('Values can be flushed', async () => {
|
|
123
141
|
const m1 = mockSetting('key1', 'value1');
|
|
124
142
|
const settings = new Settings({
|