mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-02 19:26:50 -05:00
* Initial * Faster user page * Remove redundant function * Favorite badge sorting * Upgrade deps * Simplify entry.server * Bun tests initial * Update package.json npm -> bun * Update README * Type safe translations again * Don't load streams info for finalized tournaments * Translations as an object * More unit test work * Convert match.server.test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * Test & all done * Working cf * Bun GA try * No cache * spacing * spacing 2 * Add SQL logging * Remove NR * Hmm * Hmm 2 * Interesting * SKALOP_SYSTEM_MESSAGE_URL * . * . * ? * . * ? * Server.ts adjust * Downgrade Tldraw * E2E test fix * Fix lint
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import {
|
|
afterEach,
|
|
beforeEach,
|
|
describe,
|
|
expect,
|
|
setSystemTime,
|
|
test,
|
|
} from "bun:test";
|
|
import { queryToUserIdentifier, userDiscordIdIsAged } from "./users";
|
|
|
|
describe("queryToUserIdentifier()", () => {
|
|
test("returns null if no match", () => {
|
|
expect(queryToUserIdentifier("foo")).toBe(null);
|
|
});
|
|
|
|
test("gets custom url from url", () => {
|
|
expect(queryToUserIdentifier("https://sendou.ink/u/sendou")).toEqual({
|
|
customUrl: "sendou",
|
|
});
|
|
});
|
|
|
|
test("gets discord id from url", () => {
|
|
expect(
|
|
queryToUserIdentifier("https://sendou.ink/u/79237403620945920"),
|
|
).toEqual({
|
|
discordId: "79237403620945920",
|
|
});
|
|
});
|
|
|
|
test("gets custom url from url (without https://)", () => {
|
|
expect(queryToUserIdentifier("sendou.ink/u/sendou")).toEqual({
|
|
customUrl: "sendou",
|
|
});
|
|
});
|
|
|
|
test("gets discord id", () => {
|
|
expect(queryToUserIdentifier("79237403620945920")).toEqual({
|
|
discordId: "79237403620945920",
|
|
});
|
|
});
|
|
|
|
test("gets id", () => {
|
|
expect(queryToUserIdentifier("1")).toEqual({
|
|
id: 1,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("userDiscordIdIsAged()", () => {
|
|
beforeEach(() => {
|
|
setSystemTime(new Date("2023-11-25T00:00:00.000Z"));
|
|
});
|
|
|
|
afterEach(() => {
|
|
setSystemTime();
|
|
});
|
|
|
|
test("returns false if discord id is not aged", () => {
|
|
expect(userDiscordIdIsAged({ discordId: "1177730652641181871" })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("returns true if discord id is aged", () => {
|
|
expect(userDiscordIdIsAged({ discordId: "79237403620945920" })).toBe(true);
|
|
});
|
|
|
|
test("throws error if discord id missing", () => {
|
|
expect(() => userDiscordIdIsAged({ discordId: "" })).toThrow();
|
|
});
|
|
|
|
test("throws error if discord id too short", () => {
|
|
expect(() => userDiscordIdIsAged({ discordId: "1234" })).toThrow();
|
|
});
|
|
});
|