sendou.ink/app/utils/users.test.ts
Kalle e06f7177dd
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
Fix more various small bugs
2026-06-09 21:52:26 +03:00

76 lines
1.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
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,
});
});
test("gets id from url", () => {
expect(queryToUserIdentifier("https://sendou.ink/u/42")).toEqual({
id: 42,
});
});
});
describe("userDiscordIdIsAged()", () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2023-11-25T00:00:00.000Z"));
});
afterEach(() => {
vi.useRealTimers();
});
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("return false if discord id missing", () => {
expect(userDiscordIdIsAged({ discordId: "" })).toBe(false);
});
test("return false if discord id too short", () => {
expect(userDiscordIdIsAged({ discordId: "1234" })).toBe(false);
});
});