mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 23:58:36 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
99
apps/web-react/app/utils/users.test.ts
Normal file
99
apps/web-react/app/utils/users.test.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
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,
|
||||
});
|
||||
});
|
||||
|
||||
test("gets custom url from url with trailing slash", () => {
|
||||
expect(queryToUserIdentifier("https://sendou.ink/u/sendou/")).toEqual({
|
||||
customUrl: "sendou",
|
||||
});
|
||||
});
|
||||
|
||||
test("gets custom url from profile sub-page url", () => {
|
||||
expect(queryToUserIdentifier("https://sendou.ink/u/sendou/builds")).toEqual(
|
||||
{
|
||||
customUrl: "sendou",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("gets discord id from url with query string", () => {
|
||||
expect(
|
||||
queryToUserIdentifier(
|
||||
"https://sendou.ink/u/79237403620945920?utm_source=discord",
|
||||
),
|
||||
).toEqual({
|
||||
discordId: "79237403620945920",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user