diff --git a/app/api/student/resume/confirm/route.theme-contrast.test.ts b/app/api/student/resume/confirm/route.theme-contrast.test.ts index 6279396f2..9c6325a22 100644 --- a/app/api/student/resume/confirm/route.theme-contrast.test.ts +++ b/app/api/student/resume/confirm/route.theme-contrast.test.ts @@ -1,6 +1,14 @@ import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest'; import { POST } from './route'; +vi.mock('@/lib/github-owner-verification', () => ({ + verifyGitHubOwner: vi.fn().mockResolvedValue({ + verified: true, + status: 200, + message: 'OK', + }), +})); + vi.mock('@/lib/mongodb', () => ({ default: vi.fn(), })); diff --git a/components/dashboard/StatsCard.test.tsx b/components/dashboard/StatsCard.test.tsx index 68cc9cae8..7b511c190 100644 --- a/components/dashboard/StatsCard.test.tsx +++ b/components/dashboard/StatsCard.test.tsx @@ -1,26 +1,15 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unused-vars */ + import { describe, it, expect, vi, beforeEach } from 'vitest'; import { render, screen } from '@testing-library/react'; import StatsCard from './StatsCard'; // Mock framer-motion + vi.mock('framer-motion', () => ({ motion: { - div: ({ - children, - whileHover, - whileTap, - whileInView, - initial, - animate, - exit, - transition, - viewport, - layoutId, - ...props - }: any) => ( -
+ div: ({ children, ...rest }: any) => ( +
{children}
), diff --git a/lib/cache.ts b/lib/cache.ts index 64f218bea..edbcedbb9 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -8,7 +8,6 @@ type CacheItem = { value: T; expiresAt: number; }; - /** * A Simple in-memory TTL(Time To Live) cache. * @@ -18,16 +17,21 @@ type CacheItem = { * @typeParam T - Type of values stored in the cache. */ export class TTLCache { + //private store = new Map>(); + private store = new Map>(); + private cleanupInterval: ReturnType | null = null; private readonly maxSize?: number; - private static assertValidKey(key: unknown): asserts key is string { if (typeof key !== 'string') { throw new TypeError('Cache key must be a string'); } - } + if (key.trim().length === 0) { + throw new TypeError('Cache key cannot be empty'); + } + } /** * Creates a new TTL cache instance. * @@ -109,7 +113,14 @@ export class TTLCache { * const user = cache.get("user:1"); */ get(key: string): T | null { - TTLCache.assertValidKey(key); + //TTLCache.assertValidKey(key); + if (key === null || key === undefined) { + throw new TypeError('Cache key must be a string'); + } + + if (typeof key !== 'string') { + throw new TypeError('Cache key must be a string'); + } const hit = this.store.get(key); if (!hit) return null; @@ -136,7 +147,14 @@ export class TTLCache { * } */ has(key: string): boolean { - TTLCache.assertValidKey(key); + //TTLCache.assertValidKey(key); + if (key === null || key === undefined) { + throw new TypeError('Cache key must be a string'); + } + + if (typeof key !== 'string') { + throw new TypeError('Cache key must be a string'); + } const hit = this.store.get(key); if (!hit) return false; @@ -203,8 +221,11 @@ export class TTLCache { } set(key: string, value: T, ttlMs: number): void { - TTLCache.assertValidKey(key); - if (key === '') throw new Error('Cache key cannot be empty'); + //TTLCache.assertValidKey(key); + if (typeof key !== 'string' || key.trim().length === 0) { + throw new TypeError('Cache key cannot be empty'); + } + if (ttlMs <= 0) throw new RangeError(`ttlMs must be positive, got ${ttlMs}`); if (Number.isNaN(ttlMs)) ttlMs = 60_000;