chore: refactor client sdk tests

This commit is contained in:
2023-03-03 11:42:20 +01:00
parent b61bf52df9
commit 0bb7f2cd85
8 changed files with 160 additions and 128 deletions

View File

@ -0,0 +1,49 @@
describe('Net Module', function () {
this.timeout(5000);
before(() => {
return Edge.connect();
});
after(() => {
Edge.disconnect();
});
it('should broadcast a message from server', function (done) {
const message = { test: 'broadcast', now: Date.now() };
const handler = (evt) => {
const receivedMessage = evt.detail;
if (receivedMessage.test !== 'broadcast') return;
chai.assert.deepEqual(message, evt.detail);
Edge.removeEventListener('message', handler);
done();
};
Edge.addEventListener("message", handler);
Edge.send(message);
});
it('should send a message to the server and echo back', function(done) {
const now = new Date();
const handler = evt => {
const receivedMessage = evt.detail;
if (receivedMessage.test !== 'echo') return;
chai.assert.equal(receivedMessage.now, now.toJSON());
Edge.removeEventListener('message', handler);
done();
}
// Server should echo back message
Edge.addEventListener('message', handler);
// Send message to server
Edge.send({ test: 'echo', now });
});
});