fe6bb3290e
Server: - Jest unit testy (88 testů): auth, utils, restaurants, service, voting, pizza - in-memory storage mock pro izolaci testů - oprava race condition při inicializaci Redis (storageReady promise) - dev route dostupná i pro NODE_ENV=test - getStatsMock deterministický (nahrazení Math.random) - exporty interních helperů pro testovatelnost - /api/health endpoint pro Playwright readiness check - tsconfig vylučuje test soubory z produkčního buildu E2E (e2e/): - Playwright s Firefoxem + Chromiem - testy: login, menu, výběr jídla, pizza day životní cyklus, QR/nastavení - trusted-header auth bypass pro testy, video + trace při selhání CI (Woodpecker): - pipeline spouštěna na všech větvích a PR (nejen master) - redis-stack-server service pro E2E – čistý Redis per větev automaticky - kroky: unit testy, build, E2E testy (parallel kde možné) - Docker build zůstává pouze pro master Co-Authored-By: Claude Opus (extra usage) 4.7 <noreply@anthropic.com>
34 lines
944 B
TypeScript
34 lines
944 B
TypeScript
import { RedisClientType, createClient } from 'redis';
|
|
import { StorageInterface } from "./StorageInterface";
|
|
|
|
let client: RedisClientType;
|
|
|
|
/**
|
|
* Implementace úložiště využívající Redis server.
|
|
*/
|
|
export default class RedisStorage implements StorageInterface {
|
|
constructor() {
|
|
const HOST = process.env.REDIS_HOST ?? 'localhost';
|
|
const PORT = process.env.REDIS_PORT ?? 6379;
|
|
client = createClient({ url: `redis://${HOST}:${PORT}` });
|
|
}
|
|
|
|
async initialize() {
|
|
await client.connect();
|
|
}
|
|
|
|
async hasData(key: string) {
|
|
const data = await client.json.get(key);
|
|
return (!!data);
|
|
}
|
|
|
|
async getData<Type>(key: string) {
|
|
const data = await client.json.get(key, { path: '.' });
|
|
return data as Type;
|
|
}
|
|
|
|
async setData<Type>(key: string, data: Type) {
|
|
await client.json.set(key, '.', data as any);
|
|
await client.json.get(key);
|
|
}
|
|
} |