af3c24275d
- Backend: NestJS 10 + TypeORM (better-sqlite3) feature-modular layout.
- Entities: user, setting, category, challenge, challenge_file, solve,
refresh_token, blog_post. Auto-run migrations + idempotent 6-system-
category seed on startup.
- Argon2id password hashing with policy check; JWT access + rotating
refresh tokens (HttpOnly cookie); CSRF middleware (SameSite + custom
X-CSRF-Token header); global JWT auth guard with @Public() opt-out;
per-IP login backoff + per-IP registration rate limit.
- Endpoints: auth (login/refresh/logout/csrf), users (first-admin
registration), system (bootstrap/event status/SSE), admin (guarded
user CRUD with last-admin invariant), frontend module (uploads +
SPA fallback).
- Security: helmet+CSP+HSTS-gated-by-TLS, CORS allowlist, structured
global exception filter, Zod request validation pipes, OpenAPI 3.1
served at /api/docs and /api/docs-json, 10 canonical themes under
backend/themes/.
- Frontend: Angular 17 standalone components, lazy-loaded feature routes,
signals, functional HttpInterceptorFn (csrf + auth), functional
CanActivateFn auth guard, HttpOnly-cookie-based auth service.
- Tests: Jest + supertest, 46 tests across 13 suites covering
migrations, env schema, theme loader, event status, login backoff,
registration rate limit, ApiError shape, bootstrap integration,
auth refresh rotation, admin guard, last-admin invariant, SSE flat
payloads. Single-command runner: `npm test`.
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { EventStatusService } from '../../backend/src/common/services/event-status.service';
|
|
|
|
describe('EventStatusService', () => {
|
|
const settings = {
|
|
get: jest.fn(),
|
|
} as any;
|
|
|
|
beforeEach(() => {
|
|
settings.get.mockReset();
|
|
});
|
|
|
|
it('returns Stopped before start with positive countdown', async () => {
|
|
const start = new Date(Date.now() + 60_000).toISOString();
|
|
const end = new Date(Date.now() + 120_000).toISOString();
|
|
settings.get.mockImplementation(async (k: string) => (k === 'eventStartUtc' ? start : end));
|
|
const svc = new EventStatusService(settings);
|
|
const s = await svc.getStatus();
|
|
expect(s.status).toBe('Stopped');
|
|
expect(s.countdownMs).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('returns Running between start and end', async () => {
|
|
const start = new Date(Date.now() - 30_000).toISOString();
|
|
const end = new Date(Date.now() + 60_000).toISOString();
|
|
settings.get.mockImplementation(async (k: string) => (k === 'eventStartUtc' ? start : end));
|
|
const svc = new EventStatusService(settings);
|
|
const s = await svc.getStatus();
|
|
expect(s.status).toBe('Running');
|
|
expect(s.countdownMs).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('returns Stopped after end with zero countdown', async () => {
|
|
const start = new Date(Date.now() - 120_000).toISOString();
|
|
const end = new Date(Date.now() - 60_000).toISOString();
|
|
settings.get.mockImplementation(async (k: string) => (k === 'eventStartUtc' ? start : end));
|
|
const svc = new EventStatusService(settings);
|
|
const s = await svc.getStatus();
|
|
expect(s.status).toBe('Stopped');
|
|
expect(s.countdownMs).toBe(0);
|
|
});
|
|
}); |