@pryv/monitor 3.13.0 → 3.15.0
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
CHANGED
package/src/lib/updateStreams.js
CHANGED
|
@@ -7,7 +7,10 @@ const Changes = require('./Changes');
|
|
|
7
7
|
module.exports = async function _updateStreams (monitor) {
|
|
8
8
|
try {
|
|
9
9
|
const result = await monitor.connection.get('streams');
|
|
10
|
-
if (!result.streams) {
|
|
10
|
+
if (!result.streams) {
|
|
11
|
+
// The answer rides on `innerObject`, never in the message (it holds stream data).
|
|
12
|
+
throw Object.assign(new Error('Invalid streams.get answer: no streams'), { innerObject: result });
|
|
13
|
+
}
|
|
11
14
|
monitor.emit(Changes.STREAMS, result.streams);
|
|
12
15
|
} catch (e) {
|
|
13
16
|
monitor.emit(Changes.ERROR, e);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
5
|
+
/* global describe, it, expect */
|
|
6
|
+
|
|
7
|
+
require('./load-helpers');
|
|
8
|
+
const Changes = require('../src/lib/Changes');
|
|
9
|
+
const updateStreams = require('../src/lib/updateStreams');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* [MUSX] A `streams.get` answer without streams is reported without its
|
|
13
|
+
* content in the message (stream names and clientData), on `innerObject`
|
|
14
|
+
* instead. A fake monitor: no server.
|
|
15
|
+
*/
|
|
16
|
+
describe('[MUSX] updateStreams with an invalid answer', function () {
|
|
17
|
+
it('[MUS1] emits an error whose message leaves the answer out', async function () {
|
|
18
|
+
const SECRET = 'S3CRET-stream-name';
|
|
19
|
+
const answer = { error: { id: 'unknown-error', message: 'x' }, streams_partial: [{ name: SECRET }] };
|
|
20
|
+
const emitted = [];
|
|
21
|
+
const monitor = {
|
|
22
|
+
connection: { get: async () => answer },
|
|
23
|
+
emit: (type, value) => emitted.push({ type, value })
|
|
24
|
+
};
|
|
25
|
+
await updateStreams(monitor);
|
|
26
|
+
expect(emitted).to.have.length(1);
|
|
27
|
+
expect(emitted[0].type).to.equal(Changes.ERROR);
|
|
28
|
+
expect(emitted[0].value.message).to.equal('Invalid streams.get answer: no streams');
|
|
29
|
+
expect(emitted[0].value.message).to.not.include(SECRET);
|
|
30
|
+
expect(emitted[0].value.innerObject).to.equal(answer);
|
|
31
|
+
});
|
|
32
|
+
});
|