Skip to content

Commit 8d8dde3

Browse files
committed
test: add tests for UserModule
1 parent d051dda commit 8d8dde3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/user.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import { SquareCloudAPI } from "../lib/index.js";
4+
5+
test("UserModule", async (t) => {
6+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
8+
await t.test("should get user information", async () => {
9+
const user = await client.users.get();
10+
11+
assert.ok(user);
12+
assert.ok(user.id);
13+
assert.ok(typeof user.email === "string");
14+
assert.ok(typeof user.name === "string");
15+
assert.ok(user.applications);
16+
assert.ok(user.applications.size >= 0);
17+
});
18+
19+
await t.test("should update cache on user fetch", async () => {
20+
const firstUser = await client.users.get();
21+
const cachedUser = client.cache.get("user");
22+
23+
assert.strictEqual(cachedUser?.id, firstUser.id);
24+
assert.strictEqual(cachedUser?.email, firstUser.email);
25+
});
26+
27+
await t.test("should emit userUpdate event", async () => {
28+
let emitted = false;
29+
const oldUser = client.cache.get("user");
30+
31+
client.on("userUpdate", (oldUserEvent, newUserEvent) => {
32+
assert.strictEqual(oldUserEvent, oldUser);
33+
assert.ok(newUserEvent);
34+
emitted = true;
35+
});
36+
37+
await client.users.get();
38+
assert.ok(emitted, "userUpdate event should have been emitted");
39+
});
40+
});

0 commit comments

Comments
 (0)