feat: enhance auction interactions and player statistics UI
This commit is contained in:
1 parent
6c582ba3cf
commit
be4de61bb7
115 files changed
+13292
-2871
No files matched your search
@@ -0,0 +1,88 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
appendAuctionReaction,
|
||||
isAuctionReaction,
|
||||
MAX_VISIBLE_REACTIONS,
|
||||
REACTION_LIFETIME_MS,
|
||||
sendAuctionReaction,
|
||||
} from "../src/api/auction-reactions.ts";
|
||||
|
||||
const reaction = {
|
||||
id: "reaction-1",
|
||||
kind: "clap" as const,
|
||||
displayName: "팀장",
|
||||
sentAt: 1000,
|
||||
};
|
||||
|
||||
test("rejects unsupported or malformed realtime reactions", () => {
|
||||
assert.equal(isAuctionReaction(reaction), true);
|
||||
for (const value of [
|
||||
null,
|
||||
{},
|
||||
{ ...reaction, kind: "__proto__" },
|
||||
{ ...reaction, kind: "custom" },
|
||||
{ ...reaction, id: "" },
|
||||
{ ...reaction, sentAt: Infinity },
|
||||
{ ...reaction, displayName: "a".repeat(161) },
|
||||
]) {
|
||||
assert.equal(isAuctionReaction(value), false);
|
||||
}
|
||||
});
|
||||
|
||||
test("deduplicates the broadcast and acknowledgement and caps simultaneous effects", () => {
|
||||
const first = appendAuctionReaction([], reaction, 1000);
|
||||
assert.deepEqual(appendAuctionReaction(first, reaction, 1100), first);
|
||||
let current = first;
|
||||
for (let index = 0; index < 40; index++) {
|
||||
current = appendAuctionReaction(
|
||||
current,
|
||||
{ ...reaction, id: String(index) },
|
||||
1200,
|
||||
);
|
||||
}
|
||||
assert.equal(current.length, MAX_VISIBLE_REACTIONS);
|
||||
assert.equal(current.at(-1)?.id, "39");
|
||||
});
|
||||
|
||||
test("expires by local receipt time even when the server clock differs", () => {
|
||||
const first = appendAuctionReaction(
|
||||
[],
|
||||
{ ...reaction, sentAt: 9_999_999 },
|
||||
1000,
|
||||
);
|
||||
const next = appendAuctionReaction(
|
||||
first,
|
||||
{ ...reaction, id: "next" },
|
||||
1000 + REACTION_LIFETIME_MS,
|
||||
);
|
||||
assert.deepEqual(
|
||||
next.map((value) => value.id),
|
||||
["next"],
|
||||
);
|
||||
});
|
||||
|
||||
test("only accepts valid server acknowledgements and explains unavailable sends", async () => {
|
||||
assert.equal(
|
||||
await sendAuctionReaction(async () => ({ ok: true, reaction })),
|
||||
reaction,
|
||||
);
|
||||
await assert.rejects(sendAuctionReaction(undefined), /연결되면/);
|
||||
await assert.rejects(
|
||||
sendAuctionReaction(async () => ({
|
||||
ok: false,
|
||||
code: "REACTION_RATE_LIMITED",
|
||||
})),
|
||||
/기다렸다가/,
|
||||
);
|
||||
await assert.rejects(
|
||||
sendAuctionReaction(async () => {
|
||||
throw new Error("timeout");
|
||||
}),
|
||||
/보내지 못했습니다/,
|
||||
);
|
||||
await assert.rejects(
|
||||
sendAuctionReaction(async () => ({ ok: true })),
|
||||
/보내지 못했습니다/,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user