Skip to content

Commit

Permalink
auth: onChange test
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Dec 22, 2023
1 parent 0654bde commit 9ad16b2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/auth_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './util';
import assert from "assert";
import { Client, Room } from "../src";
import { AuthData } from '../src/Auth';

describe("Auth", function() {
let client: Client;
Expand All @@ -27,4 +28,20 @@ describe("Auth", function() {

});

describe("onChange", () => {
it("should trigger onChange when token is set", () => {
let onChangePayload: AuthData | undefined = undefined;
client.auth.onChange((data) => onChangePayload = data);
client.auth['emitChange']({ user: { dummy: true }, token: "123" });
assert.strictEqual("123", client.auth.token);
assert.strictEqual("123", client.http.authToken);

client.auth.onChange((data) => onChangePayload = data);
client.auth['emitChange']({ user: { dummy: true }, token: null } as any);
assert.strictEqual(null, client.auth.token);
assert.strictEqual(null, client.http.authToken);
});

});

});

0 comments on commit 9ad16b2

Please sign in to comment.