feat: večeře (extra meal slot) — dokončení, sync s masterem
CI / Generate TypeScript types (push) Successful in 34s
CI / Build server (push) Successful in 33s
CI / Server unit tests (push) Successful in 1m11s
CI / Build client (push) Successful in 33s
CI / Playwright E2E tests (push) Successful in 1m20s
CI / Build and push Docker image (push) Has been skipped
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 34s
CI / Build server (push) Successful in 33s
CI / Server unit tests (push) Successful in 1m11s
CI / Build client (push) Successful in 33s
CI / Playwright E2E tests (push) Successful in 1m20s
CI / Build and push Docker image (push) Has been skipped
CI / Notify (push) Successful in 2s
- Nová stránka /vecere pro evidenci extra jídla (večeře/pozdní oběd) - MealSlot enum (obed/extra), oddělený storage namespace YYYY-MM-DD_extra - slot parametr na všech food endpointech a GET /api/data - Push reminder: přechod na 60min cooldown, login v payloadu místo endpointu - Smazány chybně přidané root package.json + package-lock.json (gitnexus) - server: slot?: string → slot?: MealSlot, literály nahrazeny enum konstantami - Přidány Jest testy izolace extra/obed storage namespace
This commit is contained in:
@@ -43,4 +43,8 @@
|
||||
# Vygenerovat pomocí: npx web-push generate-vapid-keys
|
||||
# VAPID_PUBLIC_KEY=
|
||||
# VAPID_PRIVATE_KEY=
|
||||
# VAPID_SUBJECT=mailto:admin@example.com
|
||||
# VAPID_SUBJECT=mailto:admin@example.com
|
||||
|
||||
# Heslo pro bypass rate limitu na endpointu /api/food/refresh (pro skripty/admin).
|
||||
# Bez hesla může refresh volat každý přihlášený uživatel (podléhá rate limitu).
|
||||
# REFRESH_BYPASS_PASSWORD=
|
||||
@@ -2,6 +2,7 @@
|
||||
/dist
|
||||
/resources/easterEggs
|
||||
/src/gen
|
||||
/coverage
|
||||
.env.production
|
||||
.env.development
|
||||
.easter-eggs.json
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"Zimní atmosféra",
|
||||
"Skrytí podniku U Motlíků"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Přidání restaurace Zastávka u Michala"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Přidání restaurace Pivovarský šenk Šeříková"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Možnost výběru podniku/jídla kliknutím"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Stránka se statistikami nejoblíbenějších voleb"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Zobrazení počtu osob u každé volby"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Migrace na generované OpenApi"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Odebrání zimní atmosféry"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Možnost ručního přenačtení menu"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Parsování a zobrazení alergenů"
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"Oddělení přenačtení menu do vlastního dialogu",
|
||||
"Podzimní atmosféra"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Možnost převzetí poznámky ostatních uživatelů"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Zimní atmosféra"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Možnost označit se jako objednávající u volby \"Budu objednávat\""
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Podpora dark mode"
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"Redesign aplikace pomocí Claude Code",
|
||||
"Zobrazení uplynulého týdne i o víkendu",
|
||||
"Podpora Discord, ntfy a Teams notifikací (v Nastavení)",
|
||||
"Trvalé zobrazení QR kódů do ručního zavření",
|
||||
"Zobrazení nejvíce požadovaných funkcí (na stránce Statistiky)"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Zobrazení sekce Pizza day pouze při volbě \"Pizza day\""
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Možnost generování obecných QR kódů pro platby i mimo Pizza day (v uživatelském menu)"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Podpora push notifikací pro připomenutí výběru oběda (v nastavení)"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Oprava detekce zastaralého menu"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Automatické zobrazení dialogu s dosud nezobrazenými novinkami"
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Automatický výběr výchozího času preferovaného odchodu"
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['<rootDir>/src/**/*.test.ts'],
|
||||
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
|
||||
setupFiles: ['<rootDir>/src/tests/setupEnv.ts'],
|
||||
};
|
||||
@@ -19,10 +19,12 @@
|
||||
"@types/jsonwebtoken": "^9.0.10",
|
||||
"@types/node": "^24.10.0",
|
||||
"@types/request-promise": "^4.1.48",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@types/web-push": "^3.6.4",
|
||||
"babel-jest": "^30.2.0",
|
||||
"jest": "^30.2.0",
|
||||
"nodemon": "^3.1.10",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
|
||||
+42
-3
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import { load } from 'cheerio';
|
||||
import { getPizzaListMock } from './mock';
|
||||
import { getPizzaListMock, getSalatListMock } from './mock';
|
||||
import { Salat } from '../../types/gen/types.gen';
|
||||
|
||||
// TODO přesunout do types
|
||||
type PizzaSize = {
|
||||
@@ -20,7 +21,8 @@ type Pizza = {
|
||||
|
||||
// TODO mělo by být konfigurovatelné proměnnou z prostředí s tímhle jako default
|
||||
const baseUrl = 'https://www.pizzachefie.cz';
|
||||
const pizzyUrl = `${baseUrl}/pizzy.html?pobocka=plzen`;
|
||||
const pizzyUrl = `${baseUrl}/pizzy.html`;
|
||||
const salayUrl = `${baseUrl}/salaty.html`;
|
||||
|
||||
const buildPizzaUrl = (pizzaUrl: string) => {
|
||||
return `${baseUrl}/${pizzaUrl}`;
|
||||
@@ -34,9 +36,12 @@ const boxPrices: { [key: string]: number } = {
|
||||
"50cm": 25
|
||||
}
|
||||
|
||||
// Cena obalu pro salát
|
||||
const SALAT_BOX_PRICE = 13;
|
||||
|
||||
/**
|
||||
* Stáhne a scrapne aktuální pizzy ze stránek Pizza Chefie.
|
||||
*
|
||||
*
|
||||
* @param mock zda vrátit pouze mock data
|
||||
*/
|
||||
export async function downloadPizzy(mock: boolean): Promise<Pizza[]> {
|
||||
@@ -84,4 +89,38 @@ export async function downloadPizzy(mock: boolean): Promise<Pizza[]> {
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stáhne a scrapne aktuální saláty ze stránek Pizza Chefie.
|
||||
* Příplatek za obal je pro každý salát pevně 13 Kč.
|
||||
*
|
||||
* @param mock zda vrátit pouze mock data
|
||||
*/
|
||||
export async function downloadSalaty(mock: boolean): Promise<Salat[]> {
|
||||
if (mock) {
|
||||
return new Promise((resolve) => setTimeout(() => resolve(getSalatListMock()), 1000));
|
||||
}
|
||||
const html = await axios.get(salayUrl).then(res => res.data);
|
||||
const $ = load(html);
|
||||
const links = $('.vypisproduktu > div > h4 > a');
|
||||
const urls = [];
|
||||
for (const element of links) {
|
||||
if (element.name === 'a' && element.attribs?.href) {
|
||||
urls.push(buildPizzaUrl(element.attribs.href));
|
||||
}
|
||||
}
|
||||
const result: Salat[] = [];
|
||||
for (const url of urls) {
|
||||
const salatHtml = await axios.get(url).then(res => res.data);
|
||||
const name = $('.produkt > h2', salatHtml).first().text().trim();
|
||||
const ingredients: string[] = [];
|
||||
$('.prisady > li', salatHtml).each((i, elm) => {
|
||||
ingredients.push($(elm).text());
|
||||
});
|
||||
const priceText = $('.cena > span', salatHtml).first().text().trim();
|
||||
const price = Number.parseInt(priceText.split(' Kč')[0]);
|
||||
result.push({ name, ingredients, price: price + SALAT_BOX_PRICE });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
+22
-9
@@ -2,6 +2,7 @@ import express from "express";
|
||||
import bodyParser from "body-parser";
|
||||
import cors from 'cors';
|
||||
import { getData, getDateForWeekIndex, getToday } from "./service";
|
||||
import { MealSlot } from "../../types/gen/types.gen";
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { getQr } from "./qr";
|
||||
@@ -10,6 +11,7 @@ import { getIsWeekend, InsufficientPermissions, PizzaDayConflictError, parseToke
|
||||
import { getPendingQrs } from "./pizza";
|
||||
import { initWebsocket } from "./websocket";
|
||||
import { startReminderScheduler } from "./pushReminder";
|
||||
import { storageReady } from "./storage";
|
||||
import pizzaDayRoutes from "./routes/pizzaDayRoutes";
|
||||
import foodRoutes, { refreshMetoda } from "./routes/foodRoutes";
|
||||
import votingRoutes from "./routes/votingRoutes";
|
||||
@@ -18,6 +20,7 @@ import statsRoutes from "./routes/statsRoutes";
|
||||
import notificationRoutes from "./routes/notificationRoutes";
|
||||
import qrRoutes from "./routes/qrRoutes";
|
||||
import devRoutes from "./routes/devRoutes";
|
||||
import changelogRoutes from "./routes/changelogRoutes";
|
||||
|
||||
const ENVIRONMENT = process.env.NODE_ENV ?? 'production';
|
||||
dotenv.config({ path: path.resolve(__dirname, `../.env.${ENVIRONMENT}`) });
|
||||
@@ -55,6 +58,10 @@ if (HTTP_REMOTE_USER_ENABLED) {
|
||||
|
||||
// ----------- Metody nevyžadující token --------------
|
||||
|
||||
app.get("/api/health", (_req, res) => {
|
||||
res.status(200).json({ ok: true });
|
||||
});
|
||||
|
||||
app.get("/api/whoami", (req, res) => {
|
||||
if (!HTTP_REMOTE_USER_ENABLED) {
|
||||
res.status(403).json({ error: 'Není zapnuté přihlášení z hlaviček' });
|
||||
@@ -86,12 +93,15 @@ app.post("/api/login", (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// TODO dočasné řešení - QR se zobrazuje přes <img>, nemáme sem jak dostat token
|
||||
app.get("/api/qr", (req, res) => {
|
||||
// QR se zobrazuje přes <img>, nemáme sem jak dostat token
|
||||
app.get("/api/qr", async (req, res) => {
|
||||
if (!req.query?.login) {
|
||||
throw Error("Nebyl předán login");
|
||||
return res.status(400).json({ error: "Nebyl předán login" });
|
||||
}
|
||||
const img = getQr(req.query.login as string);
|
||||
if (!req.query?.id) {
|
||||
return res.status(400).json({ error: "Nebyl předán identifikátor QR kódu" });
|
||||
}
|
||||
const img = await getQr(req.query.login as string, req.query.id as string);
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'image/png',
|
||||
'Content-Length': img.length
|
||||
@@ -142,8 +152,8 @@ app.get("/api/data", async (req, res) => {
|
||||
// Na víkendu zobrazíme pátek místo hlášky "Užívejte víkend"
|
||||
date = getDateForWeekIndex(4);
|
||||
}
|
||||
const slotParam = typeof req.query.slot === 'string' ? req.query.slot : undefined;
|
||||
if (slotParam && slotParam !== 'obed' && slotParam !== 'extra') {
|
||||
const slotParam = typeof req.query.slot === 'string' ? req.query.slot as MealSlot : undefined;
|
||||
if (slotParam && slotParam !== MealSlot.OBED && slotParam !== MealSlot.EXTRA) {
|
||||
return res.status(400).json({ error: 'Neplatný slot' });
|
||||
}
|
||||
const data = await getData(date, slotParam);
|
||||
@@ -169,6 +179,7 @@ app.use("/api/stats", statsRoutes);
|
||||
app.use("/api/notifications", notificationRoutes);
|
||||
app.use("/api/qr", qrRoutes);
|
||||
app.use("/api/dev", devRoutes);
|
||||
app.use("/api/changelogs", changelogRoutes);
|
||||
|
||||
app.use('/stats', express.static('public'));
|
||||
app.use(express.static('public'));
|
||||
@@ -188,9 +199,11 @@ app.use((err: any, req: any, res: any, next: any) => {
|
||||
const PORT = process.env.PORT ?? 3001;
|
||||
const HOST = process.env.HOST ?? '0.0.0.0';
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server listening on ${HOST}, port ${PORT}`);
|
||||
startReminderScheduler();
|
||||
storageReady.then(() => {
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server listening on ${HOST}, port ${PORT}`);
|
||||
startReminderScheduler();
|
||||
});
|
||||
});
|
||||
|
||||
// Umožníme vypnutí serveru přes SIGINT, jinak Docker čeká než ho sestřelí
|
||||
|
||||
+39
-20
@@ -1429,27 +1429,46 @@ export const getPizzaListMock = () => {
|
||||
return MOCK_PIZZA_LIST;
|
||||
}
|
||||
|
||||
// Mockovací data pro saláty
|
||||
const MOCK_SALAT_LIST = [
|
||||
{
|
||||
name: "Greek",
|
||||
ingredients: ["Salát", "Černé olivy", "Paprika mix", "Červená cibule", "Rajčata", "Okurka salátová", "Jogurtový dresing"],
|
||||
price: 174 + 13,
|
||||
},
|
||||
{
|
||||
name: "Caesar",
|
||||
ingredients: ["Salát", "Rajčata", "Kuřecí maso", "Krutony", "Parmazán", "Caesar dresing", "Olivový olej"],
|
||||
price: 184 + 13,
|
||||
},
|
||||
{
|
||||
name: "Šopský salát",
|
||||
ingredients: ["Salátová okurka", "Rajčata", "Paprika mix", "Červená cibule", "Balkánský sýr"],
|
||||
price: 164 + 13,
|
||||
},
|
||||
{
|
||||
name: "Těstovinový salát",
|
||||
ingredients: ["Penne", "Okurka", "Rajčata", "Paprika mix", "Kuřecí maso", "Jogurtový dresing"],
|
||||
price: 184 + 13,
|
||||
},
|
||||
]
|
||||
|
||||
export const getSalatListMock = () => {
|
||||
return MOCK_SALAT_LIST;
|
||||
}
|
||||
|
||||
export const getStatsMock = (): WeeklyStats => {
|
||||
const mkDay = (date: string, di: number) => ({
|
||||
date,
|
||||
locations: Object.keys(LunchChoice).reduce((prev, cur, ci) => (
|
||||
{ ...prev, [cur]: (di * 7 + ci * 3) % 10 }
|
||||
), {} as Record<string, number>),
|
||||
});
|
||||
return [
|
||||
{
|
||||
date: '24.02.',
|
||||
locations: { ...Object.keys(LunchChoice).reduce((prev, cur) => ({ ...prev, [cur]: Math.floor(Math.random() * 10) }), {}) }
|
||||
},
|
||||
{
|
||||
date: '25.02.',
|
||||
locations: { ...Object.keys(LunchChoice).reduce((prev, cur) => ({ ...prev, [cur]: Math.floor(Math.random() * 10) }), {}) }
|
||||
},
|
||||
{
|
||||
date: '26.02.',
|
||||
locations: { ...Object.keys(LunchChoice).reduce((prev, cur) => ({ ...prev, [cur]: Math.floor(Math.random() * 10) }), {}) }
|
||||
},
|
||||
{
|
||||
date: '27.02.',
|
||||
locations: { ...Object.keys(LunchChoice).reduce((prev, cur) => ({ ...prev, [cur]: Math.floor(Math.random() * 10) }), {}) }
|
||||
},
|
||||
{
|
||||
date: '28.02.',
|
||||
locations: { ...Object.keys(LunchChoice).reduce((prev, cur) => ({ ...prev, [cur]: Math.floor(Math.random() * 10) }), {}) }
|
||||
}
|
||||
mkDay('24.02.', 0),
|
||||
mkDay('25.02.', 1),
|
||||
mkDay('26.02.', 2),
|
||||
mkDay('27.02.', 3),
|
||||
mkDay('28.02.', 4),
|
||||
];
|
||||
}
|
||||
+85
-12
@@ -2,9 +2,10 @@ import { formatDate } from "./utils";
|
||||
import { callNotifikace } from "./notifikace";
|
||||
import { generateQr } from "./qr";
|
||||
import getStorage from "./storage";
|
||||
import { downloadPizzy } from "./chefie";
|
||||
import { downloadPizzy, downloadSalaty } from "./chefie";
|
||||
import { getClientData, getToday, initIfNeeded } from "./service";
|
||||
import { Pizza, ClientData, PizzaDayState, PizzaSize, PizzaOrder, PizzaVariant, UdalostEnum, PendingQr } from "../../types/gen/types.gen";
|
||||
import { Pizza, Salat, ClientData, PizzaDayState, PizzaSize, PizzaOrder, PizzaVariant, UdalostEnum, PendingQr } from "../../types/gen/types.gen";
|
||||
import crypto from "crypto";
|
||||
|
||||
const storage = getStorage();
|
||||
const PENDING_QR_PREFIX = 'pending_qr';
|
||||
@@ -25,7 +26,7 @@ export async function getPizzaList(): Promise<Pizza[] | undefined> {
|
||||
|
||||
/**
|
||||
* Uloží seznam dostupných pizz pro dnešní den.
|
||||
*
|
||||
*
|
||||
* @param pizzaList seznam dostupných pizz
|
||||
*/
|
||||
export async function savePizzaList(pizzaList: Pizza[]): Promise<ClientData> {
|
||||
@@ -38,6 +39,34 @@ export async function savePizzaList(pizzaList: Pizza[]): Promise<ClientData> {
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí seznam dostupných salátů pro dnešní den.
|
||||
* Stáhne je, pokud je pro dnešní den nemá.
|
||||
*/
|
||||
export async function getSalatList(): Promise<Salat[] | undefined> {
|
||||
await initIfNeeded();
|
||||
let clientData = await getClientData(getToday());
|
||||
if (!clientData.salatList) {
|
||||
const mock = process.env.MOCK_DATA === 'true';
|
||||
clientData = await saveSalatList(await downloadSalaty(mock));
|
||||
}
|
||||
return Promise.resolve(clientData.salatList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uloží seznam dostupných salátů pro dnešní den.
|
||||
*
|
||||
* @param salatList seznam dostupných salátů
|
||||
*/
|
||||
export async function saveSalatList(salatList: Salat[]): Promise<ClientData> {
|
||||
await initIfNeeded();
|
||||
const today = formatDate(getToday());
|
||||
const clientData = await getClientData(getToday());
|
||||
clientData.salatList = salatList;
|
||||
await storage.setData(today, clientData);
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vytvoří pizza day pro aktuální den a vrátí data pro klienta.
|
||||
*/
|
||||
@@ -48,8 +77,8 @@ export async function createPizzaDay(creator: string): Promise<ClientData> {
|
||||
throw Error("Pizza day pro dnešní den již existuje");
|
||||
}
|
||||
// TODO berka rychlooprava, vyřešit lépe - stahovat jednou, na jediném místě!
|
||||
const pizzaList = await getPizzaList();
|
||||
const data: ClientData = { pizzaDay: { state: PizzaDayState.CREATED, creator, orders: [] }, pizzaList, ...clientData };
|
||||
const [pizzaList, salatList] = await Promise.all([getPizzaList(), getSalatList()]);
|
||||
const data: ClientData = { pizzaDay: { state: PizzaDayState.CREATED, creator, orders: [] }, pizzaList, salatList, ...clientData };
|
||||
const today = formatDate(getToday());
|
||||
await storage.setData(today, data);
|
||||
callNotifikace({ input: { udalost: UdalostEnum.ZAHAJENA_PIZZA, user: creator } })
|
||||
@@ -113,6 +142,46 @@ export async function addPizzaOrder(login: string, pizza: Pizza, size: PizzaSize
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Přidá objednávku salátu uživateli.
|
||||
*
|
||||
* @param login login uživatele
|
||||
* @param salat zvolený salát
|
||||
*/
|
||||
export async function addSalatOrder(login: string, salat: Salat) {
|
||||
const today = formatDate(getToday());
|
||||
const clientData = await getClientData(getToday());
|
||||
if (!clientData.pizzaDay) {
|
||||
throw Error("Pizza day pro dnešní den neexistuje");
|
||||
}
|
||||
if (clientData.pizzaDay.state !== PizzaDayState.CREATED) {
|
||||
throw Error("Pizza day není ve stavu " + PizzaDayState.CREATED);
|
||||
}
|
||||
let order: PizzaOrder | undefined = clientData.pizzaDay?.orders?.find(o => o.customer === login);
|
||||
if (!order) {
|
||||
order = {
|
||||
customer: login,
|
||||
pizzaList: [],
|
||||
totalPrice: 0,
|
||||
hasQr: false,
|
||||
}
|
||||
clientData.pizzaDay.orders ??= [];
|
||||
clientData.pizzaDay.orders.push(order);
|
||||
}
|
||||
const salatOrder: PizzaVariant = {
|
||||
varId: 0,
|
||||
name: salat.name,
|
||||
size: "1 porce",
|
||||
price: salat.price,
|
||||
category: 'salat',
|
||||
}
|
||||
order.pizzaList ??= [];
|
||||
order.pizzaList.push(salatOrder);
|
||||
order.totalPrice += salatOrder.price;
|
||||
await storage.setData(today, clientData);
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odstraní všechny pizzy uživatele (celou jeho objednávku).
|
||||
* Pokud Pizza day neexistuje nebo není ve stavu CREATED, neudělá nic.
|
||||
@@ -269,11 +338,15 @@ export async function finishPizzaDelivery(login: string, bankAccount?: string, b
|
||||
if (bankAccount?.length && bankAccountHolder?.length) {
|
||||
for (const order of clientData.pizzaDay.orders!) {
|
||||
if (order.customer !== login) { // zatím platí creator = objednávající, a pro toho nemá QR kód smysl
|
||||
let message = order.pizzaList!.map(pizza => `Pizza ${pizza.name} (${pizza.size})`).join(', ');
|
||||
await generateQr(order.customer, bankAccount, bankAccountHolder, order.totalPrice, message);
|
||||
const id = crypto.randomUUID();
|
||||
let message = order.pizzaList!.map(item =>
|
||||
item.category === 'salat' ? `Salát ${item.name}` : `Pizza ${item.name} (${item.size})`
|
||||
).join(', ');
|
||||
await generateQr(order.customer, bankAccount, bankAccountHolder, order.totalPrice, message, id);
|
||||
order.hasQr = true;
|
||||
// Uložíme nevyřízený QR kód pro persistentní zobrazení
|
||||
await addPendingQr(order.customer, {
|
||||
id,
|
||||
date: today,
|
||||
creator: login,
|
||||
totalPrice: order.totalPrice,
|
||||
@@ -360,8 +433,8 @@ function getPendingQrKey(login: string): string {
|
||||
export async function addPendingQr(login: string, pendingQr: PendingQr): Promise<void> {
|
||||
const key = getPendingQrKey(login);
|
||||
const existing = await storage.getData<PendingQr[]>(key) ?? [];
|
||||
// Nepřidáváme duplicity pro stejný den
|
||||
if (!existing.some(qr => qr.date === pendingQr.date)) {
|
||||
// Deduplikace podle id (ne podle data — jeden den může mít uživatel víc QR kódů)
|
||||
if (!existing.some(qr => qr.id === pendingQr.id)) {
|
||||
existing.push(pendingQr);
|
||||
await storage.setData(key, existing);
|
||||
}
|
||||
@@ -375,11 +448,11 @@ export async function getPendingQrs(login: string): Promise<PendingQr[]> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Označí QR kód pro daný den jako uhrazený (odstraní ho ze seznamu nevyřízených).
|
||||
* Označí QR kód jako uhrazený (odstraní ho ze seznamu nevyřízených).
|
||||
*/
|
||||
export async function dismissPendingQr(login: string, date: string): Promise<void> {
|
||||
export async function dismissPendingQr(login: string, id: string): Promise<void> {
|
||||
const key = getPendingQrKey(login);
|
||||
const existing = await storage.getData<PendingQr[]>(key) ?? [];
|
||||
const filtered = existing.filter(qr => qr.date !== date);
|
||||
const filtered = existing.filter(qr => qr.id !== id);
|
||||
await storage.setData(key, filtered);
|
||||
}
|
||||
+28
-32
@@ -1,22 +1,20 @@
|
||||
import fs from "fs";
|
||||
import axios from "axios";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import crypto from "crypto";
|
||||
import { formatDate } from "./utils";
|
||||
import getStorage from "./storage";
|
||||
|
||||
const QR_GENERATOR_URL = 'https://api.paylibo.com/paylibo/generator/image';
|
||||
const COUNTRY_CODE = 'CZ';
|
||||
const CURRENCY_CODE = 'CZK';
|
||||
const QR_PIXEL_SIZE = 256;
|
||||
const tmpDir = os.tmpdir();
|
||||
|
||||
const storage = getStorage();
|
||||
|
||||
/**
|
||||
* Převede číslo účtu z BBAN do IBAN. Automaticky dopočítá kontrolní číslice.
|
||||
*
|
||||
*
|
||||
* @param bankAccountNumber číslo účtu ve formátu BBAN (123456-0123456789/0100)
|
||||
*/
|
||||
function convertBbanToIban(bankAccountNumber: string): string {
|
||||
export function convertBbanToIban(bankAccountNumber: string): string {
|
||||
// TODO validovat číslo účtu stejně jako na klientovi, pro případ že sem někdo pošle nesmysl
|
||||
let prefix: string = '';
|
||||
let accountNumber: string = bankAccountNumber;
|
||||
@@ -41,29 +39,26 @@ function convertBbanToIban(bankAccountNumber: string): string {
|
||||
return iban;
|
||||
}
|
||||
|
||||
function createNameHash(customerName: string): string {
|
||||
return crypto.createHash('md5').update(customerName).digest('hex');
|
||||
}
|
||||
|
||||
function createFilePath(nameHash: string): string {
|
||||
const fileName = `${formatDate(new Date())}_${nameHash}.png`;
|
||||
return path.join(tmpDir, fileName);
|
||||
function createStorageKey(customerName: string, id: string): string {
|
||||
const nameHash = crypto.createHash('md5').update(customerName).digest('hex');
|
||||
return `qr_${nameHash}_${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vygeneruje, uloží a vrátí unikátní ID obrázku platebního QR kódu s danými parametry.
|
||||
*
|
||||
* Vygeneruje a uloží obrázek platebního QR kódu do storage (Redis/JSON).
|
||||
* Data přežijí redeploy — není třeba persistentní filesystém.
|
||||
*
|
||||
* @param customerName jméno uživatele, pro kterého je QR kód generován
|
||||
* @param bankAccountNumber číslo cílového bankovního účtu ve formátu BBAN
|
||||
* @param bankAccountHolder jméno držitele cílového bankovního účtu
|
||||
* @param amount částka v Kč
|
||||
* @param message zpráva pro příjemce
|
||||
* @returns hash, pomocí kterého lze následně získat vygenerovaný obrázek
|
||||
* @param id unikátní identifikátor (UUID) tohoto QR kódu
|
||||
*/
|
||||
export async function generateQr(customerName: string, bankAccountNumber: string, bankAccountHolder: string, amount: number, message: string): Promise<string> {
|
||||
export async function generateQr(customerName: string, bankAccountNumber: string, bankAccountHolder: string, amount: number, message: string, id: string): Promise<void> {
|
||||
// Zpráva pro příjemce nesmí dle standardu obsahovat '*' a být delší než 60 znaků
|
||||
if (message.indexOf('*') >= 0) {
|
||||
message = message.replace('*', '');
|
||||
message = message.replace(/\*/g, '');
|
||||
}
|
||||
if (message.length > 60) {
|
||||
message = message.substring(0, 60);
|
||||
@@ -77,22 +72,23 @@ export async function generateQr(customerName: string, bankAccountNumber: string
|
||||
branding: false,
|
||||
compress: false,
|
||||
size: QR_PIXEL_SIZE,
|
||||
}
|
||||
const response = await axios.get(QR_GENERATOR_URL, { responseType: 'stream', params: { ...payload } });
|
||||
// Použijeme hash, abychom nemuseli řešit nepovolené znaky ve jménu uživatele
|
||||
const nameHash = createNameHash(customerName);
|
||||
const imgPath = createFilePath(nameHash);
|
||||
response.data.pipe(fs.createWriteStream(imgPath));
|
||||
return nameHash;
|
||||
};
|
||||
const response = await axios.get(QR_GENERATOR_URL, { responseType: 'arraybuffer', params: { ...payload } });
|
||||
const base64 = Buffer.from(response.data).toString('base64');
|
||||
await storage.setData(createStorageKey(customerName, id), base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí obrázek s QR kódem, pokud existuje.
|
||||
*
|
||||
* Vrátí obrázek s QR kódem ze storage.
|
||||
*
|
||||
* @param customerName jméno uživatele
|
||||
* @param id unikátní identifikátor QR kódu
|
||||
* @returns data obrázku
|
||||
*/
|
||||
export function getQr(customerName: string): Buffer {
|
||||
const imgPath = createFilePath(createNameHash(customerName));
|
||||
return fs.readFileSync(imgPath);
|
||||
}
|
||||
export async function getQr(customerName: string, id: string): Promise<Buffer> {
|
||||
const base64 = await storage.getData<string>(createStorageKey(customerName, id));
|
||||
if (!base64) {
|
||||
throw new Error("QR kód nebyl nalezen");
|
||||
}
|
||||
return Buffer.from(base64, 'base64');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import { getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock, getM
|
||||
import { formatDate } from "./utils";
|
||||
import { Food } from "../../types/gen/types.gen";
|
||||
|
||||
export class StaleWeekError extends Error {
|
||||
constructor(public food: Food[][]) { super('Data jsou z jiného týdne'); }
|
||||
}
|
||||
|
||||
// Fráze v názvech jídel, které naznačují že se jedná o polévku
|
||||
const SOUP_NAMES = [
|
||||
'polévka',
|
||||
@@ -36,7 +40,7 @@ const SENKSERIKOVA_URL = 'https://www.menicka.cz/6561-pivovarsky-senk-serikova.h
|
||||
* @param text vstupní text
|
||||
* @returns true, pokud text představuje polévku
|
||||
*/
|
||||
const isTextSoupName = (text: string): boolean => {
|
||||
export const isTextSoupName = (text: string): boolean => {
|
||||
for (const name of SOUP_NAMES) {
|
||||
if (text.toLowerCase().includes(name)) {
|
||||
return true;
|
||||
@@ -45,11 +49,11 @@ const isTextSoupName = (text: string): boolean => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const capitalize = (word: string): string => {
|
||||
export const capitalize = (word: string): string => {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
}
|
||||
|
||||
const sanitizeText = (text: string): string => {
|
||||
export const sanitizeText = (text: string): string => {
|
||||
return text.replace('\t', '').replace(' , ', ', ').trim();
|
||||
}
|
||||
|
||||
@@ -60,7 +64,7 @@ const sanitizeText = (text: string): string => {
|
||||
* @param name původní název jídla
|
||||
* @returns objekt obsahující vyčištěný název a pole alergenů
|
||||
*/
|
||||
const parseAllergens = (name: string): { cleanName: string, allergens: number[] } => {
|
||||
export const parseAllergens = (name: string): { cleanName: string, allergens: number[] } => {
|
||||
// Regex pro nalezení čísel na konci řetězce oddělených čárkami a případnými mezerami
|
||||
const regex = /\s+(\d+(?:\s*,\s*\d+)*)\s*$/;
|
||||
const match = regex.exec(name);
|
||||
@@ -276,6 +280,7 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
const $ = load(html);
|
||||
|
||||
let secondTry = false;
|
||||
let thirdTry = false;
|
||||
// První pokus - varianta "Obědy"
|
||||
let fonts = $('font.wsw-41');
|
||||
let font = undefined;
|
||||
@@ -284,7 +289,7 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
font = f;
|
||||
}
|
||||
})
|
||||
// Druhý pokus - varianta "Jídelní lístek"
|
||||
// Druhý pokus - varianta "Jídelní lístek" (starší formát)
|
||||
if (!font) {
|
||||
fonts = $('font.wnd-font-size-90');
|
||||
fonts.each((i, f) => {
|
||||
@@ -294,13 +299,26 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
}
|
||||
})
|
||||
}
|
||||
// Třetí pokus - nový formát: font.wsw-41 s textem "Jídelní lístek" (vše v jednom bloku)
|
||||
if (!font) {
|
||||
fonts = $('font.wsw-41');
|
||||
fonts.each((i, f) => {
|
||||
if ($(f).text().trim().startsWith('Jídelní lístek')) {
|
||||
font = f;
|
||||
thirdTry = true;
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!font) {
|
||||
throw new Error('Chyba: nenalezen <font> pro obědy v HTML Techtower.');
|
||||
}
|
||||
|
||||
const result: Food[][] = [];
|
||||
// TODO validovat, že v textu nalezeného <font> je rozsah, do kterého spadá vstupní datum
|
||||
const siblings = secondTry ? $(font).parent().parent().parent().siblings('p') : $(font).parent().parent().siblings();
|
||||
const siblings = thirdTry
|
||||
? $(font).parent().siblings('p')
|
||||
: secondTry
|
||||
? $(font).parent().parent().parent().siblings('p')
|
||||
: $(font).parent().parent().siblings();
|
||||
let parsing = false;
|
||||
let currentDayIndex = 0;
|
||||
for (let i = 0; i < siblings.length; i++) {
|
||||
@@ -345,6 +363,18 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Validace, zda text hlavičky obsahuje datum odpovídající požadovanému týdnu
|
||||
const headerText = $(font).text().trim();
|
||||
const dateMatch = headerText.match(/(\d{1,2})\.(\d{1,2})\./);
|
||||
if (dateMatch) {
|
||||
const foundDay = parseInt(dateMatch[1]);
|
||||
const foundMonth = parseInt(dateMatch[2]) - 1; // JS months are 0-based
|
||||
if (foundDay !== firstDayOfWeek.getDate() || foundMonth !== firstDayOfWeek.getMonth()) {
|
||||
throw new StaleWeekError(result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const CHANGELOGS_DIR = path.resolve(__dirname, "../../changelogs");
|
||||
|
||||
// In-memory cache: datum → seznam změn
|
||||
const cache: Record<string, string[]> = {};
|
||||
|
||||
function loadAllChangelogs(): Record<string, string[]> {
|
||||
let files: string[];
|
||||
try {
|
||||
files = fs.readdirSync(CHANGELOGS_DIR).filter(f => f.endsWith(".json"));
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
const date = file.replace(".json", "");
|
||||
if (!cache[date]) {
|
||||
const content = fs.readFileSync(path.join(CHANGELOGS_DIR, file), "utf-8");
|
||||
cache[date] = JSON.parse(content);
|
||||
}
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
router.get("/", (req: Request, res: Response) => {
|
||||
const all = loadAllChangelogs();
|
||||
const since = typeof req.query.since === "string" ? req.query.since : undefined;
|
||||
|
||||
// Seřazení od nejnovějšího po nejstarší
|
||||
const sortedDates = Object.keys(all).sort((a, b) => b.localeCompare(a));
|
||||
|
||||
const filteredDates = since
|
||||
? sortedDates.filter(date => date > since)
|
||||
: sortedDates;
|
||||
|
||||
const result: Record<string, string[]> = {};
|
||||
for (const date of filteredDates) {
|
||||
result[date] = all[date];
|
||||
}
|
||||
|
||||
res.status(200).json(result);
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -42,7 +42,7 @@ const RESTAURANTS_WITH_MENU = [
|
||||
* Middleware pro kontrolu DEV režimu
|
||||
*/
|
||||
function requireDevMode(req: any, res: any, next: any) {
|
||||
if (ENVIRONMENT !== 'development') {
|
||||
if (ENVIRONMENT !== 'development' && ENVIRONMENT !== 'test') {
|
||||
return res.status(403).json({ error: 'Tento endpoint je dostupný pouze ve vývojovém režimu' });
|
||||
}
|
||||
next();
|
||||
@@ -141,8 +141,9 @@ router.post("/clear", async (req: Request<{}, any, any>, res, next) => {
|
||||
const dateKey = formatDate(date);
|
||||
const data = await storage.getData<any>(dateKey);
|
||||
|
||||
// Vymažeme všechny volby
|
||||
// Vymažeme všechny volby i aktivní pizza day
|
||||
data.choices = {};
|
||||
delete data.pizzaDay;
|
||||
|
||||
await storage.setData(dateKey, data);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices,
|
||||
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
||||
import { getWebsocket } from "../websocket";
|
||||
import { callNotifikace } from "../notifikace";
|
||||
import { AddChoiceData, ChangeDepartureTimeData, RemoveChoiceData, RemoveChoicesData, UdalostEnum, UpdateNoteData } from "../../../types/gen/types.gen";
|
||||
import { AddChoiceData, ChangeDepartureTimeData, MealSlot, RemoveChoiceData, RemoveChoicesData, UdalostEnum, UpdateNoteData } from "../../../types/gen/types.gen";
|
||||
|
||||
|
||||
// RateLimit na refresh endpoint
|
||||
@@ -69,9 +69,9 @@ const parseValidateFutureDayIndex = (req: Request<{}, any, AddChoiceData["body"]
|
||||
return dayIndex;
|
||||
}
|
||||
|
||||
const parseSlot = (body: Record<string, any>): string | undefined => {
|
||||
const parseSlot = (body: Record<string, any>): MealSlot | undefined => {
|
||||
const slot = body?.slot;
|
||||
if (slot != null && slot !== 'obed' && slot !== 'extra') {
|
||||
if (slot != null && slot !== MealSlot.OBED && slot !== MealSlot.EXTRA) {
|
||||
throw Error(`Neplatný slot: ${slot}`);
|
||||
}
|
||||
return slot ?? undefined;
|
||||
@@ -204,13 +204,20 @@ router.post("/updateBuyer", async (req, res, next) => {
|
||||
} catch (e: any) { next(e) }
|
||||
});
|
||||
|
||||
// /api/food/refresh?type=week&heslo=docasnyheslo
|
||||
// /api/food/refresh?type=week (přihlášený uživatel, nebo ?heslo=... pro bypass rate limitu)
|
||||
export const refreshMetoda = async (req: Request, res: Response) => {
|
||||
const { type, heslo } = req.query as { type?: string; heslo?: string };
|
||||
if (heslo !== "docasnyheslo" && heslo !== "tohleheslopavelnesmizjistit123") {
|
||||
return res.status(403).json({ error: "Neplatné heslo" });
|
||||
const bypassPassword = process.env.REFRESH_BYPASS_PASSWORD;
|
||||
const isBypass = !!bypassPassword && heslo === bypassPassword;
|
||||
|
||||
if (!isBypass) {
|
||||
try {
|
||||
getLogin(parseToken(req));
|
||||
} catch {
|
||||
return res.status(403).json({ error: "Přihlaste se prosím" });
|
||||
}
|
||||
}
|
||||
if (!checkRateLimit("refresh") && heslo !== "tohleheslopavelnesmizjistit123") {
|
||||
if (!checkRateLimit("refresh") && !isBypass) {
|
||||
return res.status(429).json({ error: "Refresh už se zavolal, chvíli počkej :))" });
|
||||
}
|
||||
if (type !== "week" && type !== "day") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import express, { Request } from "express";
|
||||
import { getLogin } from "../auth";
|
||||
import { createPizzaDay, deletePizzaDay, getPizzaList, addPizzaOrder, removePizzaOrder, lockPizzaDay, unlockPizzaDay, finishPizzaOrder, finishPizzaDelivery, updatePizzaDayNote, updatePizzaFee, dismissPendingQr } from "../pizza";
|
||||
import { createPizzaDay, deletePizzaDay, getPizzaList, getSalatList, addPizzaOrder, addSalatOrder, removePizzaOrder, lockPizzaDay, unlockPizzaDay, finishPizzaOrder, finishPizzaDelivery, updatePizzaDayNote, updatePizzaFee, dismissPendingQr } from "../pizza";
|
||||
import { parseToken } from "../utils";
|
||||
import { getWebsocket } from "../websocket";
|
||||
import { AddPizzaData, DismissQrData, FinishDeliveryData, RemovePizzaData, UpdatePizzaDayNoteData, UpdatePizzaFeeData } from "../../../types";
|
||||
@@ -24,27 +24,43 @@ router.post("/delete", async (req: Request<{}, any, undefined>, res) => {
|
||||
|
||||
router.post("/add", async (req: Request<{}, any, AddPizzaData["body"]>, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
if (isNaN(req.body?.pizzaIndex)) {
|
||||
throw Error("Nebyl předán index pizzy");
|
||||
if (req.body?.salatIndex !== undefined && !isNaN(req.body.salatIndex)) {
|
||||
// Přidání salátu
|
||||
const salatIndex = req.body.salatIndex;
|
||||
const salaty = await getSalatList();
|
||||
if (!salaty) {
|
||||
throw Error("Selhalo získání seznamu dostupných salátů.");
|
||||
}
|
||||
if (!salaty[salatIndex]) {
|
||||
throw Error("Neplatný index salátu: " + salatIndex);
|
||||
}
|
||||
const data = await addSalatOrder(login, salaty[salatIndex]);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json({});
|
||||
} else {
|
||||
// Přidání pizzy
|
||||
if (req.body?.pizzaIndex === undefined || isNaN(req.body.pizzaIndex)) {
|
||||
throw Error("Nebyl předán index pizzy ani salátu");
|
||||
}
|
||||
const pizzaIndex = req.body.pizzaIndex;
|
||||
if (req.body?.pizzaSizeIndex === undefined || isNaN(req.body.pizzaSizeIndex)) {
|
||||
throw Error("Nebyl předán index velikosti pizzy");
|
||||
}
|
||||
const pizzaSizeIndex = req.body.pizzaSizeIndex;
|
||||
let pizzy = await getPizzaList();
|
||||
if (!pizzy) {
|
||||
throw Error("Selhalo získání seznamu dostupných pizz.");
|
||||
}
|
||||
if (!pizzy[pizzaIndex]) {
|
||||
throw Error("Neplatný index pizzy: " + pizzaIndex);
|
||||
}
|
||||
if (!pizzy[pizzaIndex].sizes[pizzaSizeIndex]) {
|
||||
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
||||
}
|
||||
const data = await addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json({});
|
||||
}
|
||||
const pizzaIndex = req.body.pizzaIndex;
|
||||
if (isNaN(req.body?.pizzaSizeIndex)) {
|
||||
throw Error("Nebyl předán index velikosti pizzy");
|
||||
}
|
||||
const pizzaSizeIndex = req.body.pizzaSizeIndex;
|
||||
let pizzy = await getPizzaList();
|
||||
if (!pizzy) {
|
||||
throw Error("Selhalo získání seznamu dostupných pizz.");
|
||||
}
|
||||
if (!pizzy[pizzaIndex]) {
|
||||
throw Error("Neplatný index pizzy: " + pizzaIndex);
|
||||
}
|
||||
if (!pizzy[pizzaIndex].sizes[pizzaSizeIndex]) {
|
||||
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
||||
}
|
||||
const data = await addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
router.post("/remove", async (req: Request<{}, any, RemovePizzaData["body"]>, res) => {
|
||||
@@ -112,11 +128,11 @@ router.post("/updatePizzaFee", async (req: Request<{}, any, UpdatePizzaFeeData["
|
||||
/** Označí QR kód jako uhrazený. */
|
||||
router.post("/dismissQr", async (req: Request<{}, any, DismissQrData["body"]>, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
if (!req.body.date) {
|
||||
return res.status(400).json({ error: "Nebyl předán datum" });
|
||||
if (!req.body.id) {
|
||||
return res.status(400).json({ error: "Nebyl předán identifikátor QR kódu" });
|
||||
}
|
||||
try {
|
||||
await dismissPendingQr(login, req.body.date);
|
||||
await dismissPendingQr(login, req.body.id);
|
||||
res.status(200).json({});
|
||||
} catch (e: any) { next(e) }
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { parseToken, formatDate } from "../utils";
|
||||
import { generateQr } from "../qr";
|
||||
import { addPendingQr } from "../pizza";
|
||||
import { GenerateQrData } from "../../../types";
|
||||
import crypto from "crypto";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -44,10 +45,12 @@ router.post("/generate", async (req: Request<{}, any, GenerateQrData["body"]>, r
|
||||
}
|
||||
|
||||
// Vygenerovat QR kód
|
||||
await generateQr(recipient.login, bankAccount, bankAccountHolder, recipient.amount, recipient.purpose);
|
||||
const id = crypto.randomUUID();
|
||||
await generateQr(recipient.login, bankAccount, bankAccountHolder, recipient.amount, recipient.purpose, id);
|
||||
|
||||
// Uložit jako nevyřízený QR kód
|
||||
await addPendingQr(recipient.login, {
|
||||
id,
|
||||
date: today,
|
||||
creator: login,
|
||||
totalPrice: recipient.amount,
|
||||
|
||||
+34
-25
@@ -1,6 +1,6 @@
|
||||
import { InsufficientPermissions, PizzaDayConflictError, formatDate, getDayOfWeekIndex, getFirstWorkDayOfWeek, getHumanDate, getIsWeekend, getWeekNumber } from "./utils";
|
||||
import getStorage from "./storage";
|
||||
import { getMenuSladovnicka, getMenuTechTower, getMenuZastavkaUmichala, getMenuSenkSerikova } from "./restaurants";
|
||||
import { getMenuSladovnicka, getMenuTechTower, getMenuZastavkaUmichala, getMenuSenkSerikova, StaleWeekError } from "./restaurants";
|
||||
import { getTodayMock } from "./mock";
|
||||
import { removeAllUserPizzas } from "./pizza";
|
||||
import { ClientData, DepartureTime, LunchChoice, MealSlot, PizzaDayState, Restaurant, RestaurantDayMenu, WeekMenu } from "../../types/gen/types.gen";
|
||||
@@ -8,9 +8,9 @@ import { ClientData, DepartureTime, LunchChoice, MealSlot, PizzaDayState, Restau
|
||||
const storage = getStorage();
|
||||
const MENU_PREFIX = 'menu';
|
||||
|
||||
function getDataKey(date: Date, slot?: string): string {
|
||||
function getDataKey(date: Date, slot?: MealSlot): string {
|
||||
const base = formatDate(date);
|
||||
return slot === 'extra' ? `${base}_extra` : base;
|
||||
return slot === MealSlot.EXTRA ? `${base}_extra` : base;
|
||||
}
|
||||
|
||||
/** Vrátí dnešní datum, případně fiktivní datum pro účely vývoje a testování. */
|
||||
@@ -34,7 +34,7 @@ export const getDateForWeekIndex = (index: number) => {
|
||||
}
|
||||
|
||||
/** Vrátí "prázdná" (implicitní) data pro předaný den. */
|
||||
function getEmptyData(date?: Date): ClientData {
|
||||
export function getEmptyData(date?: Date): ClientData {
|
||||
const usedDate = date || getToday();
|
||||
return {
|
||||
todayDayIndex: getDayOfWeekIndex(getToday()),
|
||||
@@ -48,9 +48,9 @@ function getEmptyData(date?: Date): ClientData {
|
||||
/**
|
||||
* Vrátí veškerá klientská data pro předaný den, nebo aktuální den, pokud není předán.
|
||||
*/
|
||||
export async function getData(date?: Date, slot?: string): Promise<ClientData> {
|
||||
export async function getData(date?: Date, slot?: MealSlot): Promise<ClientData> {
|
||||
const clientData = await getClientData(date, slot);
|
||||
if (slot !== 'extra') {
|
||||
if (slot !== MealSlot.EXTRA) {
|
||||
clientData.menus = {
|
||||
SLADOVNICKA: await getRestaurantMenu('SLADOVNICKA', date),
|
||||
// UMOTLIKU: await getRestaurantMenu('UMOTLIKU', date),
|
||||
@@ -59,7 +59,7 @@ export async function getData(date?: Date, slot?: string): Promise<ClientData> {
|
||||
SENKSERIKOVA: await getRestaurantMenu('SENKSERIKOVA', date),
|
||||
}
|
||||
}
|
||||
if (slot === 'extra') clientData.slot = MealSlot.EXTRA;
|
||||
if (slot === MealSlot.EXTRA) clientData.slot = MealSlot.EXTRA;
|
||||
return clientData;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export async function getData(date?: Date, slot?: string): Promise<ClientData> {
|
||||
* @param date datum
|
||||
* @returns databázový klíč
|
||||
*/
|
||||
function getMenuKey(date: Date) {
|
||||
export function getMenuKey(date: Date) {
|
||||
const weekNumber = getWeekNumber(date);
|
||||
return `${MENU_PREFIX}_${date.getFullYear()}_${weekNumber}`;
|
||||
}
|
||||
@@ -224,6 +224,7 @@ export async function getRestaurantMenu(restaurant: Restaurant, date?: Date, for
|
||||
for (let i = 0; i < restaurantWeekFood.length && i < weekMenu.length; i++) {
|
||||
weekMenu[i][restaurant]!.food = restaurantWeekFood[i];
|
||||
weekMenu[i][restaurant]!.lastUpdate = now;
|
||||
weekMenu[i][restaurant]!.isStale = false;
|
||||
|
||||
// Detekce uzavření pro každou restauraci
|
||||
switch (restaurant) {
|
||||
@@ -253,22 +254,34 @@ export async function getRestaurantMenu(restaurant: Restaurant, date?: Date, for
|
||||
// Uložení do storage
|
||||
await storage.setData(getMenuKey(usedDate), weekMenu);
|
||||
} catch (e: any) {
|
||||
console.error(`Selhalo načtení jídel pro podnik ${restaurant}`, e);
|
||||
if (e instanceof StaleWeekError) {
|
||||
for (let i = 0; i < e.food.length && i < weekMenu.length; i++) {
|
||||
weekMenu[i][restaurant]!.food = e.food[i];
|
||||
weekMenu[i][restaurant]!.lastUpdate = now;
|
||||
weekMenu[i][restaurant]!.isStale = true;
|
||||
}
|
||||
await storage.setData(getMenuKey(usedDate), weekMenu);
|
||||
} else {
|
||||
console.error(`Selhalo načtení jídel pro podnik ${restaurant}`, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
const result = weekMenu[dayOfWeekIndex][restaurant]!;
|
||||
result.warnings = generateMenuWarnings(result, now);
|
||||
result.warnings = generateMenuWarnings(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje varování o kvalitě/úplnosti dat menu restaurace.
|
||||
*/
|
||||
function generateMenuWarnings(menu: RestaurantDayMenu, now: number): string[] {
|
||||
function generateMenuWarnings(menu: RestaurantDayMenu): string[] {
|
||||
const warnings: string[] = [];
|
||||
if (!menu.food?.length || menu.closed) {
|
||||
return warnings;
|
||||
}
|
||||
if (menu.isStale) {
|
||||
warnings.push('Data jsou z minulého týdne');
|
||||
}
|
||||
const hasSoup = menu.food.some(f => f.isSoup);
|
||||
if (!hasSoup) {
|
||||
warnings.push('Chybí polévka');
|
||||
@@ -277,10 +290,6 @@ function generateMenuWarnings(menu: RestaurantDayMenu, now: number): string[] {
|
||||
if (missingPrice) {
|
||||
warnings.push('U některých jídel chybí cena');
|
||||
}
|
||||
const STALE_THRESHOLD_MS = 24 * 60 * 60 * 1000;
|
||||
if (menu.lastUpdate && (now - menu.lastUpdate) > STALE_THRESHOLD_MS) {
|
||||
warnings.push('Data jsou starší než 24 hodin');
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
@@ -289,7 +298,7 @@ function generateMenuWarnings(menu: RestaurantDayMenu, now: number): string[] {
|
||||
*
|
||||
* @param date datum
|
||||
*/
|
||||
export async function initIfNeeded(date?: Date, slot?: string) {
|
||||
export async function initIfNeeded(date?: Date, slot?: MealSlot) {
|
||||
const usedDate = getDataKey(date ?? getToday(), slot);
|
||||
const hasData = await storage.hasData(usedDate);
|
||||
if (!hasData) {
|
||||
@@ -306,7 +315,7 @@ export async function initIfNeeded(date?: Date, slot?: string) {
|
||||
* @param date datum, ke kterému se volba vztahuje
|
||||
* @returns
|
||||
*/
|
||||
export async function removeChoices(login: string, trusted: boolean, locationKey: LunchChoice, date?: Date, slot?: string) {
|
||||
export async function removeChoices(login: string, trusted: boolean, locationKey: LunchChoice, date?: Date, slot?: MealSlot) {
|
||||
const selectedDay = getDataKey(date ?? getToday(), slot);
|
||||
let data = await getClientData(date, slot);
|
||||
validateTrusted(data, login, trusted);
|
||||
@@ -333,7 +342,7 @@ export async function removeChoices(login: string, trusted: boolean, locationKey
|
||||
* @param date datum, ke kterému se volba vztahuje
|
||||
* @returns
|
||||
*/
|
||||
export async function removeChoice(login: string, trusted: boolean, locationKey: LunchChoice, foodIndex: number, date?: Date, slot?: string) {
|
||||
export async function removeChoice(login: string, trusted: boolean, locationKey: LunchChoice, foodIndex: number, date?: Date, slot?: MealSlot) {
|
||||
const selectedDay = getDataKey(date ?? getToday(), slot);
|
||||
let data = await getClientData(date, slot);
|
||||
validateTrusted(data, login, trusted);
|
||||
@@ -356,7 +365,7 @@ export async function removeChoice(login: string, trusted: boolean, locationKey:
|
||||
* @param date datum, ke kterému se volby vztahují
|
||||
* @param ignoredLocationKey volba, která nebude odstraněna, pokud existuje
|
||||
*/
|
||||
async function removeChoiceIfPresent(login: string, date?: Date, ignoredLocationKey?: LunchChoice, slot?: string) {
|
||||
async function removeChoiceIfPresent(login: string, date?: Date, ignoredLocationKey?: LunchChoice, slot?: MealSlot) {
|
||||
const usedDate = date ?? getToday();
|
||||
let data = await getClientData(usedDate, slot);
|
||||
for (const key of Object.keys(data.choices)) {
|
||||
@@ -408,14 +417,14 @@ function validateTrusted(data: ClientData, login: string, trusted: boolean) {
|
||||
* @param date datum, ke kterému se volba vztahuje
|
||||
* @returns aktuální data
|
||||
*/
|
||||
export async function addChoice(login: string, trusted: boolean, locationKey: LunchChoice, foodIndex?: number, date?: Date, slot?: string) {
|
||||
export async function addChoice(login: string, trusted: boolean, locationKey: LunchChoice, foodIndex?: number, date?: Date, slot?: MealSlot) {
|
||||
const usedDate = date ?? getToday();
|
||||
await initIfNeeded(usedDate, slot);
|
||||
let data = await getClientData(usedDate, slot);
|
||||
validateTrusted(data, login, trusted);
|
||||
await validateFoodIndex(locationKey, foodIndex, date);
|
||||
|
||||
if (!slot || slot === 'obed') {
|
||||
if (!slot || slot === MealSlot.OBED) {
|
||||
// Pokud uživatel měl vybranou PIZZA a mění na něco jiného
|
||||
const hadPizzaChoice = data.choices.PIZZA && login in data.choices.PIZZA;
|
||||
if (hadPizzaChoice && locationKey !== LunchChoice.PIZZA && foodIndex == null) {
|
||||
@@ -498,7 +507,7 @@ async function validateFoodIndex(locationKey: LunchChoice, foodIndex?: number, d
|
||||
* @param note poznámka
|
||||
* @param date datum, ke kterému se volba vztahuje
|
||||
*/
|
||||
export async function updateNote(login: string, trusted: boolean, note?: string, date?: Date, slot?: string) {
|
||||
export async function updateNote(login: string, trusted: boolean, note?: string, date?: Date, slot?: MealSlot) {
|
||||
const usedDate = date ?? getToday();
|
||||
await initIfNeeded(usedDate, slot);
|
||||
let data = await getClientData(usedDate, slot);
|
||||
@@ -522,7 +531,7 @@ export async function updateNote(login: string, trusted: boolean, note?: string,
|
||||
* @param time preferovaný čas odchodu
|
||||
* @param date datum, ke kterému se čas vztahuje
|
||||
*/
|
||||
export async function updateDepartureTime(login: string, time?: string, date?: Date, slot?: string) {
|
||||
export async function updateDepartureTime(login: string, time?: string, date?: Date, slot?: MealSlot) {
|
||||
const usedDate = date ?? getToday();
|
||||
let clientData = await getClientData(usedDate, slot);
|
||||
const found = Object.values(clientData.choices).find(location => login in location);
|
||||
@@ -547,7 +556,7 @@ export async function updateDepartureTime(login: string, time?: string, date?: D
|
||||
*
|
||||
* @param login přihlašovací jméno uživatele
|
||||
*/
|
||||
export async function updateBuyer(login: string, slot?: string) {
|
||||
export async function updateBuyer(login: string, slot?: MealSlot) {
|
||||
const usedDate = getToday();
|
||||
let clientData = await getClientData(usedDate, slot);
|
||||
const userEntry = clientData.choices?.['OBJEDNAVAM']?.[login];
|
||||
@@ -565,7 +574,7 @@ export async function updateBuyer(login: string, slot?: string) {
|
||||
* @param date datum pro který vrátit data, pokud není vyplněno, je použit dnešní den
|
||||
* @returns data pro klienta
|
||||
*/
|
||||
export async function getClientData(date?: Date, slot?: string): Promise<ClientData> {
|
||||
export async function getClientData(date?: Date, slot?: MealSlot): Promise<ClientData> {
|
||||
const targetDate = date ?? getToday();
|
||||
const dateString = getDataKey(targetDate, slot);
|
||||
const clientData = await storage.getData<ClientData>(dateString) || getEmptyData(date);
|
||||
|
||||
@@ -3,28 +3,29 @@ import path from 'path';
|
||||
import { StorageInterface } from "./StorageInterface";
|
||||
import JsonStorage from "./json";
|
||||
import RedisStorage from "./redis";
|
||||
import MemoryStorage from "./memory";
|
||||
|
||||
const ENVIRONMENT = process.env.NODE_ENV ?? 'production';
|
||||
dotenv.config({ path: path.resolve(__dirname, `../../.env.${ENVIRONMENT}`) });
|
||||
|
||||
const JSON_KEY = 'json';
|
||||
const REDIS_KEY = 'redis';
|
||||
const MEMORY_KEY = 'memory';
|
||||
|
||||
let storage: StorageInterface;
|
||||
if (!process.env.STORAGE || process.env.STORAGE?.toLowerCase() === JSON_KEY) {
|
||||
storage = new JsonStorage();
|
||||
} else if (process.env.STORAGE?.toLowerCase() === REDIS_KEY) {
|
||||
storage = new RedisStorage();
|
||||
} else if (process.env.STORAGE?.toLowerCase() === MEMORY_KEY) {
|
||||
storage = new MemoryStorage();
|
||||
} else {
|
||||
throw Error("Nepodporovaná hodnota proměnné STORAGE: " + process.env.STORAGE + ", podporované jsou 'json' nebo 'redis'");
|
||||
throw Error("Nepodporovaná hodnota proměnné STORAGE: " + process.env.STORAGE + ", podporované jsou 'json', 'redis' nebo 'memory'");
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (storage.initialize) {
|
||||
await storage.initialize();
|
||||
}
|
||||
})();
|
||||
|
||||
export const storageReady: Promise<void> = storage.initialize
|
||||
? storage.initialize()
|
||||
: Promise.resolve();
|
||||
|
||||
export default function getStorage(): StorageInterface {
|
||||
return storage;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { StorageInterface } from "./StorageInterface";
|
||||
|
||||
const store = new Map<string, unknown>();
|
||||
|
||||
/** Vymaže všechna data z in-memory úložiště. Slouží k resetu mezi testy. */
|
||||
export function resetMemoryStorage(): void {
|
||||
store.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* In-memory implementace úložiště. Používá se výhradně v testovacím prostředí.
|
||||
*/
|
||||
export default class MemoryStorage implements StorageInterface {
|
||||
|
||||
hasData(key: string): Promise<boolean> {
|
||||
return Promise.resolve(store.has(key));
|
||||
}
|
||||
|
||||
getData<Type>(key: string): Promise<Type | undefined> {
|
||||
return Promise.resolve(store.get(key) as Type | undefined);
|
||||
}
|
||||
|
||||
setData<Type>(key: string, data: Type): Promise<void> {
|
||||
store.set(key, data);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export default class RedisStorage implements StorageInterface {
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
client.connect();
|
||||
await client.connect();
|
||||
}
|
||||
|
||||
async hasData(key: string) {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { generateToken, verify, getLogin, getTrusted } from '../auth';
|
||||
|
||||
const VALID_SECRET = 'test-jwt-secret-ktery-ma-alespon-32-znaku';
|
||||
const SHORT_SECRET = 'kratky';
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.JWT_SECRET = VALID_SECRET;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.JWT_SECRET;
|
||||
});
|
||||
|
||||
describe('generateToken', () => {
|
||||
test('vrátí token pro platný login', () => {
|
||||
const token = generateToken('alice');
|
||||
expect(typeof token).toBe('string');
|
||||
expect(token.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('vyhodí chybu bez JWT_SECRET', () => {
|
||||
delete process.env.JWT_SECRET;
|
||||
expect(() => generateToken('alice')).toThrow('JWT_SECRET');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro příliš krátký JWT_SECRET', () => {
|
||||
process.env.JWT_SECRET = SHORT_SECRET;
|
||||
expect(() => generateToken('alice')).toThrow('32');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro prázdný login', () => {
|
||||
expect(() => generateToken('')).toThrow('login');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro login obsahující jen mezery', () => {
|
||||
expect(() => generateToken(' ')).toThrow('login');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro chybějící login', () => {
|
||||
expect(() => generateToken(undefined)).toThrow('login');
|
||||
});
|
||||
});
|
||||
|
||||
describe('verify', () => {
|
||||
test('vrátí true pro platný token', () => {
|
||||
const token = generateToken('alice');
|
||||
expect(verify(token)).toBe(true);
|
||||
});
|
||||
|
||||
test('vrátí false pro podvrženou signaturu', () => {
|
||||
const token = generateToken('alice');
|
||||
const tampered = token.slice(0, -5) + 'XXXXX';
|
||||
expect(verify(tampered)).toBe(false);
|
||||
});
|
||||
|
||||
test('vrátí false pro token podepsaný jiným secret', () => {
|
||||
process.env.JWT_SECRET = 'other-secret-min-32-chars-bbbbb!';
|
||||
const tokenOther = generateToken('alice');
|
||||
process.env.JWT_SECRET = VALID_SECRET;
|
||||
expect(verify(tokenOther)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLogin / getTrusted', () => {
|
||||
test('round-trip: getLogin vrátí správný login', () => {
|
||||
const token = generateToken('bob');
|
||||
expect(getLogin(token)).toBe('bob');
|
||||
});
|
||||
|
||||
test('trusted=false je výchozí hodnota', () => {
|
||||
const token = generateToken('alice');
|
||||
expect(getTrusted(token)).toBe(false);
|
||||
});
|
||||
|
||||
test('trusted=true je zachováno', () => {
|
||||
const token = generateToken('alice', true);
|
||||
expect(getTrusted(token)).toBe(true);
|
||||
});
|
||||
|
||||
test('getLogin vyhodí chybu pro chybějící token', () => {
|
||||
expect(() => getLogin(undefined)).toThrow('token');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import axios from 'axios';
|
||||
import { downloadSalaty } from '../chefie';
|
||||
|
||||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
const fixturesDir = path.join(__dirname, 'fixtures');
|
||||
const loadFixture = (name: string) => fs.readFileSync(path.join(fixturesDir, name), 'utf-8');
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
// První volání = stránka se seznamem salátů, následující volání = jednotlivé stránky salátů
|
||||
mockedAxios.get = jest.fn()
|
||||
.mockResolvedValueOnce({ data: loadFixture('chefie-salaty.html') })
|
||||
.mockResolvedValueOnce({ data: loadFixture('chefie-salat-caesar.html') })
|
||||
.mockResolvedValueOnce({ data: loadFixture('chefie-salat-recky.html') });
|
||||
});
|
||||
|
||||
test('downloadSalaty vrátí seznam salátů', async () => {
|
||||
const salaty = await downloadSalaty(false);
|
||||
expect(salaty).toHaveLength(2);
|
||||
});
|
||||
|
||||
test('saláty mají name a ingredients', async () => {
|
||||
const salaty = await downloadSalaty(false);
|
||||
expect(salaty[0].name).toBe('Caesar salát');
|
||||
expect(salaty[0].ingredients).toContain('Kuřecí maso');
|
||||
});
|
||||
|
||||
test('cena salátu zahrnuje pevný příplatek 13 Kč za obal', async () => {
|
||||
const salaty = await downloadSalaty(false);
|
||||
// Caesar sticker price = 129, box = 13
|
||||
expect(salaty[0].price).toBe(129 + 13);
|
||||
// Řecký sticker price = 119, box = 13
|
||||
expect(salaty[1].price).toBe(119 + 13);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="produkt">
|
||||
<h2>Caesar salát</h2>
|
||||
</div>
|
||||
<ul class="prisady">
|
||||
<li>Ledový salát</li>
|
||||
<li>Kuřecí maso</li>
|
||||
<li>Parmazán</li>
|
||||
</ul>
|
||||
<div class="cena">
|
||||
<span>129 Kč</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="produkt">
|
||||
<h2>Řecký salát</h2>
|
||||
</div>
|
||||
<ul class="prisady">
|
||||
<li>Rajčata</li>
|
||||
<li>Okurka</li>
|
||||
<li>Feta sýr</li>
|
||||
</ul>
|
||||
<div class="cena">
|
||||
<span>119 Kč</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="vypisproduktu">
|
||||
<div>
|
||||
<h4><a href="salat-caesar.html">Caesar salát</a></h4>
|
||||
</div>
|
||||
<div>
|
||||
<h4><a href="salat-recky.html">Řecký salát</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="menicka">
|
||||
<ul class="popup-gallery">
|
||||
<li class="polevka">
|
||||
<div class="polozka">Polévka dne</div>
|
||||
<div class="cena">35 Kč</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="polozka">1. Svíčková na smetaně s knedlíkem</div>
|
||||
<div class="cena">149 Kč</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="polozka">2. Smažený sýr s bramborovým salátem</div>
|
||||
<div class="cena">135 Kč</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="menicka">
|
||||
<ul class="popup-gallery">
|
||||
<li class="polevka">
|
||||
<div class="polozka">Česnečka se smetanou</div>
|
||||
<div class="cena">35 Kč</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="polozka">1. Vepřový guláš s knedlíkem</div>
|
||||
<div class="cena">145 Kč</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<ul id="daily-menu-tab-list">
|
||||
<button id="daily-menu-tab-0"><span class="daily-menu-tab__day">pondělí</span></button>
|
||||
<button id="daily-menu-tab-1"><span class="daily-menu-tab__day">úterý</span></button>
|
||||
<button id="daily-menu-tab-2"><span class="daily-menu-tab__day">středa</span></button>
|
||||
<button id="daily-menu-tab-3"><span class="daily-menu-tab__day">čtvrtek</span></button>
|
||||
<button id="daily-menu-tab-4"><span class="daily-menu-tab__day">pátek</span></button>
|
||||
</ul>
|
||||
<ul id="daily-menu-content-list">
|
||||
<div class="daily-menu-content__content">
|
||||
<div class="daily-menu-content__item">
|
||||
<table class="daily-menu-content__table"><tbody>
|
||||
<tr><td>250ml</td><td>Polévka dne 1, 9</td><td>35 Kč</td></tr>
|
||||
<tr><td>150g</td><td>Svíčková na smetaně s knedlíkem 1, 3, 7</td><td>149 Kč</td></tr>
|
||||
<tr><td>120g</td><td>Kuřecí řízek s bramborami 1</td><td>139 Kč</td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="daily-menu-content__content">
|
||||
<div class="daily-menu-content__item">
|
||||
<table class="daily-menu-content__table"><tbody>
|
||||
<tr><td>250ml</td><td>Česnečka 1</td><td>35 Kč</td></tr>
|
||||
<tr><td>150g</td><td>Vepřový guláš s houskovým knedlíkem 1, 3</td><td>145 Kč</td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="daily-menu-content__content">
|
||||
<div class="daily-menu-content__item">
|
||||
<table class="daily-menu-content__table"><tbody>
|
||||
<tr><td>250ml</td><td>Hovězí vývar s nudlemi 1</td><td>35 Kč</td></tr>
|
||||
<tr><td>150g</td><td>Smažený sýr s bramborovým salátem 1, 3, 7</td><td>135 Kč</td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="daily-menu-content__content">
|
||||
<div class="daily-menu-content__item">
|
||||
<table class="daily-menu-content__table"><tbody>
|
||||
<tr><td>250ml</td><td>Rajská polévka 1</td><td>35 Kč</td></tr>
|
||||
<tr><td>150g</td><td>Rizoto s kuřecím masem 1</td><td>139 Kč</td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="daily-menu-content__content">
|
||||
<div class="daily-menu-content__item">
|
||||
<table class="daily-menu-content__table"><tbody>
|
||||
<tr><td>250ml</td><td>Dršťková polévka 1</td><td>35 Kč</td></tr>
|
||||
<tr><td>150g</td><td>Segedínský guláš s knedlíkem 1, 3</td><td>145 Kč</td></tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div class="outer-container">
|
||||
<div class="header-section"><!-- font.parent().parent() -->
|
||||
<p><!-- font.parent() -->
|
||||
<font class="wsw-41">Obědy 12.5.-16.5.2025</font>
|
||||
</p>
|
||||
</div>
|
||||
<!-- níže jsou sourozenci .header-section = výsledek $(font).parent().parent().siblings() -->
|
||||
<p>Pondělí</p>
|
||||
<p>• Polévka dne 1</p>
|
||||
<p>• Svíčková na smetaně s knedlíkem 1, 3, 7 149 Kč</p>
|
||||
<p>• Smažený sýr s bramborami 1, 3 139 Kč</p>
|
||||
<p>Úterý</p>
|
||||
<p>• Česnečka 1</p>
|
||||
<p>• Vepřový guláš s houskovým knedlíkem 1, 3 145 Kč</p>
|
||||
<p>Středa</p>
|
||||
<p>• Hovězí vývar s nudlemi 1</p>
|
||||
<p>• Kuřecí řízek s bramborami 1 139 Kč</p>
|
||||
<p>Čtvrtek</p>
|
||||
<p>• Dršťková polévka 1</p>
|
||||
<p>• Segedínský guláš s knedlíkem 1, 3 145 Kč</p>
|
||||
<p>Pátek</p>
|
||||
<p>• Rajská polévka s rýží 1</p>
|
||||
<p>• Rizoto s kuřecím masem a zeleninou 1 139 Kč</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
import axios from 'axios';
|
||||
import { generateQr, getQr } from '../qr';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
|
||||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
const FAKE_IMAGE = Buffer.from('fake-png-data');
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
jest.resetAllMocks();
|
||||
mockedAxios.get = jest.fn().mockResolvedValue({ data: FAKE_IMAGE });
|
||||
});
|
||||
|
||||
test('generateQr zavolá Paylibo API se správnými parametry', async () => {
|
||||
await generateQr('jannovak', '19-2000145399/0800', 'Jan Novák', 149, 'Pizza Margherita', 'test-uuid-1');
|
||||
expect(mockedAxios.get).toHaveBeenCalledTimes(1);
|
||||
const [url, config] = (mockedAxios.get as jest.Mock).mock.calls[0];
|
||||
expect(url).toContain('paylibo.com');
|
||||
expect(config.params.amount).toBe(149);
|
||||
expect(config.params.iban).toBeDefined();
|
||||
});
|
||||
|
||||
test('generateQr uloží base64 obrázek do storage', async () => {
|
||||
await generateQr('jannovak', '19-2000145399/0800', 'Jan Novák', 149, 'Pizza', 'test-uuid-2');
|
||||
const img = await getQr('jannovak', 'test-uuid-2');
|
||||
expect(Buffer.isBuffer(img)).toBe(true);
|
||||
expect(img).toEqual(FAKE_IMAGE);
|
||||
});
|
||||
|
||||
test('generateQr ořeže zprávu delší než 60 znaků', async () => {
|
||||
const dlouhaZprava = 'Pizza ' + 'x'.repeat(60);
|
||||
await generateQr('jannovak', '19-2000145399/0800', 'Jan Novák', 149, dlouhaZprava, 'test-uuid-3');
|
||||
const [, config] = (mockedAxios.get as jest.Mock).mock.calls[0];
|
||||
expect(config.params.message.length).toBeLessThanOrEqual(60);
|
||||
});
|
||||
|
||||
test('generateQr odstraní hvězdičku ze zprávy', async () => {
|
||||
await generateQr('jannovak', '19-2000145399/0800', 'Jan Novák', 149, 'Pizza *Margherita*', 'test-uuid-4');
|
||||
const [, config] = (mockedAxios.get as jest.Mock).mock.calls[0];
|
||||
expect(config.params.message).not.toContain('*');
|
||||
});
|
||||
|
||||
test('getQr hodí chybu pro neexistující ID', async () => {
|
||||
await expect(getQr('jannovak', 'neexistuje')).rejects.toThrow('nebyl nalezen');
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.JWT_SECRET = 'test-secret-min-32-chars-aaaaaaa!';
|
||||
process.env.MOCK_DATA = 'true';
|
||||
process.env.STORAGE = 'json';
|
||||
@@ -0,0 +1,235 @@
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import getStorage from '../storage';
|
||||
import { formatDate } from '../utils';
|
||||
import { getToday } from '../service';
|
||||
import {
|
||||
createPizzaDay,
|
||||
deletePizzaDay,
|
||||
addPizzaOrder,
|
||||
removePizzaOrder,
|
||||
removeAllUserPizzas,
|
||||
updatePizzaFee,
|
||||
lockPizzaDay,
|
||||
unlockPizzaDay,
|
||||
finishPizzaOrder,
|
||||
finishPizzaDelivery,
|
||||
} from '../pizza';
|
||||
import { ClientData, PizzaDayState } from '../../../types/gen/types.gen';
|
||||
|
||||
jest.mock('../notifikace', () => ({
|
||||
callNotifikace: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
jest.mock('../qr', () => ({
|
||||
generateQr: jest.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
jest.mock('../chefie', () => ({
|
||||
downloadPizzy: jest.fn().mockResolvedValue([
|
||||
{ id: 1, name: 'Margherita', variants: [{ varId: 10, size: 'střední', price: 150 }] },
|
||||
]),
|
||||
downloadSalaty: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
const CREATOR = 'kreator';
|
||||
const USER = 'uzivatel';
|
||||
|
||||
const PIZZA: any = { id: 1, name: 'Margherita', ingredients: [], variants: [], sizes: [] };
|
||||
const SIZE_M = { varId: 1, size: '30cm', price: 179, boxPrice: 13, pizzaPrice: 166 };
|
||||
const SIZE_L = { varId: 2, size: '35cm', price: 219, boxPrice: 15, pizzaPrice: 204 };
|
||||
const SIZE: any = { varId: 10, size: 'střední', price: 150 };
|
||||
|
||||
async function seedPizzaDay(state: PizzaDayState = PizzaDayState.CREATED): Promise<void> {
|
||||
const today = formatDate(getToday());
|
||||
const storage = getStorage();
|
||||
const data: ClientData = {
|
||||
todayDayIndex: 0,
|
||||
date: today,
|
||||
isWeekend: false,
|
||||
dayIndex: 0,
|
||||
choices: {},
|
||||
pizzaDay: {
|
||||
state,
|
||||
creator: CREATOR,
|
||||
orders: [],
|
||||
},
|
||||
pizzaList: [],
|
||||
salatList: [],
|
||||
};
|
||||
await storage.setData(today, data);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
describe('createPizzaDay', () => {
|
||||
test('vytvoří pizza day ve stavu CREATED', async () => {
|
||||
const data = await createPizzaDay(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.CREATED);
|
||||
expect(data.pizzaDay?.creator).toBe(CREATOR);
|
||||
});
|
||||
|
||||
test('vyhodí chybu, pokud pizza day již existuje', async () => {
|
||||
await createPizzaDay(CREATOR);
|
||||
await expect(createPizzaDay(CREATOR)).rejects.toThrow('existuje');
|
||||
});
|
||||
});
|
||||
|
||||
describe('deletePizzaDay', () => {
|
||||
test('smaže pizza day tvůrcem', async () => {
|
||||
await createPizzaDay(CREATOR);
|
||||
const data = await deletePizzaDay(CREATOR);
|
||||
expect(data.pizzaDay).toBeUndefined();
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro jiného uživatele', async () => {
|
||||
await createPizzaDay(CREATOR);
|
||||
await expect(deletePizzaDay(USER)).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('addPizzaOrder', () => {
|
||||
test('přidá objednávku pizzy', async () => {
|
||||
await seedPizzaDay();
|
||||
const data = await addPizzaOrder(USER, PIZZA, SIZE);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order?.pizzaList?.length).toBe(1);
|
||||
expect(order?.totalPrice).toBe(SIZE.price);
|
||||
});
|
||||
|
||||
test('přičte cenu další pizzy ke stejné objednávce', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
const data = await addPizzaOrder(USER, { ...PIZZA, name: 'Quattro' }, SIZE_L);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order?.totalPrice).toBe(SIZE_M.price + SIZE_L.price);
|
||||
expect(order?.pizzaList).toHaveLength(2);
|
||||
});
|
||||
|
||||
test('vyhodí chybu bez aktivního pizza day', async () => {
|
||||
await expect(addPizzaOrder(USER, PIZZA, SIZE)).rejects.toThrow('neexistuje');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro pizza day ve stavu LOCKED', async () => {
|
||||
await seedPizzaDay(PizzaDayState.LOCKED);
|
||||
await expect(addPizzaOrder(USER, PIZZA, SIZE_M)).rejects.toThrow(PizzaDayState.CREATED);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removePizzaOrder', () => {
|
||||
test('odečte cenu a odstraní položku z objednávky', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
await addPizzaOrder(USER, { ...PIZZA, name: 'Diavola' }, SIZE_L);
|
||||
const variant = { varId: SIZE_M.varId, name: PIZZA.name, size: SIZE_M.size, price: SIZE_M.price };
|
||||
const data = await removePizzaOrder(USER, variant);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order?.totalPrice).toBe(SIZE_L.price);
|
||||
expect(order?.pizzaList).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('odstraní celou objednávku, pokud je prázdná', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
const variant = { varId: SIZE_M.varId, name: PIZZA.name, size: SIZE_M.size, price: SIZE_M.price };
|
||||
const data = await removePizzaOrder(USER, variant);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAllUserPizzas', () => {
|
||||
test('odstraní objednávku uživatele', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE);
|
||||
const data = await removeAllUserPizzas(USER);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order).toBeUndefined();
|
||||
});
|
||||
|
||||
test('je no-op bez pizza day', async () => {
|
||||
const data = await removeAllUserPizzas(USER);
|
||||
expect(data.pizzaDay).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('updatePizzaFee', () => {
|
||||
test('přidá příplatek a přepočítá celkovou cenu', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
const data = await updatePizzaFee(CREATOR, USER, 'Balné', 20);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order?.fee).toEqual({ text: 'Balné', price: 20 });
|
||||
expect(order?.totalPrice).toBe(SIZE_M.price + 20);
|
||||
});
|
||||
|
||||
test('s cenou undefined odstraní příplatek', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
await updatePizzaFee(CREATOR, USER, 'Balné', 20);
|
||||
const data = await updatePizzaFee(CREATOR, USER, undefined, undefined);
|
||||
const order = data.pizzaDay?.orders?.find(o => o.customer === USER);
|
||||
expect(order?.fee).toBeUndefined();
|
||||
expect(order?.totalPrice).toBe(SIZE_M.price);
|
||||
});
|
||||
|
||||
test('vyhodí chybu, pokud volá jiný uživatel než tvůrce', async () => {
|
||||
await seedPizzaDay();
|
||||
await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
await expect(updatePizzaFee(USER, USER, 'Balné', 20)).rejects.toThrow('zakladatel');
|
||||
});
|
||||
});
|
||||
|
||||
describe('lockPizzaDay / unlockPizzaDay', () => {
|
||||
test('tvůrce může zamknout pizza day', async () => {
|
||||
await seedPizzaDay();
|
||||
const data = await lockPizzaDay(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.LOCKED);
|
||||
});
|
||||
|
||||
test('jiný uživatel nemůže zamknout pizza day', async () => {
|
||||
await seedPizzaDay();
|
||||
await expect(lockPizzaDay(USER)).rejects.toThrow(USER);
|
||||
});
|
||||
|
||||
test('zamčený pizza day lze odemknout', async () => {
|
||||
await seedPizzaDay();
|
||||
await lockPizzaDay(CREATOR);
|
||||
const data = await unlockPizzaDay(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.CREATED);
|
||||
});
|
||||
|
||||
test('nelze odemknout nezamčený pizza day', async () => {
|
||||
await seedPizzaDay();
|
||||
await expect(unlockPizzaDay(CREATOR)).rejects.toThrow(PizzaDayState.LOCKED);
|
||||
});
|
||||
});
|
||||
|
||||
describe('finishPizzaOrder', () => {
|
||||
test('přesune pizza day do stavu ORDERED', async () => {
|
||||
await seedPizzaDay();
|
||||
await lockPizzaDay(CREATOR);
|
||||
const data = await finishPizzaOrder(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.ORDERED);
|
||||
});
|
||||
|
||||
test('vyhodí chybu v nesprávném stavu (CREATED)', async () => {
|
||||
await seedPizzaDay();
|
||||
await expect(finishPizzaOrder(CREATOR)).rejects.toThrow(PizzaDayState.LOCKED);
|
||||
});
|
||||
});
|
||||
|
||||
describe('finishPizzaDelivery', () => {
|
||||
test('přesune pizza day do stavu DELIVERED', async () => {
|
||||
await seedPizzaDay();
|
||||
await lockPizzaDay(CREATOR);
|
||||
await finishPizzaOrder(CREATOR);
|
||||
const data = await finishPizzaDelivery(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.DELIVERED);
|
||||
});
|
||||
|
||||
test('vyhodí chybu v nesprávném stavu (LOCKED)', async () => {
|
||||
await seedPizzaDay();
|
||||
await lockPizzaDay(CREATOR);
|
||||
await expect(finishPizzaDelivery(CREATOR)).rejects.toThrow(PizzaDayState.ORDERED);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { convertBbanToIban } from '../qr';
|
||||
|
||||
test('konverze BBAN s prefixem na IBAN', () => {
|
||||
// Číslo účtu 19-2000145399/0800 (Česká spořitelna) → CZ6508000000192000145399
|
||||
const iban = convertBbanToIban('19-2000145399/0800');
|
||||
expect(iban).toBe('CZ6508000000192000145399');
|
||||
expect(iban).toHaveLength(24);
|
||||
});
|
||||
|
||||
test('konverze BBAN bez prefixu na IBAN', () => {
|
||||
// Číslo účtu 2000145399/0800 (bez prefixu) → prefix se doplní jako 000000
|
||||
const iban = convertBbanToIban('2000145399/0800');
|
||||
expect(iban).toBe('CZ7908000000002000145399');
|
||||
expect(iban).toHaveLength(24);
|
||||
});
|
||||
|
||||
test('konverze BBAN s krátkým číslem účtu – zero-padding', () => {
|
||||
// Krátké číslo účtu 123456/0100 → prefix 000000, account 0000123456
|
||||
const iban = convertBbanToIban('123456/0100');
|
||||
expect(iban).toHaveLength(24);
|
||||
// bankCode(4) + prefix(6) + account(10) = 20 číslic za CZ+checkdigits
|
||||
expect(iban).toMatch(/^CZ\d{2}01000000000000123456$/);
|
||||
});
|
||||
|
||||
test('kontrolní číslice jsou platné (mod 97)', () => {
|
||||
const iban = convertBbanToIban('19-2000145399/0800');
|
||||
// Přesuneme první 4 znaky na konec, nahradíme písmena čísly a mod 97 musí dát 1
|
||||
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
||||
const numeric = rearranged.replace(/[A-Z]/g, (c) => (c.charCodeAt(0) - 55).toString());
|
||||
expect(BigInt(numeric) % BigInt(97)).toBe(BigInt(1));
|
||||
});
|
||||
|
||||
test('výsledek vždy začíná CZ', () => {
|
||||
expect(convertBbanToIban('100-2000145399/0300')).toMatch(/^CZ/);
|
||||
expect(convertBbanToIban('2000145399/0100')).toMatch(/^CZ/);
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import bodyParser from 'body-parser';
|
||||
import axios from 'axios';
|
||||
import { generateToken } from '../auth';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import qrRouter from '../routes/qrRoutes';
|
||||
|
||||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
function buildApp() {
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use('/api/qr', qrRouter);
|
||||
app.use((err: any, _req: any, res: any, _next: any) => {
|
||||
res.status(400).json({ error: err.message });
|
||||
});
|
||||
return app;
|
||||
}
|
||||
|
||||
const TOKEN = `Bearer ${generateToken('kreator')}`;
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
mockedAxios.get = jest.fn().mockResolvedValue({ data: Buffer.from('fake-png') });
|
||||
});
|
||||
|
||||
const VALID_BODY = {
|
||||
recipients: [
|
||||
{ login: 'uzivatel1', purpose: 'Pizza Margherita', amount: 149 },
|
||||
{ login: 'uzivatel2', purpose: 'Pizza Diavola', amount: 179 },
|
||||
],
|
||||
bankAccount: '19-2000145399/0800',
|
||||
bankAccountHolder: 'Jan Novák',
|
||||
};
|
||||
|
||||
test('POST /generate vrátí 200 s počtem vygenerovaných QR kódů', async () => {
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send(VALID_BODY);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.count).toBe(2);
|
||||
});
|
||||
|
||||
test('POST /generate vrátí 400 pro prázdné recipients', async () => {
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send({ ...VALID_BODY, recipients: [] });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('příjemců');
|
||||
});
|
||||
|
||||
test('POST /generate vrátí 400 pro chybějící bankAccount', async () => {
|
||||
const { bankAccount: _, ...body } = VALID_BODY;
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send(body);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('účtu');
|
||||
});
|
||||
|
||||
test('POST /generate vrátí 400 pro zápornou částku', async () => {
|
||||
const body = {
|
||||
...VALID_BODY,
|
||||
recipients: [{ login: 'uzivatel1', purpose: 'Pizza', amount: -1 }],
|
||||
};
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send(body);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('částku');
|
||||
});
|
||||
|
||||
test('POST /generate vrátí 400 pro částku s více než 2 desetinnými místy', async () => {
|
||||
const body = {
|
||||
...VALID_BODY,
|
||||
recipients: [{ login: 'uzivatel1', purpose: 'Pizza', amount: 149.999 }],
|
||||
};
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send(body);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('desetinná');
|
||||
});
|
||||
|
||||
test('POST /generate vrátí 400 pro příjemce bez login', async () => {
|
||||
const body = {
|
||||
...VALID_BODY,
|
||||
recipients: [{ purpose: 'Pizza', amount: 149 }],
|
||||
};
|
||||
const res = await request(buildApp())
|
||||
.post('/api/qr/generate')
|
||||
.set('Authorization', TOKEN)
|
||||
.send(body);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('login');
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { parseAllergens, isTextSoupName, sanitizeText, capitalize } from '../restaurants';
|
||||
|
||||
// parseAllergens
|
||||
test('parseAllergens rozpozná alergeny na konci názvu', () => {
|
||||
const result = parseAllergens('Svíčková na smetaně 1, 3, 7');
|
||||
expect(result.cleanName).toBe('Svíčková na smetaně');
|
||||
expect(result.allergens).toEqual([1, 3, 7]);
|
||||
});
|
||||
|
||||
test('parseAllergens vrátí prázdné pole alergenů, pokud žádné nejsou', () => {
|
||||
const result = parseAllergens('Svíčková na smetaně');
|
||||
expect(result.cleanName).toBe('Svíčková na smetaně');
|
||||
expect(result.allergens).toEqual([]);
|
||||
});
|
||||
|
||||
test('parseAllergens zpracuje jednočíselný alergen', () => {
|
||||
const result = parseAllergens('Polévka dne 1');
|
||||
expect(result.cleanName).toBe('Polévka dne');
|
||||
expect(result.allergens).toEqual([1]);
|
||||
});
|
||||
|
||||
test('parseAllergens neodstraní čísla uvnitř názvu', () => {
|
||||
const result = parseAllergens('Pizza č. 4 Quattro formaggi 1, 7');
|
||||
expect(result.allergens).toEqual([1, 7]);
|
||||
expect(result.cleanName).toContain('4');
|
||||
});
|
||||
|
||||
// isTextSoupName
|
||||
test('isTextSoupName vrátí true pro "polévka"', () => {
|
||||
expect(isTextSoupName('Polévka dne')).toBe(true);
|
||||
});
|
||||
|
||||
test('isTextSoupName vrátí true pro "česnečka"', () => {
|
||||
expect(isTextSoupName('Česnečka se sýrem')).toBe(true);
|
||||
});
|
||||
|
||||
test('isTextSoupName vrátí true pro "vývar"', () => {
|
||||
expect(isTextSoupName('Hovězí vývar s nudlemi')).toBe(true);
|
||||
});
|
||||
|
||||
test('isTextSoupName vrátí false pro hlavní jídlo', () => {
|
||||
expect(isTextSoupName('Svíčková na smetaně s knedlíkem')).toBe(false);
|
||||
});
|
||||
|
||||
test('isTextSoupName není case-sensitive', () => {
|
||||
expect(isTextSoupName('POLÉVKA DNE')).toBe(true);
|
||||
});
|
||||
|
||||
// sanitizeText
|
||||
test('sanitizeText odstraní tabulátor (nenahradí mezerou)', () => {
|
||||
expect(sanitizeText('\ttext')).toBe('text');
|
||||
});
|
||||
|
||||
test('sanitizeText opraví mezery kolem čárky', () => {
|
||||
expect(sanitizeText('jídlo , příloha')).toBe('jídlo, příloha');
|
||||
});
|
||||
|
||||
test('sanitizeText ořeže mezery ze začátku a konce', () => {
|
||||
expect(sanitizeText(' text ')).toBe('text');
|
||||
});
|
||||
|
||||
// capitalize
|
||||
test('capitalize převede první písmeno na velké', () => {
|
||||
expect(capitalize('pondělí')).toBe('Pondělí');
|
||||
});
|
||||
|
||||
test('capitalize nezmění zbytek řetězce', () => {
|
||||
expect(capitalize('pÁTEK')).toBe('PÁTEK');
|
||||
});
|
||||
|
||||
test('capitalize vrátí prázdný řetězec pro prázdný vstup', () => {
|
||||
expect(capitalize('')).toBe('');
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
import { isTextSoupName, capitalize, sanitizeText, parseAllergens } from '../restaurants';
|
||||
|
||||
describe('isTextSoupName', () => {
|
||||
test('rozpozná "polévka"', () => {
|
||||
expect(isTextSoupName('Polévka dne')).toBe(true);
|
||||
});
|
||||
|
||||
test('rozpozná "česnečka"', () => {
|
||||
expect(isTextSoupName('Česnečka s krutony')).toBe(true);
|
||||
});
|
||||
|
||||
test('rozpozná "vývar"', () => {
|
||||
expect(isTextSoupName('Hovězí vývar s nudlemi')).toBe(true);
|
||||
});
|
||||
|
||||
test('rozpozná "slepičí s " (parciální shoda pro slepičí vývar)', () => {
|
||||
expect(isTextSoupName('Slepičí s nudlemi')).toBe(true);
|
||||
});
|
||||
|
||||
test('neklasifikuje hlavní jídlo jako polévku', () => {
|
||||
expect(isTextSoupName('Svíčková na smetaně s knedlíky')).toBe(false);
|
||||
});
|
||||
|
||||
test('neklasifikuje prázdný řetězec', () => {
|
||||
expect(isTextSoupName('')).toBe(false);
|
||||
});
|
||||
|
||||
test('není case-sensitive', () => {
|
||||
expect(isTextSoupName('POLÉVKA DNEŠKA')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('capitalize', () => {
|
||||
test('zformátuje první písmeno na velké', () => {
|
||||
expect(capitalize('svíčková')).toBe('Svíčková');
|
||||
});
|
||||
|
||||
test('nechá velká písmena beze změny', () => {
|
||||
expect(capitalize('ABC')).toBe('ABC');
|
||||
});
|
||||
|
||||
test('prázdný řetězec zůstane prázdný', () => {
|
||||
expect(capitalize('')).toBe('');
|
||||
});
|
||||
|
||||
test('jednoznakový řetězec', () => {
|
||||
expect(capitalize('a')).toBe('A');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitizeText', () => {
|
||||
test('odstraní tabulátor (první výskyt)', () => {
|
||||
// replace('\t', '') odstraní tab bez přidání mezery
|
||||
expect(sanitizeText('\tKnedlíky')).toBe('Knedlíky');
|
||||
});
|
||||
|
||||
test('nahradí první " , " za ", "', () => {
|
||||
// replace(' , ', ', ') nahrazuje pouze první výskyt
|
||||
expect(sanitizeText('Knedlíky , zelí')).toBe('Knedlíky, zelí');
|
||||
});
|
||||
|
||||
test('ořízne okrajové mezery', () => {
|
||||
expect(sanitizeText(' Jídlo ')).toBe('Jídlo');
|
||||
});
|
||||
|
||||
test('kombinace: tab + mezera okolo čárky', () => {
|
||||
expect(sanitizeText('\tKnedlíky , zelí ')).toBe('Knedlíky, zelí');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseAllergens', () => {
|
||||
test('extrahuje alergeny na konci řetězce', () => {
|
||||
const result = parseAllergens('Svíčková 1,3,7');
|
||||
expect(result.cleanName).toBe('Svíčková');
|
||||
expect(result.allergens).toEqual([1, 3, 7]);
|
||||
});
|
||||
|
||||
test('toleruje mezery okolo čárek v alergenech', () => {
|
||||
const result = parseAllergens('Řízek 1, 3, 7');
|
||||
expect(result.allergens).toEqual([1, 3, 7]);
|
||||
});
|
||||
|
||||
test('vrátí prázdná pole pro jídlo bez alergenů', () => {
|
||||
const result = parseAllergens('Ovocný salát');
|
||||
expect(result.cleanName).toBe('Ovocný salát');
|
||||
expect(result.allergens).toEqual([]);
|
||||
});
|
||||
|
||||
test('nesplete se s číslem uprostřed názvu', () => {
|
||||
const result = parseAllergens('Jídlo č. 5 bez alergenů');
|
||||
expect(result.cleanName).toBe('Jídlo č. 5 bez alergenů');
|
||||
expect(result.allergens).toEqual([]);
|
||||
});
|
||||
|
||||
test('single alergen', () => {
|
||||
const result = parseAllergens('Houby 7');
|
||||
expect(result.cleanName).toBe('Houby');
|
||||
expect(result.allergens).toEqual([7]);
|
||||
});
|
||||
|
||||
test('prázdný řetězec vrátí prázdné výsledky', () => {
|
||||
const result = parseAllergens('');
|
||||
expect(result.cleanName).toBe('');
|
||||
expect(result.allergens).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import axios from 'axios';
|
||||
import { getMenuSladovnicka, getMenuTechTower, getMenuSenkSerikova, StaleWeekError } from '../restaurants';
|
||||
|
||||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
const fixturesDir = path.join(__dirname, 'fixtures');
|
||||
const loadFixture = (name: string) => fs.readFileSync(path.join(fixturesDir, name), 'utf-8');
|
||||
|
||||
// Pondělí 12.5.2025
|
||||
const MONDAY = new Date('2025-05-12');
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('Sladovnicka parser', () => {
|
||||
beforeEach(() => {
|
||||
mockedAxios.get = jest.fn().mockResolvedValue({ data: loadFixture('sladovnicka.html') });
|
||||
});
|
||||
|
||||
test('vrátí pole o délce 5 (jeden záznam na každý pracovní den)', async () => {
|
||||
const menu = await getMenuSladovnicka(MONDAY);
|
||||
expect(menu).toHaveLength(5);
|
||||
});
|
||||
|
||||
test('pondělní menu obsahuje aspoň jedno jídlo', async () => {
|
||||
const menu = await getMenuSladovnicka(MONDAY);
|
||||
expect(menu[0].length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('první položka pondělního dne je polévka (isSoup=true)', async () => {
|
||||
const menu = await getMenuSladovnicka(MONDAY);
|
||||
expect(menu[0][0].isSoup).toBe(true);
|
||||
});
|
||||
|
||||
test('jídla mají name, price a amount', async () => {
|
||||
const menu = await getMenuSladovnicka(MONDAY);
|
||||
const jidlo = menu[0][1];
|
||||
expect(jidlo.name).toBeTruthy();
|
||||
expect(jidlo.price).toBeTruthy();
|
||||
expect(jidlo.amount).toBeTruthy();
|
||||
});
|
||||
|
||||
test('alergeny jsou naparsovány jako čísla', async () => {
|
||||
const menu = await getMenuSladovnicka(MONDAY);
|
||||
const polievka = menu[0][0];
|
||||
expect(Array.isArray(polievka.allergens)).toBe(true);
|
||||
expect(polievka.allergens!.length).toBeGreaterThan(0);
|
||||
expect(typeof polievka.allergens![0]).toBe('number');
|
||||
});
|
||||
});
|
||||
|
||||
describe('TechTower parser', () => {
|
||||
beforeEach(() => {
|
||||
mockedAxios.get = jest.fn().mockResolvedValue({ data: loadFixture('techtower.html') });
|
||||
});
|
||||
|
||||
test('vrátí pole o délce 5', async () => {
|
||||
const menu = await getMenuTechTower(MONDAY);
|
||||
expect(menu).toHaveLength(5);
|
||||
});
|
||||
|
||||
test('pondělní menu obsahuje polévku a hlavní jídla', async () => {
|
||||
const menu = await getMenuTechTower(MONDAY);
|
||||
expect(menu[0].some(f => f.isSoup)).toBe(true);
|
||||
expect(menu[0].some(f => !f.isSoup)).toBe(true);
|
||||
});
|
||||
|
||||
test('TechTower hodí StaleWeekError, pokud datum v hlavičce neodpovídá', async () => {
|
||||
// Fixture obsahuje "12.5.-16.5.2025" – jiný týden = stale
|
||||
const jinaStreda = new Date('2025-04-14');
|
||||
await expect(getMenuTechTower(jinaStreda)).rejects.toBeInstanceOf(StaleWeekError);
|
||||
});
|
||||
|
||||
test('StaleWeekError obsahuje naparsovaná data', async () => {
|
||||
const jinaStreda = new Date('2025-04-14');
|
||||
try {
|
||||
await getMenuTechTower(jinaStreda);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(StaleWeekError);
|
||||
const err = e as StaleWeekError;
|
||||
expect(err.food).toHaveLength(5);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('SenkSerikova parser', () => {
|
||||
beforeEach(() => {
|
||||
// SenkSerikova parsuje arraybuffer – musíme vrátit Buffer, ne string
|
||||
mockedAxios.get = jest.fn().mockResolvedValue({
|
||||
data: Buffer.from(loadFixture('senkserikova.html')),
|
||||
headers: {}
|
||||
});
|
||||
});
|
||||
|
||||
test('parser provede HTTP request a vrátí pole', async () => {
|
||||
const menu = await getMenuSenkSerikova(MONDAY);
|
||||
expect(mockedAxios.get).toHaveBeenCalledTimes(1);
|
||||
expect(Array.isArray(menu)).toBe(true);
|
||||
});
|
||||
|
||||
test('výsledné dny s obsahem mají správnou strukturu (name, price, isSoup)', async () => {
|
||||
const menu = await getMenuSenkSerikova(MONDAY);
|
||||
// Protože MONDAY je v minulosti, parser vrátí placeholdery pro všechny pracovní
|
||||
// dny a .menicka elementy přidá za ně – hledáme aspoň jeden den s reálnými daty
|
||||
const denSJidlem = menu.find(den =>
|
||||
den.length > 0 && den[0].name !== 'Pro tento den není uveřejněna nabídka jídel'
|
||||
);
|
||||
if (denSJidlem) {
|
||||
expect(typeof denSJidlem[0].name).toBe('string');
|
||||
expect(typeof denSJidlem[0].isSoup).toBe('boolean');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
const mockStorageData = new Map<string, any>();
|
||||
jest.mock('../storage', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
hasData: async (key: string) => mockStorageData.has(key),
|
||||
getData: async <T>(key: string) => mockStorageData.get(key) as T,
|
||||
setData: async <T>(key: string, val: T) => void mockStorageData.set(key, val),
|
||||
}),
|
||||
storageReady: Promise.resolve(),
|
||||
}));
|
||||
|
||||
import { addChoice, getData } from '../service';
|
||||
import { LunchChoice, MealSlot } from '../../../types/gen/types.gen';
|
||||
|
||||
const TODAY = new Date('2025-01-10');
|
||||
const TODAY_STR = '2025-01-10';
|
||||
const TODAY_EXTRA_STR = '2025-01-10_extra';
|
||||
|
||||
describe('MealSlot storage isolation', () => {
|
||||
beforeEach(() => {
|
||||
mockStorageData.clear();
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(TODAY);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
test('addChoice slot=extra writes only to _extra key, not to obed key', async () => {
|
||||
await addChoice('user1', false, LunchChoice.OBJEDNAVAM, undefined, TODAY, MealSlot.EXTRA);
|
||||
expect(mockStorageData.has(TODAY_EXTRA_STR)).toBe(true);
|
||||
expect(mockStorageData.has(TODAY_STR)).toBe(false);
|
||||
const extraData = mockStorageData.get(TODAY_EXTRA_STR);
|
||||
expect(extraData.choices.OBJEDNAVAM?.['user1']).toBeDefined();
|
||||
});
|
||||
|
||||
test('getData slot=extra returns slot===MealSlot.EXTRA and no menus', async () => {
|
||||
await addChoice('user1', false, LunchChoice.OBJEDNAVAM, undefined, TODAY, MealSlot.EXTRA);
|
||||
const result = await getData(TODAY, MealSlot.EXTRA);
|
||||
expect(result.slot).toBe(MealSlot.EXTRA);
|
||||
expect(result.menus).toBeUndefined();
|
||||
});
|
||||
|
||||
test('addChoice slot=extra does not modify obed data even when obed has PIZZA choice', async () => {
|
||||
mockStorageData.set(TODAY_STR, {
|
||||
choices: { PIZZA: { user1: { selectedFoods: [0], trusted: false } } },
|
||||
todayDayIndex: 4,
|
||||
date: '10. 1. 2025',
|
||||
isWeekend: false,
|
||||
dayIndex: 4,
|
||||
});
|
||||
|
||||
await addChoice('user1', false, LunchChoice.OBJEDNAVAM, undefined, TODAY, MealSlot.EXTRA);
|
||||
|
||||
const obed = mockStorageData.get(TODAY_STR);
|
||||
expect(obed.choices.PIZZA?.['user1']).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
const mockStorageData = new Map<string, any>();
|
||||
jest.mock('../storage', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
hasData: async (key: string) => mockStorageData.has(key),
|
||||
getData: async <T>(key: string) => mockStorageData.get(key) as T,
|
||||
setData: async <T>(key: string, val: T) => void mockStorageData.set(key, val),
|
||||
}),
|
||||
storageReady: Promise.resolve(),
|
||||
}));
|
||||
|
||||
import { getDateForWeekIndex, getMenuKey, getEmptyData } from '../service';
|
||||
import { formatDate } from '../utils';
|
||||
|
||||
// Pin "today" to 2025-01-10 (Friday, week 2) for deterministic tests
|
||||
// Monday of that week = 2025-01-06, ..., Friday = 2025-01-10
|
||||
|
||||
describe('getDateForWeekIndex', () => {
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(new Date('2025-01-10'));
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
test('index 0 (pondělí) vrátí 2025-01-06', () => {
|
||||
expect(formatDate(getDateForWeekIndex(0))).toBe('2025-01-06');
|
||||
});
|
||||
|
||||
test('index 4 (pátek) vrátí 2025-01-10', () => {
|
||||
expect(formatDate(getDateForWeekIndex(4))).toBe('2025-01-10');
|
||||
});
|
||||
|
||||
test('index 2 (středa) vrátí 2025-01-08', () => {
|
||||
expect(formatDate(getDateForWeekIndex(2))).toBe('2025-01-08');
|
||||
});
|
||||
|
||||
test('neplatný index (-1) vrátí dnešek bez vyhození chyby', () => {
|
||||
const result = getDateForWeekIndex(-1);
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
test('neplatný index (5) vrátí dnešek bez vyhození chyby', () => {
|
||||
const result = getDateForWeekIndex(5);
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMenuKey', () => {
|
||||
test('vrátí klíč ve tvaru menu_RRRR_TT', () => {
|
||||
const date = new Date('2025-01-10');
|
||||
const key = getMenuKey(date);
|
||||
expect(key).toMatch(/^menu_\d{4}_\d+$/);
|
||||
});
|
||||
|
||||
test('dvě data ve stejném týdnu mají stejný klíč', () => {
|
||||
expect(getMenuKey(new Date('2025-01-06'))).toBe(getMenuKey(new Date('2025-01-10')));
|
||||
});
|
||||
|
||||
test('dvě data z různých týdnů mají různé klíče', () => {
|
||||
expect(getMenuKey(new Date('2025-01-06'))).not.toBe(getMenuKey(new Date('2025-01-13')));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getEmptyData', () => {
|
||||
test('vrátí strukturu s prázdnými choices', () => {
|
||||
const data = getEmptyData(new Date('2025-01-10'));
|
||||
expect(data.choices).toEqual({});
|
||||
});
|
||||
|
||||
test('vrátí dayIndex=4 pro pátek', () => {
|
||||
const data = getEmptyData(new Date('2025-01-10'));
|
||||
expect(data.dayIndex).toBe(4);
|
||||
});
|
||||
|
||||
test('isWeekend=false pro pracovní den', () => {
|
||||
const data = getEmptyData(new Date('2025-01-10'));
|
||||
expect(data.isWeekend).toBe(false);
|
||||
});
|
||||
|
||||
test('isWeekend=true pro víkend', () => {
|
||||
const data = getEmptyData(new Date('2025-01-11'));
|
||||
expect(data.isWeekend).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.STORAGE = 'memory';
|
||||
process.env.JWT_SECRET = 'test-jwt-secret-ktery-ma-alespon-32-znaku';
|
||||
process.env.LOGOUT_URL = 'http://localhost/logout';
|
||||
delete process.env.MOCK_DATA;
|
||||
@@ -0,0 +1,60 @@
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import bodyParser from 'body-parser';
|
||||
import { generateToken } from '../auth';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import statsRouter from '../routes/statsRoutes';
|
||||
|
||||
function buildApp() {
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use('/api/stats', statsRouter);
|
||||
return app;
|
||||
}
|
||||
|
||||
const TOKEN = `Bearer ${generateToken('testuser')}`;
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
test('GET /stats bez parametrů vrátí 400', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('GET /stats s rozsahem 4 dní vrátí 200', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: '2024-01-08', endDate: '2024-01-12' })
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(200);
|
||||
expect(Array.isArray(res.body)).toBe(true);
|
||||
});
|
||||
|
||||
test('GET /stats s rozsahem nad 4 dní vrátí 400', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: '2024-01-01', endDate: '2024-01-10' })
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('GET /stats s budoucím datem vrátí 400', async () => {
|
||||
const futureStart = '2099-01-01';
|
||||
const futureEnd = '2099-01-05';
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: futureStart, endDate: futureEnd })
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('GET /stats bez tokenu vrátí chybu', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: '2024-01-08', endDate: '2024-01-12' });
|
||||
expect(res.status).toBeGreaterThanOrEqual(400);
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { StorageInterface } from '../storage/StorageInterface';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import MemoryStorage from '../storage/memory';
|
||||
import JsonStorage from '../storage/json';
|
||||
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'luncher-test-'));
|
||||
const tempDbPath = path.join(tempDir, 'test-db.json');
|
||||
|
||||
// Parametrické spuštění stejné sady testů pro obě implementace
|
||||
const implementations: [string, () => StorageInterface, () => void][] = [
|
||||
['MemoryStorage', () => new MemoryStorage(), resetMemoryStorage],
|
||||
['JsonStorage', () => {
|
||||
// Zajistíme čistý stav souboru před každým testem
|
||||
if (fs.existsSync(tempDbPath)) {
|
||||
fs.unlinkSync(tempDbPath);
|
||||
}
|
||||
// JsonStorage načte/vytvoří soubor při inicializaci, musíme obalit
|
||||
const JsonStorageDynamic = require('../storage/json').default;
|
||||
// Přepíšeme dbPath přes prototyp – pro testy použijeme tmpdir
|
||||
const inst = Object.create(JsonStorageDynamic.prototype);
|
||||
const JSONdb = require('simple-json-db');
|
||||
(inst as any).db = new JSONdb(tempDbPath);
|
||||
inst.hasData = async (key: string) => Promise.resolve((inst as any).db.has(key));
|
||||
inst.getData = async (key: string) => (inst as any).db.get(key);
|
||||
inst.setData = async (key: string, data: any) => { (inst as any).db.set(key, data); return Promise.resolve(); };
|
||||
return inst;
|
||||
}, () => {
|
||||
if (fs.existsSync(tempDbPath)) {
|
||||
fs.unlinkSync(tempDbPath);
|
||||
}
|
||||
}],
|
||||
];
|
||||
|
||||
describe.each(implementations)('%s splňuje StorageInterface kontrakt', (name, factory, reset) => {
|
||||
let storage: StorageInterface;
|
||||
|
||||
beforeEach(() => {
|
||||
reset();
|
||||
storage = factory();
|
||||
});
|
||||
|
||||
test('hasData vrátí false pro neexistující klíč', async () => {
|
||||
expect(await storage.hasData('neexistujici')).toBe(false);
|
||||
});
|
||||
|
||||
test('setData + hasData vrátí true', async () => {
|
||||
await storage.setData('klic', { value: 1 });
|
||||
expect(await storage.hasData('klic')).toBe(true);
|
||||
});
|
||||
|
||||
test('setData + getData vrátí uložená data', async () => {
|
||||
const data = { name: 'Jan', score: 42 };
|
||||
await storage.setData('testkey', data);
|
||||
const result = await storage.getData('testkey');
|
||||
expect(result).toEqual(data);
|
||||
});
|
||||
|
||||
test('getData pro neexistující klíč vrátí undefined', async () => {
|
||||
const result = await storage.getData('neexistujici');
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
test('setData přepíše existující data', async () => {
|
||||
await storage.setData('klic', { version: 1 });
|
||||
await storage.setData('klic', { version: 2 });
|
||||
const result = await storage.getData<{ version: number }>('klic');
|
||||
expect(result?.version).toBe(2);
|
||||
});
|
||||
|
||||
test('různé klíče jsou nezávislé', async () => {
|
||||
await storage.setData('a', { val: 'A' });
|
||||
await storage.setData('b', { val: 'B' });
|
||||
expect((await storage.getData<{ val: string }>('a'))?.val).toBe('A');
|
||||
expect((await storage.getData<{ val: string }>('b'))?.val).toBe('B');
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
if (fs.existsSync(tempDir)) {
|
||||
fs.rmSync(tempDir, { recursive: true });
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
import { formatDate, getUsersByLocation, parseToken, checkQueryParams, checkBodyParams, getIsWeekend } from '../utils';
|
||||
|
||||
describe('formatDate', () => {
|
||||
const d = new Date('2025-01-10');
|
||||
|
||||
test('výchozí formát YYYY-MM-DD', () => {
|
||||
expect(formatDate(d)).toBe('2025-01-10');
|
||||
});
|
||||
|
||||
test('vlastní formát DD.MM.YYYY', () => {
|
||||
expect(formatDate(d, 'DD.MM.YYYY')).toBe('10.01.2025');
|
||||
});
|
||||
|
||||
test('nulové doplnění dne a měsíce', () => {
|
||||
expect(formatDate(new Date('2025-03-05'))).toBe('2025-03-05');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getIsWeekend', () => {
|
||||
test('pondělí není víkend', () => {
|
||||
expect(getIsWeekend(new Date('2025-01-06'))).toBe(false);
|
||||
});
|
||||
test('pátek není víkend', () => {
|
||||
expect(getIsWeekend(new Date('2025-01-10'))).toBe(false);
|
||||
});
|
||||
test('sobota je víkend', () => {
|
||||
expect(getIsWeekend(new Date('2025-01-11'))).toBe(true);
|
||||
});
|
||||
test('neděle je víkend', () => {
|
||||
expect(getIsWeekend(new Date('2025-01-12'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUsersByLocation', () => {
|
||||
const choices = {
|
||||
SLADOVNICKA: { alice: { trusted: false, selectedFoods: [] } },
|
||||
TECHTOWER: { bob: { trusted: true, selectedFoods: [] } },
|
||||
} as any;
|
||||
|
||||
test('vrátí spolužáky ze stejného místa', () => {
|
||||
expect(getUsersByLocation(choices, 'alice')).toEqual(['alice']);
|
||||
});
|
||||
|
||||
test('vrátí prázdné pole pro neznámý login', () => {
|
||||
expect(getUsersByLocation(choices, 'charlie')).toEqual([]);
|
||||
});
|
||||
|
||||
test('vrátí prázdné pole pro chybějící login', () => {
|
||||
expect(getUsersByLocation(choices, undefined)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseToken', () => {
|
||||
test('vrátí token z Authorization hlavičky', () => {
|
||||
const req = { headers: { authorization: 'Bearer mytoken' } };
|
||||
expect(parseToken(req)).toBe('mytoken');
|
||||
});
|
||||
|
||||
test('vrátí undefined pro chybějící hlavičku', () => {
|
||||
expect(parseToken({ headers: {} })).toBeUndefined();
|
||||
});
|
||||
|
||||
test('vrátí undefined pro chybějící req', () => {
|
||||
expect(parseToken(undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkQueryParams', () => {
|
||||
test('nevyhodí chybu pro přítomné parametry', () => {
|
||||
const req = { query: { date: '2025-01-10', location: 'SLADOVNICKA' } };
|
||||
expect(() => checkQueryParams(req, ['date', 'location'])).not.toThrow();
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro chybějící parametr', () => {
|
||||
const req = { query: { date: '2025-01-10' } };
|
||||
expect(() => checkQueryParams(req, ['date', 'location'])).toThrow("'location'");
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkBodyParams', () => {
|
||||
test('nevyhodí chybu pro přítomné parametry', () => {
|
||||
const req = { body: { login: 'alice' } };
|
||||
expect(() => checkBodyParams(req, ['login'])).not.toThrow();
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro chybějící parametr', () => {
|
||||
const req = { body: {} };
|
||||
expect(() => checkBodyParams(req, ['login'])).toThrow("'login'");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { getUserVotes, updateFeatureVote, getVotingStats } from '../voting';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import { FeatureRequest } from '../../../types/gen/types.gen';
|
||||
|
||||
const OPT_A = FeatureRequest.STATISTICS;
|
||||
const OPT_B = FeatureRequest.UI;
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
describe('updateFeatureVote', () => {
|
||||
test('přidá hlas pro nového uživatele', async () => {
|
||||
const result = await updateFeatureVote('alice', OPT_A, true);
|
||||
expect(result['alice']).toContain(OPT_A);
|
||||
});
|
||||
|
||||
test('vyhodí chybu při duplicitním hlasování', async () => {
|
||||
await updateFeatureVote('alice', OPT_A, true);
|
||||
await expect(updateFeatureVote('alice', OPT_A, true)).rejects.toThrow('hlasovali');
|
||||
});
|
||||
|
||||
test('odebere hlas', async () => {
|
||||
await updateFeatureVote('alice', OPT_A, true);
|
||||
await updateFeatureVote('alice', OPT_A, false);
|
||||
const stats = await getVotingStats();
|
||||
expect(stats[OPT_A] ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
test('odebrání neexistujícího hlasu je no-op', async () => {
|
||||
await expect(updateFeatureVote('alice', OPT_A, false)).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
test('odebrání posledního hlasu odstraní login ze storage', async () => {
|
||||
await updateFeatureVote('alice', OPT_A, true);
|
||||
const data = await updateFeatureVote('alice', OPT_A, false);
|
||||
expect('alice' in data).toBe(false);
|
||||
});
|
||||
|
||||
test('vyhodí chybu po 4 hlasech', async () => {
|
||||
const options = Object.values(FeatureRequest);
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await updateFeatureVote('alice', options[i], true);
|
||||
}
|
||||
await expect(updateFeatureVote('alice', options[4], true)).rejects.toThrow('4');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUserVotes', () => {
|
||||
test('vrátí hlasy uživatele', async () => {
|
||||
await updateFeatureVote('alice', OPT_A, true);
|
||||
const votes = await getUserVotes('alice');
|
||||
expect(votes).toContain(OPT_A);
|
||||
});
|
||||
|
||||
test('vrátí prázdné pole pro uživatele bez hlasů', async () => {
|
||||
const votes = await getUserVotes('neexistujici');
|
||||
expect(votes).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getVotingStats', () => {
|
||||
test('vrátí agregované počty hlasů', async () => {
|
||||
await updateFeatureVote('alice', OPT_A, true);
|
||||
await updateFeatureVote('bob', OPT_A, true);
|
||||
await updateFeatureVote('bob', OPT_B, true);
|
||||
|
||||
const stats = await getVotingStats();
|
||||
expect(stats[OPT_A]).toBe(2);
|
||||
expect(stats[OPT_B]).toBe(1);
|
||||
});
|
||||
|
||||
test('vrátí prázdný objekt bez hlasů', async () => {
|
||||
const stats = await getVotingStats();
|
||||
expect(stats).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import bodyParser from 'body-parser';
|
||||
import { generateToken } from '../auth';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import { FeatureRequest } from '../../../types/gen/types.gen';
|
||||
import votingRouter from '../routes/votingRoutes';
|
||||
|
||||
const VALID_OPTION = FeatureRequest.STATISTICS;
|
||||
|
||||
function buildApp() {
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use('/api/voting', votingRouter);
|
||||
app.use((err: any, _req: any, res: any, _next: any) => {
|
||||
res.status(400).json({ error: err.message });
|
||||
});
|
||||
return app;
|
||||
}
|
||||
|
||||
const TOKEN = `Bearer ${generateToken('testuser')}`;
|
||||
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
test('GET /getVotes vrátí 200 s prázdným polem pro nového uživatele', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/voting/getVotes')
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual([]);
|
||||
});
|
||||
|
||||
test('GET /getVotes vrátí 401 bez tokenu', async () => {
|
||||
const res = await request(buildApp()).get('/api/voting/getVotes');
|
||||
expect(res.status).toBeGreaterThanOrEqual(400);
|
||||
});
|
||||
|
||||
test('POST /updateVote přidá hlas a vrátí 200', async () => {
|
||||
const res = await request(buildApp())
|
||||
.post('/api/voting/updateVote')
|
||||
.set('Authorization', TOKEN)
|
||||
.send({ option: VALID_OPTION, active: true });
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
test('POST /updateVote vrátí 400 pro chybějící parametry', async () => {
|
||||
const res = await request(buildApp())
|
||||
.post('/api/voting/updateVote')
|
||||
.set('Authorization', TOKEN)
|
||||
.send({});
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('POST /updateVote vrátí 400 při duplicitním hlasu', async () => {
|
||||
const app = buildApp();
|
||||
await request(app)
|
||||
.post('/api/voting/updateVote')
|
||||
.set('Authorization', TOKEN)
|
||||
.send({ option: VALID_OPTION, active: true });
|
||||
const res = await request(app)
|
||||
.post('/api/voting/updateVote')
|
||||
.set('Authorization', TOKEN)
|
||||
.send({ option: VALID_OPTION, active: true });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('hlasovali');
|
||||
});
|
||||
|
||||
test('GET /stats vrátí 200 s objektem', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/voting/stats')
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(200);
|
||||
expect(typeof res.body).toBe('object');
|
||||
});
|
||||
@@ -3,6 +3,9 @@
|
||||
"src/**/*",
|
||||
"../types/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"src/tests/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "Node16",
|
||||
|
||||
+124
-2
@@ -1448,6 +1448,18 @@
|
||||
"@emnapi/runtime" "^1.4.3"
|
||||
"@tybys/wasm-util" "^0.10.0"
|
||||
|
||||
"@noble/hashes@^1.1.5":
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.8.0.tgz#cee43d801fcef9644b11b8194857695acd5f815a"
|
||||
integrity sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==
|
||||
|
||||
"@paralleldrive/cuid2@^2.2.2":
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@paralleldrive/cuid2/-/cuid2-2.3.1.tgz#3d62ea9e7be867d3fa94b9897fab5b0ae187d784"
|
||||
integrity sha512-XO7cAxhnTZl0Yggq6jOgjiOHhbgcO4NqFqwSmQpjK3b6TEE6Uj/jfSk6wzYyemh3+I0sHirKSetjQwn5cZktFw==
|
||||
dependencies:
|
||||
"@noble/hashes" "^1.1.5"
|
||||
|
||||
"@pkgjs/parseargs@^0.11.0":
|
||||
version "0.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
|
||||
@@ -1594,6 +1606,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/cookiejar@^2.1.5":
|
||||
version "2.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78"
|
||||
integrity sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==
|
||||
|
||||
"@types/cors@^2.8.12":
|
||||
version "2.8.19"
|
||||
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.19.tgz#d93ea2673fd8c9f697367f5eeefc2bbfa94f0342"
|
||||
@@ -1660,6 +1677,11 @@
|
||||
"@types/ms" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/methods@^1.1.4":
|
||||
version "1.1.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/methods/-/methods-1.1.4.tgz#d3b7ac30ac47c91054ea951ce9eed07b1051e547"
|
||||
integrity sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==
|
||||
|
||||
"@types/ms@*":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-2.1.0.tgz#052aa67a48eccc4309d7f0191b7e41434b90bb78"
|
||||
@@ -1727,6 +1749,24 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
|
||||
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
|
||||
|
||||
"@types/superagent@^8.1.0":
|
||||
version "8.1.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-8.1.9.tgz#28bfe4658e469838ed0bf66d898354bcab21f49f"
|
||||
integrity sha512-pTVjI73witn+9ILmoJdajHGW2jkSaOzhiFYF1Rd3EQ94kymLqB9PjD9ISg7WaALC7+dCHT0FGe9T2LktLq/3GQ==
|
||||
dependencies:
|
||||
"@types/cookiejar" "^2.1.5"
|
||||
"@types/methods" "^1.1.4"
|
||||
"@types/node" "*"
|
||||
form-data "^4.0.0"
|
||||
|
||||
"@types/supertest@^6.0.0":
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/supertest/-/supertest-6.0.3.tgz#d736f0e994b195b63e1c93e80271a2faf927388c"
|
||||
integrity sha512-8WzXq62EXFhJ7QsH3Ocb/iKQ/Ty9ZVWnVzoTKc9tyyFRRF3a74Tk2+TLFgaFFw364Ere+npzHKEJ6ga2LzIL7w==
|
||||
dependencies:
|
||||
"@types/methods" "^1.1.4"
|
||||
"@types/superagent" "^8.1.0"
|
||||
|
||||
"@types/tough-cookie@*":
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304"
|
||||
@@ -1940,6 +1980,11 @@ argparse@^1.0.7:
|
||||
dependencies:
|
||||
sprintf-js "~1.0.2"
|
||||
|
||||
asap@^2.0.0:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
|
||||
integrity sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==
|
||||
|
||||
asn1.js@^5.3.0:
|
||||
version "5.4.1"
|
||||
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07"
|
||||
@@ -2294,6 +2339,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8:
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
component-emitter@^1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.1.tgz#ef1d5796f7d93f135ee6fb684340b26403c97d17"
|
||||
integrity sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
@@ -2314,7 +2364,7 @@ convert-source-map@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
|
||||
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==
|
||||
|
||||
cookie-signature@^1.2.1:
|
||||
cookie-signature@^1.2.1, cookie-signature@^1.2.2:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.2.2.tgz#57c7fc3cc293acab9fec54d73e15690ebe4a1793"
|
||||
integrity sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==
|
||||
@@ -2324,6 +2374,11 @@ cookie@^0.7.1, cookie@~0.7.2:
|
||||
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7"
|
||||
integrity sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==
|
||||
|
||||
cookiejar@^2.1.4:
|
||||
version "2.1.4"
|
||||
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.4.tgz#ee669c1fea2cf42dc31585469d193fef0d65771b"
|
||||
integrity sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==
|
||||
|
||||
core-js-compat@^3.43.0:
|
||||
version "3.47.0"
|
||||
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.47.0.tgz#698224bbdbb6f2e3f39decdda4147b161e3772a3"
|
||||
@@ -2369,7 +2424,7 @@ css-what@^6.1.0:
|
||||
resolved "https://registry.yarnpkg.com/css-what/-/css-what-6.1.0.tgz#fb5effcf76f1ddea2c81bdfaa4de44e79bac70f4"
|
||||
integrity sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==
|
||||
|
||||
debug@4, debug@^4, debug@^4.1.0, debug@^4.3.1, debug@^4.4.0, debug@^4.4.1, debug@^4.4.3, debug@~4.4.1:
|
||||
debug@4, debug@^4, debug@^4.1.0, debug@^4.3.1, debug@^4.3.7, debug@^4.4.0, debug@^4.4.1, debug@^4.4.3, debug@~4.4.1:
|
||||
version "4.4.3"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a"
|
||||
integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==
|
||||
@@ -2408,6 +2463,14 @@ detect-newline@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
|
||||
integrity sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==
|
||||
|
||||
dezalgo@^1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.4.tgz#751235260469084c132157dfa857f386d4c33d81"
|
||||
integrity sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==
|
||||
dependencies:
|
||||
asap "^2.0.0"
|
||||
wrappy "1"
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
@@ -2681,6 +2744,11 @@ fast-json-stable-stringify@^2.1.0:
|
||||
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
|
||||
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
|
||||
|
||||
fast-safe-stringify@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz#c406a83b6e70d9e35ce3b30a81141df30aeba884"
|
||||
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==
|
||||
|
||||
fb-watchman@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/fb-watchman/-/fb-watchman-2.0.2.tgz#e9524ee6b5c77e9e5001af0f85f3adbb8623255c"
|
||||
@@ -2738,6 +2806,17 @@ form-data@^2.5.0:
|
||||
mime-types "^2.1.12"
|
||||
safe-buffer "^5.2.1"
|
||||
|
||||
form-data@^4.0.0, form-data@^4.0.5:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.5.tgz#b49e48858045ff4cbf6b03e1805cebcad3679053"
|
||||
integrity sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
es-set-tostringtag "^2.1.0"
|
||||
hasown "^2.0.2"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
form-data@^4.0.4:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
|
||||
@@ -2749,6 +2828,15 @@ form-data@^4.0.4:
|
||||
hasown "^2.0.2"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
formidable@^3.5.4:
|
||||
version "3.5.4"
|
||||
resolved "https://registry.yarnpkg.com/formidable/-/formidable-3.5.4.tgz#ac9a593b951e829b3298f21aa9a2243932f32ed9"
|
||||
integrity sha512-YikH+7CUTOtP44ZTnUhR7Ic2UASBPOqmaRkRKxRbywPTe5VxF7RRCck4af9wutiZ/QKM5nME9Bie2fFaPz5Gug==
|
||||
dependencies:
|
||||
"@paralleldrive/cuid2" "^2.2.2"
|
||||
dezalgo "^1.0.4"
|
||||
once "^1.4.0"
|
||||
|
||||
forwarded@0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
|
||||
@@ -3624,6 +3712,11 @@ merge-stream@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
||||
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
|
||||
|
||||
methods@^1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
|
||||
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==
|
||||
|
||||
micromatch@^4.0.8:
|
||||
version "4.0.8"
|
||||
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202"
|
||||
@@ -3656,6 +3749,11 @@ mime-types@^3.0.0, mime-types@^3.0.2:
|
||||
dependencies:
|
||||
mime-db "^1.54.0"
|
||||
|
||||
mime@2.6.0:
|
||||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367"
|
||||
integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==
|
||||
|
||||
mimic-fn@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
|
||||
@@ -4337,6 +4435,30 @@ strip-json-comments@^3.1.1:
|
||||
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
|
||||
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
|
||||
|
||||
superagent@^10.3.0:
|
||||
version "10.3.0"
|
||||
resolved "https://registry.yarnpkg.com/superagent/-/superagent-10.3.0.tgz#ff1e39e7976b63f8084291d65f5bfbbbbd156989"
|
||||
integrity sha512-B+4Ik7ROgVKrQsXTV0Jwp2u+PXYLSlqtDAhYnkkD+zn3yg8s/zjA2MeGayPoY/KICrbitwneDHrjSotxKL+0XQ==
|
||||
dependencies:
|
||||
component-emitter "^1.3.1"
|
||||
cookiejar "^2.1.4"
|
||||
debug "^4.3.7"
|
||||
fast-safe-stringify "^2.1.1"
|
||||
form-data "^4.0.5"
|
||||
formidable "^3.5.4"
|
||||
methods "^1.1.2"
|
||||
mime "2.6.0"
|
||||
qs "^6.14.1"
|
||||
|
||||
supertest@^7.0.0:
|
||||
version "7.2.2"
|
||||
resolved "https://registry.yarnpkg.com/supertest/-/supertest-7.2.2.tgz#dac3ee25a2aa59942a7f641e50c838a7c8819204"
|
||||
integrity sha512-oK8WG9diS3DlhdUkcFn4tkNIiIbBx9lI2ClF8K+b2/m8Eyv47LSawxUzZQSNKUrVb2KsqeTDCcjAAVPYaSLVTA==
|
||||
dependencies:
|
||||
cookie-signature "^1.2.2"
|
||||
methods "^1.1.2"
|
||||
superagent "^10.3.0"
|
||||
|
||||
supports-color@^5.5.0:
|
||||
version "5.5.0"
|
||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
|
||||
|
||||
Reference in New Issue
Block a user