Skip to content

Commit

Permalink
Simplefied test
Browse files Browse the repository at this point in the history
  • Loading branch information
Houwie7000 committed Dec 2, 2024
1 parent 0fcbd85 commit 67ddc35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
39 changes: 4 additions & 35 deletions Framework/Backend/test/mocha-ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,41 +232,10 @@ describe('websocket', () => {
});
});

it('Accept filter and log criteria', (done) => {
const connection = new WebSocketClient(`ws://localhost:${config.http.port}/?token=${token}`);

connection.on('open', () => {
const message = { command: 'filter',
token: token,
filter: function (returnCriteriasOnly = false) {
if (returnCriteriasOnly) {
return filters;
}
return;
}.toString() };
connection.send(JSON.stringify(message));
});

connection.on('message', (message) => {
const parsed = JSON.parse(message);
if (parsed.command == 'authed') {
return;
}
new WebSocketMessage().parse(message)
.then((parsed) => {
if (parsed.getCommand() == 'filter' && parsed.getPayload()) {
connection.filter = new Function(`return ${parsed.getPayload()}`)();
const criterias = this.minifyCriteria(connection.filter(message, true));
if (criterias != false) {
this.logger.debugMessage(`New live filter applied: ${JSON.stringify(criterias)}`);
assert.strictEqual(criterias, minifiedFilters);
}
}
});

connection.terminate();
done();
});
it('minifyCriteria() works as expected', (done) => {
const criterias = ws.minifyCriteria(filters);
assert.strictEqual(JSON.stringify(criterias), minifiedFilters);
done();
});

it('Request message broadcast with 200', (done) => {
Expand Down
4 changes: 3 additions & 1 deletion Framework/Backend/websocket/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ class WebSocket {
if (parsed.getCommand() == 'filter' && parsed.getPayload()) {
client.filter = new Function(`return ${parsed.getPayload()}`)();
const criterias = this.minifyCriteria(client.filter(message, true));
this.logger.debugMessage(JSON.stringify(criterias));
if (criterias != false) {
this.logger.debugMessage(`New live filter applied: ${JSON.stringify(criterias)}`);

Check warning on line 187 in Framework/Backend/websocket/server.js

View check run for this annotation

Codecov / codecov/patch

Framework/Backend/websocket/server.js#L185-L187

Added lines #L185 - L187 were not covered by tests
}
}
// 3. Get reply if callback exists
this.processRequest(parsed)
Expand Down

0 comments on commit 67ddc35

Please sign in to comment.