Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
network: make auth test not run assertions after the end
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov committed Mar 2, 2021
1 parent d5fb550 commit dfc2e43
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/network/websockets/server/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import { makeWsMock } from "./ws-mock";

test.cb("websocket server allows to read and write when auth allows", (t) => {
const ws = makeWsMock();
let seenCorrectCanRead = false;
let seenCorrectCanWrite = false;
let seenCorrectParseToken = false;
runWebsocketServer({
auth: {
canRead: ({ auth, kind, id }) => {
t.is(kind, "tasks");
t.is(id, "1");
t.is(auth, "john");
if (kind === "tasks" && id === "1" && auth === "john")
seenCorrectCanRead = true;
return true;
},
canWrite: ({ auth, kind, id }) => {
t.is(kind, "tasks");
t.is(id, "1");
t.is(auth, "john");
if (kind === "tasks" && id === "1" && auth === "john")
seenCorrectCanWrite = true;
return true;
},
parseToken: async (token) => {
t.is(token, "t1");
if (token === "t1") seenCorrectParseToken = true;
return "john";
},
},
Expand All @@ -31,6 +32,9 @@ test.cb("websocket server allows to read and write when auth allows", (t) => {
});
const client = ws.client((msg) => {
if (msg.action === "pushResult" && msg.newRevision === "2") {
t.true(seenCorrectCanRead);
t.true(seenCorrectCanWrite);
t.true(seenCorrectParseToken);
t.end();
}
});
Expand Down

0 comments on commit dfc2e43

Please sign in to comment.