Skip to content

Commit

Permalink
Update ws server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacgr committed Jul 12, 2019
1 parent d62ea3b commit b567048
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
52 changes: 29 additions & 23 deletions tests/server/ws-server.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { expect } = require("chai");
const Jaysonic = require("../../src");

const { clientws, wstest } = require("../test-client");
const { clientws } = require("../test-client");

const wss = new Jaysonic.server.ws({ port: 9000 });
wss.method("add", ([a, b]) => a + b);
Expand Down Expand Up @@ -75,36 +75,42 @@ describe("WebSocket Server", () => {
});
});
it("should send 'parse error'", (done) => {
wstest.send("parse error");
wstest.onmessage = (event) => {
expect(event.data).to.eql(
`${JSON.stringify({
jsonrpc: "2.0",
error: { code: -32700, message: "Parse Error" },
id: null
})}\n`
);
done();
const wstest = new window.WebSocket("ws://127.0.0.1:9000");
wstest.onopen = () => {
wstest.send("parse error");
wstest.onmessage = (event) => {
expect(event.data).to.eql(
`${JSON.stringify({
jsonrpc: "2.0",
error: { code: -32700, message: "Parse Error" },
id: null
})}\n`
);
done();
};
};
});
it("should send 'invalid request' error", (done) => {
wstest.send(
`${JSON.stringify({
jsonrpc: "2.0",
method: 1,
params: [],
id: 69
})}\n`
);
wstest.onmessage = (event) => {
expect(event.data).to.eql(
const wstest = new window.WebSocket("ws://127.0.0.1:9000");
wstest.onopen = () => {
wstest.send(
`${JSON.stringify({
jsonrpc: "2.0",
error: { code: -32600, message: "Invalid Request" },
method: 1,
params: [],
id: 69
})}\n`
);
done();
wstest.onmessage = (event) => {
expect(event.data).to.eql(
`${JSON.stringify({
jsonrpc: "2.0",
error: { code: -32600, message: "Invalid Request" },
id: 69
})}\n`
);
done();
};
};
});
});
Expand Down
4 changes: 1 addition & 3 deletions tests/test-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ const clienthttp = new Jaysonic.client.http({ host: "127.0.0.1", port: 8000 });
const socket = new net.Socket();
const sock = new net.Socket();
const clientws = new WebSocket.wsclient({ url: "ws://127.0.0.1:9000" });
const wstest = new window.WebSocket("ws://127.0.0.1:9000");

module.exports = {
client,
clienthttp,
socket,
sock,
clientws,
wstest
clientws
};

0 comments on commit b567048

Please sign in to comment.