Compare commits
1 Commits
db1fe473cd
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
64d85036fd
|
@@ -1,260 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
|
||||
# ─── 1. Generate OpenAPI types ────────────────────────────────────────────
|
||||
|
||||
generate-types:
|
||||
name: Generate TypeScript types
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- run: npm install -g yarn
|
||||
|
||||
- run: cd types && yarn install --frozen-lockfile && yarn openapi-ts
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: types-gen
|
||||
path: types/gen
|
||||
|
||||
# ─── 2a. Server unit tests ────────────────────────────────────────────────
|
||||
|
||||
server-test:
|
||||
name: Server unit tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: generate-types
|
||||
env:
|
||||
NODE_ENV: test
|
||||
JWT_SECRET: test-secret-min-32-chars-aaaaaaa!
|
||||
MOCK_DATA: "true"
|
||||
STORAGE: json
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- run: npm install -g yarn
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: types-gen
|
||||
path: types/gen
|
||||
|
||||
- run: cd server && yarn install --frozen-lockfile && yarn test
|
||||
|
||||
# ─── 2b. Build server ─────────────────────────────────────────────────────
|
||||
|
||||
server-build:
|
||||
name: Build server
|
||||
runs-on: ubuntu-latest
|
||||
needs: generate-types
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- run: npm install -g yarn
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: types-gen
|
||||
path: types/gen
|
||||
|
||||
- run: cd types && yarn install --frozen-lockfile
|
||||
|
||||
- run: cd server && yarn install --frozen-lockfile && yarn build
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: server-dist
|
||||
path: server/dist
|
||||
|
||||
# ─── 2c. Build client ─────────────────────────────────────────────────────
|
||||
|
||||
client-build:
|
||||
name: Build client
|
||||
runs-on: ubuntu-latest
|
||||
needs: generate-types
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- run: npm install -g yarn
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: types-gen
|
||||
path: types/gen
|
||||
|
||||
- run: cd types && yarn install --frozen-lockfile
|
||||
|
||||
- run: cd client && yarn install --frozen-lockfile && yarn build
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: client-dist
|
||||
path: client/dist
|
||||
|
||||
# ─── 3. Playwright E2E tests ──────────────────────────────────────────────
|
||||
|
||||
e2e:
|
||||
name: Playwright E2E tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ server-build, client-build ]
|
||||
container: mcr.microsoft.com/playwright:v1.59.1-jammy
|
||||
services:
|
||||
redis:
|
||||
image: redis/redis-stack-server:7.4.0-v1
|
||||
env:
|
||||
REDIS_ARGS: "--save '' --loglevel warning"
|
||||
env:
|
||||
CI: "true"
|
||||
NODE_ENV: test
|
||||
JWT_SECRET: test-secret-min-32-chars-aaaaaaa!
|
||||
MOCK_DATA: "true"
|
||||
STORAGE: redis
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: "6379"
|
||||
HTTP_REMOTE_USER_ENABLED: "true"
|
||||
HTTP_REMOTE_USER_HEADER_NAME: remote-user
|
||||
HTTP_REMOTE_TRUSTED_IPS: "127.0.0.1,::1,::ffff:127.0.0.1"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: server-dist
|
||||
path: server/dist
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: client-dist
|
||||
path: client/dist
|
||||
|
||||
- name: Install server dependencies
|
||||
run: cd server && yarn install --frozen-lockfile
|
||||
|
||||
- name: Copy client build into server/public
|
||||
run: cp -r client/dist server/public
|
||||
|
||||
- name: Install e2e dependencies and browsers
|
||||
run: cd e2e && yarn install --frozen-lockfile && yarn playwright install firefox
|
||||
--with-deps
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: cd e2e && yarn test
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: |
|
||||
e2e/playwright-report
|
||||
e2e/test-results
|
||||
|
||||
# ─── 4. Build and push Docker image (master only) ─────────────────────────
|
||||
|
||||
docker-build:
|
||||
name: Build and push Docker image
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ server-build, client-build, server-test, e2e ]
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- run: npm install -g yarn
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: server-dist
|
||||
path: server/dist
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: client-dist
|
||||
path: client/dist
|
||||
|
||||
- name: Install server production dependencies
|
||||
run: cd server && yarn install --frozen-lockfile --production
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REPO_URL }}
|
||||
username: ${{ secrets.REPO_USERNAME }}
|
||||
password: ${{ secrets.REPO_PASSWORD }}
|
||||
|
||||
- uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile-Woodpecker
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: ${{ secrets.REPO_URL }}/${{ secrets.REPO_NAME }}:latest
|
||||
|
||||
# ─── 5. Notifications ────────────────────────
|
||||
|
||||
notify:
|
||||
name: Notify
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ server-build, client-build, server-test, e2e, docker-build ]
|
||||
if: always() && github.event_name == 'push'
|
||||
steps:
|
||||
- name: Send webhook
|
||||
env:
|
||||
DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
|
||||
DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
|
||||
NTFY_URL: ${{ secrets.NTFY_URL }}
|
||||
BUILD_RESULT: ${{ needs.docker-build.result }}
|
||||
RUN_NUMBER: ${{ github.run_number }}
|
||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{
|
||||
github.run_id }}
|
||||
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
||||
COMMIT_AUTHOR: ${{ github.event.head_commit.author.name }}
|
||||
run: |
|
||||
if [ "$BUILD_RESULT" = "success" ]; then
|
||||
MSG="✅ Sestavení #${RUN_NUMBER} proběhlo úspěšně."
|
||||
NTFY_TAGS="white_check_mark"
|
||||
else
|
||||
MSG="❌ Sestavení #${RUN_NUMBER} selhalo."
|
||||
NTFY_TAGS="x"
|
||||
fi
|
||||
FULL_MSG="$(printf '%s\n\nPipeline: %s\nPoslední commit: %sAutor: %s' \
|
||||
"$MSG" "$RUN_URL" "$COMMIT_MESSAGE" "$COMMIT_AUTHOR")"
|
||||
curl -s -X POST \
|
||||
"https://discord.com/api/webhooks/${DISCORD_WEBHOOK_ID}/${DISCORD_WEBHOOK_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data "$(jq -n --arg content "$FULL_MSG" '{content: $content}')"
|
||||
curl -s -X POST "${NTFY_URL}" \
|
||||
-H "Title: Luncher CI #${RUN_NUMBER}" \
|
||||
-H "Tags: ${NTFY_TAGS}" \
|
||||
-H "Click: ${RUN_URL}" \
|
||||
-d "${FULL_MSG}"
|
||||
+1
-4
@@ -1,6 +1,3 @@
|
||||
node_modules
|
||||
types/gen
|
||||
**.DS_Store
|
||||
.mcp.json
|
||||
.claude/settings.local.json
|
||||
server/public/
|
||||
**.DS_Store
|
||||
@@ -0,0 +1,70 @@
|
||||
variables:
|
||||
- &node_image "node:22-alpine"
|
||||
- &branch "master"
|
||||
|
||||
when:
|
||||
- event: push
|
||||
branch: *branch
|
||||
|
||||
steps:
|
||||
- name: Generate TypeScript types
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd types
|
||||
- yarn install --frozen-lockfile
|
||||
- yarn openapi-ts
|
||||
- name: Install server dependencies
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd server
|
||||
- yarn install --frozen-lockfile
|
||||
depends_on: [Generate TypeScript types]
|
||||
- name: Install client dependencies
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd client
|
||||
- yarn install --frozen-lockfile
|
||||
depends_on: [Generate TypeScript types]
|
||||
- name: Test server
|
||||
depends_on: [Install server dependencies]
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd server
|
||||
- yarn test
|
||||
- name: Build server
|
||||
depends_on: [Test server]
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd server
|
||||
- yarn build
|
||||
- name: Build client
|
||||
depends_on: [Install client dependencies]
|
||||
image: *node_image
|
||||
commands:
|
||||
- cd client
|
||||
- yarn build
|
||||
- name: Build Docker image
|
||||
depends_on: [Build server, Build client]
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
settings:
|
||||
dockerfile: Dockerfile-Woodpecker
|
||||
platforms: linux/amd64
|
||||
registry:
|
||||
from_secret: REPO_URL
|
||||
username:
|
||||
from_secret: REPO_USERNAME
|
||||
password:
|
||||
from_secret: REPO_PASSWORD
|
||||
repo:
|
||||
from_secret: REPO_NAME
|
||||
- name: Discord notification - build
|
||||
image: appleboy/drone-discord
|
||||
depends_on: [Build Docker image]
|
||||
when:
|
||||
- status: [success, failure]
|
||||
settings:
|
||||
webhook_id:
|
||||
from_secret: DISCORD_WEBHOOK_ID
|
||||
webhook_token:
|
||||
from_secret: DISCORD_WEBHOOK_TOKEN
|
||||
message: "{{#success build.status}}✅ Sestavení {{build.number}} proběhlo úspěšně.{{else}}❌ Sestavení {{build.number}} selhalo.{{/success}}\n\nPipeline: {{build.link}}\nPoslední commit: {{commit.message}}Autor: {{commit.author}}"
|
||||
@@ -1,3 +0,0 @@
|
||||
node_modules/
|
||||
playwright-report/
|
||||
test-results/
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "@luncher/e2e",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "playwright test",
|
||||
"test:ui": "playwright test --ui",
|
||||
"test:debug": "playwright test --debug",
|
||||
"report": "playwright show-report"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.50.0",
|
||||
"@types/node": "^22.0.0",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import path from 'path';
|
||||
|
||||
// Use 127.0.0.1 explicitly — on Node.js 18+/Windows, `localhost` may resolve to ::1
|
||||
// (IPv6) while the HTTP server only binds to 0.0.0.0 (IPv4), causing the webServer
|
||||
// readiness poll to time out even though the server is listening.
|
||||
const BASE_URL = process.env.E2E_BASE_URL ?? 'http://127.0.0.1:3001';
|
||||
|
||||
// Server env vars injected for local runs. In CI these are set at the step level.
|
||||
const serverEnv: Record<string, string> = {
|
||||
NODE_ENV: 'test',
|
||||
MOCK_DATA: 'true',
|
||||
STORAGE: process.env.STORAGE ?? 'json',
|
||||
JWT_SECRET: process.env.JWT_SECRET ?? 'e2e-test-secret-min-32-chars-aaaa',
|
||||
HTTP_REMOTE_USER_ENABLED: 'true',
|
||||
HTTP_REMOTE_USER_HEADER_NAME: 'remote-user',
|
||||
HTTP_REMOTE_TRUSTED_IPS: process.env.HTTP_REMOTE_TRUSTED_IPS ?? '127.0.0.1,::1,::ffff:127.0.0.1',
|
||||
};
|
||||
if (process.env.REDIS_HOST) {
|
||||
serverEnv.REDIS_HOST = process.env.REDIS_HOST;
|
||||
serverEnv.REDIS_PORT = process.env.REDIS_PORT ?? '6379';
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests',
|
||||
timeout: 30_000,
|
||||
retries: process.env.CI ? 1 : 0,
|
||||
workers: 1,
|
||||
reporter: [['list'], ['html', { open: 'never' }]],
|
||||
use: {
|
||||
baseURL: BASE_URL,
|
||||
// Default: every test authenticates as e2e-user via trusted header.
|
||||
// Tests that need the real login form should override this in their own context.
|
||||
extraHTTPHeaders: {
|
||||
'remote-user': 'e2e-user',
|
||||
},
|
||||
trace: 'retain-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
},
|
||||
projects: [
|
||||
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
|
||||
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
|
||||
],
|
||||
// Pre-built server must be started before tests. In CI the step does this
|
||||
// explicitly. Locally: build types+server+client, cp -r client/dist server/public,
|
||||
// then `cd e2e && yarn test` OR let webServer below do it if reuseExistingServer=true
|
||||
// is set and the server is already running.
|
||||
webServer: {
|
||||
command: 'node dist/server/src/index.js',
|
||||
cwd: path.resolve(__dirname, '../server'),
|
||||
// Poll a dedicated health endpoint — polling '/' can stall in Express 5 when
|
||||
// server/public/ doesn't exist in the working directory (no finalhandler match).
|
||||
url: `http://127.0.0.1:3001/api/health`,
|
||||
timeout: 15_000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
env: serverEnv,
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
},
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Page, APIRequestContext } from '@playwright/test';
|
||||
|
||||
/** Přihlásí uživatele přes POST /api/login a uloží JWT do localStorage. */
|
||||
export async function loginViaApi(page: Page, login: string): Promise<void> {
|
||||
const response = await page.request.post('/api/login', {
|
||||
headers: { 'Content-Type': 'application/json', 'remote-user': login },
|
||||
data: {},
|
||||
});
|
||||
const token = await response.json() as string;
|
||||
await page.goto('/');
|
||||
await page.evaluate((t) => localStorage.setItem('token', t), token);
|
||||
}
|
||||
|
||||
/** Vyčistí stav pizza dne pro zadaný dayIndex (0=pondělí…4=pátek) přes dev API. */
|
||||
export async function clearPizzaDay(request: APIRequestContext): Promise<void> {
|
||||
const today = new Date('2025-01-10'); // MOCK_DATA pins to Friday = dayIndex 4
|
||||
await request.post('/api/dev/clear', {
|
||||
headers: { 'Content-Type': 'application/json', 'remote-user': 'e2e-user' },
|
||||
data: { dayIndex: 4 },
|
||||
});
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
// Tento test záměrně NEPOUŽÍVÁ trusted-header – testuje reálný login formulář.
|
||||
test.use({ extraHTTPHeaders: {} });
|
||||
|
||||
test('uživatel se přihlásí formulářem a uvidí obsah aplikace', async ({ page }) => {
|
||||
// Server běží s HTTP_REMOTE_USER_ENABLED=true, takže POST /api/login vždy vyžaduje
|
||||
// hlavičku remote-user. Zachytíme požadavky z formuláře (mají tělo s polem login)
|
||||
// a přidáme hlavičku; požadavek auto-loginu (bez těla) projde bez hlavičky a selže,
|
||||
// čímž formulář zůstane viditelný.
|
||||
await page.route('**/api/login', async (route) => {
|
||||
const body = route.request().postData();
|
||||
let login: string | undefined;
|
||||
try { login = body ? JSON.parse(body)?.login : undefined; } catch {}
|
||||
await route.continue({
|
||||
headers: login
|
||||
? { ...route.request().headers(), 'remote-user': login }
|
||||
: route.request().headers(),
|
||||
});
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
// Formulář musí být viditelný – auto-login selhal (nepřišla hlavička)
|
||||
const loginInput = page.locator('#login-input');
|
||||
await expect(loginInput).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Vyplnění loginu a odeslání Enterem
|
||||
await loginInput.fill('testuser');
|
||||
await loginInput.press('Enter');
|
||||
|
||||
// Po přihlášení musí zmizet login formulář
|
||||
await expect(loginInput).not.toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// JWT musí být uloženo v localStorage jako 3-dílný token
|
||||
const token = await page.evaluate(() => localStorage.getItem('token'));
|
||||
expect(token).toBeTruthy();
|
||||
expect((token as string).split('.')).toHaveLength(3);
|
||||
});
|
||||
|
||||
test('trusted-header přihlášení proběhne automaticky bez formuláře', async ({ page, context }) => {
|
||||
// Obnoví trusted header (přepíše prázdný extraHTTPHeaders z test.use výše)
|
||||
await context.setExtraHTTPHeaders({ 'remote-user': 'e2e-auto-user' });
|
||||
await page.goto('/');
|
||||
|
||||
// Login formulář by se neměl nikdy zobrazit, nebo se ihned schová
|
||||
await page.waitForLoadState('networkidle');
|
||||
const loginInput = page.locator('#login-input');
|
||||
await expect(loginInput).not.toBeVisible({ timeout: 5_000 });
|
||||
});
|
||||
@@ -1,70 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { clearPizzaDay } from './helpers';
|
||||
|
||||
test.beforeEach(async ({ page, request }) => {
|
||||
// Vyčistíme volby dne, aby testy neovlivnily navzájem
|
||||
await request.post('/api/dev/clear', {
|
||||
data: { dayIndex: 4 },
|
||||
});
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
// Počkáme, až se zobrazí volba stravování
|
||||
await expect(page.locator('.choice-section select').first()).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
test('výběr restaurace zobrazí seznam jídel', async ({ page }) => {
|
||||
const locationSelect = page.locator('.choice-section select').first();
|
||||
|
||||
// Vybereme Sladovnickou – mock menu existuje
|
||||
await locationSelect.selectOption('SLADOVNICKA');
|
||||
|
||||
// Po výběru restaurace se zobrazí druhý select s jídly
|
||||
const foodSelect = page.locator('.choice-section select').nth(1);
|
||||
await expect(foodSelect).toBeVisible({ timeout: 5_000 });
|
||||
|
||||
// Select musí obsahovat alespoň 2 možnosti (empty + ≥1 jídlo)
|
||||
const options = foodSelect.locator('option');
|
||||
expect(await options.count()).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
test('výběr jídla se uloží a přetrvá po reload', async ({ page }) => {
|
||||
const locationSelect = page.locator('.choice-section select').first();
|
||||
await locationSelect.selectOption('SLADOVNICKA');
|
||||
|
||||
const foodSelect = page.locator('.choice-section select').nth(1);
|
||||
await expect(foodSelect).toBeVisible({ timeout: 5_000 });
|
||||
|
||||
// Vybereme první nenulovou možnost
|
||||
const options = await foodSelect.locator('option:not([value=""])').all();
|
||||
if (options.length === 0) {
|
||||
test.skip(); // Mock data nejsou dostupná pro tuto restauraci
|
||||
}
|
||||
const firstValue = await options[0].getAttribute('value');
|
||||
await foodSelect.selectOption({ value: firstValue! });
|
||||
|
||||
// Počkáme, až se volba přenese na server
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Po reload musí volba přetrvat v tabulce choices
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
const choicesTable = page.locator('.choices-table');
|
||||
await expect(choicesTable).toBeVisible({ timeout: 5_000 });
|
||||
await expect(choicesTable.locator('text=Sladovnická')).toBeVisible();
|
||||
});
|
||||
|
||||
test('přepnutí na NEOBEDVAM odstraní výběr restaurace', async ({ page }) => {
|
||||
// Nejprve zvolíme restauraci
|
||||
const locationSelect = page.locator('.choice-section select').first();
|
||||
await locationSelect.selectOption('SLADOVNICKA');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Přepneme na "Neobědvám"
|
||||
await locationSelect.selectOption('NEOBEDVAM');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Tabulka choices musí zobrazovat "Neobědvám"
|
||||
const choicesTable = page.locator('.choices-table');
|
||||
await expect(choicesTable).toBeVisible({ timeout: 5_000 });
|
||||
await expect(choicesTable.locator('text=Neobědvám')).toBeVisible();
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
// Pizza day testy musí běžet sekvenčně (sdílejí stav mock dne)
|
||||
test.describe.serial('pizza day životní cyklus', () => {
|
||||
|
||||
test.beforeEach(async ({ request }) => {
|
||||
// Vyčistíme data mock dne před každým testem
|
||||
await request.post('/api/dev/clear', { data: { dayIndex: 4 } });
|
||||
});
|
||||
|
||||
test('zobrazí sekci Pizza Day bez aktivního dne', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
// Sekce pizza-section se zobrazí jen pokud má uživatel zvolenou možnost "Pizza day"
|
||||
await page.locator('select').selectOption({ label: 'Pizza day' });
|
||||
await page.waitForLoadState('networkidle');
|
||||
const pizzaSection = page.locator('.pizza-section');
|
||||
await expect(pizzaSection).toBeVisible({ timeout: 10_000 });
|
||||
await expect(pizzaSection.locator('text=není aktuálně založen')).toBeVisible();
|
||||
});
|
||||
|
||||
test('vytvoří, uzamkne a dokončí pizza day', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
// Sekce pizza-section se zobrazí jen pokud má uživatel zvolenou možnost "Pizza day"
|
||||
await page.locator('select').selectOption({ label: 'Pizza day' });
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// --- CREATED ---
|
||||
const createBtn = page.locator('.pizza-section button', { hasText: 'Založit Pizza day' });
|
||||
await expect(createBtn).toBeVisible({ timeout: 10_000 });
|
||||
// Čekáme na odpověď API před reloadem – jinak by reload přerušil probíhající request
|
||||
const createResponse = page.waitForResponse(resp => resp.url().includes('/api/pizzaDay/create'));
|
||||
await createBtn.click();
|
||||
await createResponse;
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('.pizza-section')).toContainText('spravován uživatelem', { timeout: 5_000 });
|
||||
|
||||
// Přidáme pizzu přes API (obejde komplex SelectSearch)
|
||||
const token = await page.evaluate(() => localStorage.getItem('token'));
|
||||
const addResp = await page.request.post('/api/pizzaDay/add', {
|
||||
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
data: { pizzaIndex: 0, pizzaSizeIndex: 0 },
|
||||
});
|
||||
expect(addResp.ok()).toBeTruthy();
|
||||
|
||||
// Reload – server aktualizoval data přes WebSocket, ale reload je jistější
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// --- LOCK ---
|
||||
const lockBtn = page.locator('.pizza-section button', { hasText: 'Uzamknout' });
|
||||
await expect(lockBtn).toBeEnabled({ timeout: 5_000 });
|
||||
await lockBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('.pizza-section')).toContainText('uzamčeny', { timeout: 5_000 });
|
||||
|
||||
// --- ORDERED ---
|
||||
const orderBtn = page.locator('.pizza-section button', { hasText: 'Objednáno' });
|
||||
await expect(orderBtn).toBeEnabled({ timeout: 5_000 });
|
||||
await orderBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('.pizza-section')).toContainText('objednány', { timeout: 5_000 });
|
||||
|
||||
// --- DELIVERED ---
|
||||
const deliverBtn = page.locator('.pizza-section button', { hasText: 'Doručeno' });
|
||||
await expect(deliverBtn).toBeVisible({ timeout: 5_000 });
|
||||
// window.confirm dialog − Playwright automaticky potvrdí
|
||||
page.on('dialog', dialog => dialog.accept());
|
||||
await deliverBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('.pizza-section')).toContainText('doručeny', { timeout: 5_000 });
|
||||
});
|
||||
});
|
||||
@@ -1,79 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page, request }) => {
|
||||
// Naseedujeme 5 uživatelů pro dnešní den – GenerateQrModal pracuje se stávajícími choices
|
||||
await request.post('/api/dev/generate', { data: { dayIndex: 4, count: 5 } });
|
||||
|
||||
// Přednastavíme bankovní účet v localStorage (SettingsContext čte z LS při inicializaci)
|
||||
await page.goto('/');
|
||||
await page.evaluate(() => {
|
||||
localStorage.setItem('bank_account_number', '2400000000/2010');
|
||||
localStorage.setItem('bank_account_holder_name', 'Test User');
|
||||
});
|
||||
// Reload tak, aby SettingsContext načetl nové hodnoty z localStorage
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
test('Nastavení ukládají číslo účtu a jméno do localStorage', async ({ page }) => {
|
||||
// Otevření nastavení
|
||||
await page.locator('#basic-nav-dropdown').click();
|
||||
await page.locator('text=Nastavení').click();
|
||||
|
||||
// Modal musí být viditelný
|
||||
await expect(page.locator('.modal-title')).toContainText('Nastavení', { timeout: 5_000 });
|
||||
|
||||
// Změníme číslo účtu – pressSequentially zajistí spuštění React onChange na každý znak
|
||||
// Číslo 1000000005 je platné (kontrolní součet mod 11 = 0), jinak by validace zamítla uložení
|
||||
const accountInput = page.getByPlaceholder('123456-1234567890/1234');
|
||||
await accountInput.click({ clickCount: 3 });
|
||||
await accountInput.pressSequentially('1000000005/5500');
|
||||
|
||||
// Změníme jméno
|
||||
const nameInput = page.getByPlaceholder('Jan Novák');
|
||||
await nameInput.click({ clickCount: 3 });
|
||||
await nameInput.pressSequentially('Nové Jméno');
|
||||
|
||||
// Uložíme a počkáme na zavření modalu
|
||||
await page.locator('.modal-footer button', { hasText: 'Uložit' }).click();
|
||||
await expect(page.locator('.modal')).not.toBeVisible({ timeout: 5_000 });
|
||||
|
||||
// Ověříme v localStorage
|
||||
const bankAccount = await page.evaluate(() => localStorage.getItem('bank_account_number'));
|
||||
const holderName = await page.evaluate(() => localStorage.getItem('bank_account_holder_name'));
|
||||
expect(bankAccount).toBe('1000000005/5500');
|
||||
expect(holderName).toBe('Nové Jméno');
|
||||
});
|
||||
|
||||
test('otevře modal Generování QR kódů pokud je nastaven účet', async ({ page }) => {
|
||||
// Otevření dropdown menu
|
||||
await page.locator('#basic-nav-dropdown').click();
|
||||
await page.locator('text=Generování QR kódů').click();
|
||||
|
||||
// Modal se otevře
|
||||
await expect(page.locator('.modal')).toBeVisible({ timeout: 5_000 });
|
||||
// Modal musí obsahovat seznam uživatelů nebo prázdný stav
|
||||
await expect(page.locator('.modal-body')).toBeVisible();
|
||||
});
|
||||
|
||||
test('upozorní pokud není nastaven bankovní účet', async ({ page }) => {
|
||||
// Odebereme nastavení účtu
|
||||
await page.evaluate(() => {
|
||||
localStorage.removeItem('bank_account_number');
|
||||
localStorage.removeItem('bank_account_holder_name');
|
||||
});
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Dialog místo modalu
|
||||
page.on('dialog', async dialog => {
|
||||
expect(dialog.message()).toContain('číslo účtu');
|
||||
await dialog.accept();
|
||||
});
|
||||
|
||||
await page.locator('#basic-nav-dropdown').click();
|
||||
await page.locator('text=Generování QR kódů').click();
|
||||
|
||||
// Modal se NESMÍ otevřít
|
||||
await expect(page.locator('.modal')).not.toBeVisible({ timeout: 3_000 });
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Trusted-header login runs automatically when Login mounts.
|
||||
// networkidle zaručí, že fetch('/api/data') byl dokončen.
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
test('zobrazí mock datum 10.01.2025', async ({ page }) => {
|
||||
// MOCK_DATA=true pins today to 2025-01-10
|
||||
await expect(page.locator('text=10.01')).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
test('zobrazí čtyři restaurační karty z mock dat', async ({ page }) => {
|
||||
// Každá restaurace je obalena v .restaurant-card
|
||||
const cards = page.locator('.restaurant-card');
|
||||
await expect(cards).toHaveCount(4, { timeout: 10_000 });
|
||||
});
|
||||
|
||||
test('zobrazí alespoň jedno jídlo v menu každé restaurace', async ({ page }) => {
|
||||
await expect(page.locator('.restaurant-card').first()).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Každá karta musí mít aspoň jeden řádek v .food-table
|
||||
const cards = page.locator('.restaurant-card');
|
||||
const count = await cards.count();
|
||||
for (let i = 0; i < count; i++) {
|
||||
const card = cards.nth(i);
|
||||
const rows = card.locator('.food-table tr');
|
||||
expect(await rows.count()).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('zobrazí volbu stravování před menu', async ({ page }) => {
|
||||
// Sekce .choice-section obsahuje select pro výběr stravování
|
||||
const choiceSection = page.locator('.choice-section');
|
||||
await expect(choiceSection).toBeVisible({ timeout: 10_000 });
|
||||
await expect(choiceSection.locator('select').first()).toBeVisible();
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@playwright/test@^1.50.0":
|
||||
version "1.59.1"
|
||||
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.59.1.tgz#5c4d38eac84a61527af466602ae20277685a02d6"
|
||||
integrity sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==
|
||||
dependencies:
|
||||
playwright "1.59.1"
|
||||
|
||||
"@types/node@^22.0.0":
|
||||
version "22.19.17"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.19.17.tgz#09c71fb34ba2510f8ac865361b1fcb9552b8a581"
|
||||
integrity sha512-wGdMcf+vPYM6jikpS/qhg6WiqSV/OhG+jeeHT/KlVqxYfD40iYJf9/AE1uQxVWFvU7MipKRkRv8NSHiCGgPr8Q==
|
||||
dependencies:
|
||||
undici-types "~6.21.0"
|
||||
|
||||
fsevents@2.3.2:
|
||||
version "2.3.2"
|
||||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
|
||||
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
|
||||
|
||||
playwright-core@1.59.1:
|
||||
version "1.59.1"
|
||||
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.59.1.tgz#d8a2b28bcb8f2bd08ef3df93b02ae83c813244b2"
|
||||
integrity sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==
|
||||
|
||||
playwright@1.59.1:
|
||||
version "1.59.1"
|
||||
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.59.1.tgz#f7b0ca61637ae25264cec370df671bbe1f368a4a"
|
||||
integrity sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==
|
||||
dependencies:
|
||||
playwright-core "1.59.1"
|
||||
optionalDependencies:
|
||||
fsevents "2.3.2"
|
||||
|
||||
typescript@^5.9.3:
|
||||
version "5.9.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f"
|
||||
integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==
|
||||
|
||||
undici-types@~6.21.0:
|
||||
version "6.21.0"
|
||||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.21.0.tgz#691d00af3909be93a7faa13be61b3a5b50ef12cb"
|
||||
integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==
|
||||
@@ -2,6 +2,7 @@
|
||||
/dist
|
||||
/resources/easterEggs
|
||||
/src/gen
|
||||
/coverage
|
||||
.env.production
|
||||
.env.development
|
||||
.easter-eggs.json
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['<rootDir>/src/tests/**/*.test.ts'],
|
||||
setupFiles: ['<rootDir>/src/tests/helpers/setupEnv.ts'],
|
||||
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"
|
||||
},
|
||||
|
||||
+3
-10
@@ -10,7 +10,6 @@ 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";
|
||||
@@ -57,10 +56,6 @@ 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' });
|
||||
@@ -194,11 +189,9 @@ 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';
|
||||
|
||||
storageReady.then(() => {
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server listening on ${HOST}, port ${PORT}`);
|
||||
startReminderScheduler();
|
||||
});
|
||||
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í
|
||||
|
||||
+20
-11
@@ -1458,17 +1458,26 @@ export const getSalatListMock = () => {
|
||||
}
|
||||
|
||||
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 [
|
||||
mkDay('24.02.', 0),
|
||||
mkDay('25.02.', 1),
|
||||
mkDay('26.02.', 2),
|
||||
mkDay('27.02.', 3),
|
||||
mkDay('28.02.', 4),
|
||||
{
|
||||
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) }), {}) }
|
||||
}
|
||||
];
|
||||
}
|
||||
+2
-2
@@ -14,7 +14,7 @@ const storage = getStorage();
|
||||
*
|
||||
* @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;
|
||||
@@ -58,7 +58,7 @@ function createStorageKey(customerName: string, id: string): 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);
|
||||
|
||||
@@ -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' && ENVIRONMENT !== 'test') {
|
||||
if (ENVIRONMENT !== 'development') {
|
||||
return res.status(403).json({ error: 'Tento endpoint je dostupný pouze ve vývojovém režimu' });
|
||||
}
|
||||
next();
|
||||
|
||||
@@ -29,7 +29,7 @@ export const getDateForWeekIndex = (index: number) => {
|
||||
}
|
||||
|
||||
/** Vrátí "prázdná" (implicitní) data pro předaný den. */
|
||||
export function getEmptyData(date?: Date): ClientData {
|
||||
function getEmptyData(date?: Date): ClientData {
|
||||
const usedDate = date || getToday();
|
||||
return {
|
||||
todayDayIndex: getDayOfWeekIndex(getToday()),
|
||||
@@ -61,7 +61,7 @@ export async function getData(date?: Date): Promise<ClientData> {
|
||||
* @param date datum
|
||||
* @returns databázový klíč
|
||||
*/
|
||||
export function getMenuKey(date: Date) {
|
||||
function getMenuKey(date: Date) {
|
||||
const weekNumber = getWeekNumber(date);
|
||||
return `${MENU_PREFIX}_${date.getFullYear()}_${weekNumber}`;
|
||||
}
|
||||
|
||||
@@ -3,25 +3,32 @@ 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'");
|
||||
}
|
||||
|
||||
export const storageReady: Promise<void> = storage.initialize
|
||||
? storage.initialize()
|
||||
: Promise.resolve();
|
||||
(async () => {
|
||||
if (storage.initialize) {
|
||||
await storage.initialize();
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
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() {
|
||||
await client.connect();
|
||||
client.connect();
|
||||
}
|
||||
|
||||
async hasData(key: string) {
|
||||
|
||||
@@ -1,79 +1,62 @@
|
||||
import { generateToken, verify, getLogin, getTrusted } from '../auth';
|
||||
|
||||
const VALID_SECRET = 'test-secret-min-32-chars-aaaaaaa!';
|
||||
const VALID_SECRET = 'test-jwt-secret-ktery-ma-alespon-32-znaku';
|
||||
const SHORT_SECRET = 'kratky';
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.JWT_SECRET = VALID_SECRET;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
test('generateToken → getLogin vrátí stejný login', () => {
|
||||
const token = generateToken('jannovak');
|
||||
expect(getLogin(token)).toBe('jannovak');
|
||||
});
|
||||
|
||||
test('getTrusted vrátí false, pokud nebyl příznak předán', () => {
|
||||
const token = generateToken('jannovak');
|
||||
expect(getTrusted(token)).toBe(false);
|
||||
});
|
||||
|
||||
test('getTrusted vrátí true, pokud byl příznak předán jako true', () => {
|
||||
const token = generateToken('jannovak', true);
|
||||
expect(getTrusted(token)).toBe(true);
|
||||
});
|
||||
|
||||
test('verify vrátí true pro platný token', () => {
|
||||
const token = generateToken('jannovak');
|
||||
expect(verify(token)).toBe(true);
|
||||
});
|
||||
|
||||
test('verify vrátí false pro token podepsaný jiným secretem', () => {
|
||||
const token = generateToken('jannovak');
|
||||
process.env.JWT_SECRET = 'uplne-jiny-secret-ktery-ma-take-32-znaku';
|
||||
expect(verify(token)).toBe(false);
|
||||
});
|
||||
|
||||
test('verify vrátí false pro pozměněný token', () => {
|
||||
const token = generateToken('jannovak');
|
||||
const tampered = token.slice(0, -5) + 'xxxxx';
|
||||
expect(verify(tampered)).toBe(false);
|
||||
});
|
||||
|
||||
test('generateToken vyhodí chybu pro chybějící JWT_SECRET', () => {
|
||||
delete process.env.JWT_SECRET;
|
||||
expect(() => generateToken('jannovak')).toThrow('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';
|
||||
expect(() => generateToken('alice')).toThrow('32');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro prázdný login', () => {
|
||||
expect(() => generateToken('')).toThrow('login');
|
||||
expect(() => generateToken(' ')).toThrow('login');
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro chybějící login', () => {
|
||||
expect(() => generateToken(undefined)).toThrow('login');
|
||||
});
|
||||
test('generateToken vyhodí chybu pro příliš krátký JWT_SECRET', () => {
|
||||
process.env.JWT_SECRET = SHORT_SECRET;
|
||||
expect(() => generateToken('jannovak')).toThrow('32');
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
test('generateToken vyhodí chybu pro prázdný login', () => {
|
||||
expect(() => generateToken('')).toThrow();
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
test('generateToken vyhodí chybu pro login obsahující jen mezery', () => {
|
||||
expect(() => generateToken(' ')).toThrow();
|
||||
});
|
||||
|
||||
test('getLogin vyhodí chybu pro chybějící token', () => {
|
||||
expect(() => getLogin(undefined)).toThrow();
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.JWT_SECRET = 'test-secret-min-32-chars-aaaaaaa!';
|
||||
process.env.MOCK_DATA = 'true';
|
||||
process.env.STORAGE = 'json';
|
||||
+122
-126
@@ -1,148 +1,144 @@
|
||||
import { PizzaDayState, PizzaSize } from '../../../types/gen/types.gen';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import getStorage from '../storage';
|
||||
import { formatDate } from '../utils';
|
||||
import {
|
||||
createPizzaDay,
|
||||
addPizzaOrder,
|
||||
removePizzaOrder,
|
||||
updatePizzaFee,
|
||||
lockPizzaDay,
|
||||
} from '../pizza';
|
||||
import { ClientData, PizzaDayState } from '../../../types/gen/types.gen';
|
||||
|
||||
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(),
|
||||
jest.mock('../notifikace', () => ({
|
||||
callNotifikace: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
jest.mock('../notifikace', () => ({ callNotifikace: jest.fn() }));
|
||||
jest.mock('../qr', () => ({ generateQr: jest.fn().mockResolvedValue(undefined) }));
|
||||
jest.mock('../qr', () => ({
|
||||
generateQr: jest.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
// downloadPizzy/downloadSalaty voláme jen když pizzaList/salatList chybí – vyhneme se reálnému HTTP
|
||||
jest.mock('../chefie', () => ({
|
||||
downloadPizzy: jest.fn().mockResolvedValue([
|
||||
{ id: 1, name: 'Margherita', variants: [{ varId: 10, size: 'střední', price: 150 }] },
|
||||
]),
|
||||
downloadPizzy: jest.fn().mockResolvedValue([]),
|
||||
downloadSalaty: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
import {
|
||||
createPizzaDay,
|
||||
deletePizzaDay,
|
||||
lockPizzaDay,
|
||||
unlockPizzaDay,
|
||||
finishPizzaOrder,
|
||||
finishPizzaDelivery,
|
||||
addPizzaOrder,
|
||||
removeAllUserPizzas,
|
||||
} from '../pizza';
|
||||
const today = formatDate(new Date());
|
||||
const CREATOR = 'kreator';
|
||||
const USER = 'uzivatel';
|
||||
|
||||
const PIZZA: any = { id: 1, name: 'Margherita', variants: [] };
|
||||
const SIZE: PizzaSize = { varId: 10, size: 'střední', price: 150 };
|
||||
const PIZZA = { name: 'Margherita', ingredients: [], sizes: [] } as any;
|
||||
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 };
|
||||
|
||||
beforeEach(() => mockStorageData.clear());
|
||||
async function seedPizzaDay(state: PizzaDayState = PizzaDayState.CREATED): Promise<void> {
|
||||
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);
|
||||
}
|
||||
|
||||
describe('createPizzaDay', () => {
|
||||
test('vytvoří pizza day ve stavu CREATED', async () => {
|
||||
const data = await createPizzaDay('alice');
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.CREATED);
|
||||
expect(data.pizzaDay?.creator).toBe('alice');
|
||||
});
|
||||
|
||||
test('vyhodí chybu, pokud pizza day již existuje', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await expect(createPizzaDay('alice')).rejects.toThrow('existuje');
|
||||
});
|
||||
beforeEach(async () => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
describe('deletePizzaDay', () => {
|
||||
test('smaže pizza day tvůrcem', async () => {
|
||||
await createPizzaDay('alice');
|
||||
const data = await deletePizzaDay('alice');
|
||||
expect(data.pizzaDay).toBeUndefined();
|
||||
});
|
||||
|
||||
test('vyhodí chybu pro jiného uživatele', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await expect(deletePizzaDay('bob')).rejects.toThrow();
|
||||
});
|
||||
test('createPizzaDay 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);
|
||||
});
|
||||
|
||||
describe('addPizzaOrder', () => {
|
||||
test('přidá objednávku pizzy', async () => {
|
||||
await createPizzaDay('alice');
|
||||
const data = await addPizzaOrder('bob', PIZZA, SIZE);
|
||||
const bobOrder = data.pizzaDay?.orders?.find(o => o.customer === 'bob');
|
||||
expect(bobOrder?.pizzaList?.length).toBe(1);
|
||||
expect(bobOrder?.totalPrice).toBe(150);
|
||||
});
|
||||
|
||||
test('vyhodí chybu bez aktivního pizza day', async () => {
|
||||
await expect(addPizzaOrder('bob', PIZZA, SIZE)).rejects.toThrow('neexistuje');
|
||||
});
|
||||
test('createPizzaDay vyhodí chybu, pokud pizza day pro dnešek již existuje', async () => {
|
||||
await seedPizzaDay();
|
||||
await expect(createPizzaDay(CREATOR)).rejects.toThrow('již existuje');
|
||||
});
|
||||
|
||||
describe('lockPizzaDay / unlockPizzaDay', () => {
|
||||
test('tvůrce může zamknout pizza day', async () => {
|
||||
await createPizzaDay('alice');
|
||||
const data = await lockPizzaDay('alice');
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.LOCKED);
|
||||
});
|
||||
|
||||
test('jiný uživatel nemůže zamknout pizza day', async () => {
|
||||
await createPizzaDay('alice');
|
||||
// chybová zpráva obsahuje login volajícího (bob), nikoli tvůrce
|
||||
await expect(lockPizzaDay('bob')).rejects.toThrow('bob');
|
||||
});
|
||||
|
||||
test('zamčený pizza day lze odemknout', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await lockPizzaDay('alice');
|
||||
const data = await unlockPizzaDay('alice');
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.CREATED);
|
||||
});
|
||||
|
||||
test('nelze odemknout nezamčený pizza day', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await expect(unlockPizzaDay('alice')).rejects.toThrow(PizzaDayState.LOCKED);
|
||||
});
|
||||
test('addPizzaOrder přičte cenu pizzy k totalPrice objednávky', async () => {
|
||||
await seedPizzaDay();
|
||||
const data = await addPizzaOrder(USER, PIZZA, SIZE_M);
|
||||
const order = data.pizzaDay!.orders!.find(o => o.customer === USER);
|
||||
expect(order?.totalPrice).toBe(SIZE_M.price);
|
||||
expect(order?.pizzaList).toHaveLength(1);
|
||||
});
|
||||
|
||||
describe('finishPizzaOrder', () => {
|
||||
test('přesune pizza day do stavu ORDERED', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await lockPizzaDay('alice');
|
||||
const data = await finishPizzaOrder('alice');
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.ORDERED);
|
||||
});
|
||||
|
||||
test('vyhodí chybu v nesprávném stavu (CREATED)', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await expect(finishPizzaOrder('alice')).rejects.toThrow(PizzaDayState.LOCKED);
|
||||
});
|
||||
test('addPizzaOrder sečte více pizz ve 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);
|
||||
});
|
||||
|
||||
describe('finishPizzaDelivery', () => {
|
||||
test('přesune pizza day do stavu DELIVERED', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await lockPizzaDay('alice');
|
||||
await finishPizzaOrder('alice');
|
||||
const data = await finishPizzaDelivery('alice');
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.DELIVERED);
|
||||
});
|
||||
|
||||
test('vyhodí chybu v nesprávném stavu (LOCKED)', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await lockPizzaDay('alice');
|
||||
await expect(finishPizzaDelivery('alice')).rejects.toThrow(PizzaDayState.ORDERED);
|
||||
});
|
||||
test('addPizzaOrder 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('removeAllUserPizzas', () => {
|
||||
test('odstraní objednávku uživatele', async () => {
|
||||
await createPizzaDay('alice');
|
||||
await addPizzaOrder('bob', PIZZA, SIZE);
|
||||
const data = await removeAllUserPizzas('bob');
|
||||
const bobOrder = data.pizzaDay?.orders?.find(o => o.customer === 'bob');
|
||||
expect(bobOrder).toBeUndefined();
|
||||
});
|
||||
|
||||
test('je no-op bez pizza day', async () => {
|
||||
const data = await removeAllUserPizzas('bob');
|
||||
expect(data.pizzaDay).toBeUndefined();
|
||||
});
|
||||
test('removePizzaOrder 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('removePizzaOrder 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();
|
||||
});
|
||||
|
||||
test('updatePizzaFee 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('updatePizzaFee 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('updatePizzaFee 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');
|
||||
});
|
||||
|
||||
test('lockPizzaDay přepne stav na LOCKED', async () => {
|
||||
await seedPizzaDay();
|
||||
const data = await lockPizzaDay(CREATOR);
|
||||
expect(data.pizzaDay?.state).toBe(PizzaDayState.LOCKED);
|
||||
});
|
||||
|
||||
test('lockPizzaDay vyhodí chybu pro jiného uživatele než tvůrce', async () => {
|
||||
await seedPizzaDay();
|
||||
// Chybová zpráva obsahuje login volajícího (USER), ne tvůrce
|
||||
await expect(lockPizzaDay(USER)).rejects.toThrow(USER);
|
||||
});
|
||||
|
||||
@@ -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('');
|
||||
});
|
||||
@@ -1,106 +0,0 @@
|
||||
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');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
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';
|
||||
|
||||
// MOCK_DATA=true pins "today" to 2025-01-10 (Friday, week 2)
|
||||
// Monday of that week = 2025-01-06, ..., Friday = 2025-01-10
|
||||
|
||||
describe('getDateForWeekIndex', () => {
|
||||
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,4 @@
|
||||
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';
|
||||
@@ -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 });
|
||||
}
|
||||
});
|
||||
@@ -1,90 +0,0 @@
|
||||
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'");
|
||||
});
|
||||
});
|
||||
@@ -1,66 +1,63 @@
|
||||
import { getUserVotes, updateFeatureVote, getVotingStats } from '../voting';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import { FeatureRequest } from '../../../types/gen/types.gen';
|
||||
|
||||
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(),
|
||||
}));
|
||||
const OPT_A = FeatureRequest.STATISTICS;
|
||||
const OPT_B = FeatureRequest.UI;
|
||||
|
||||
import { updateFeatureVote, getVotingStats } from '../voting';
|
||||
|
||||
beforeEach(() => mockStorageData.clear());
|
||||
|
||||
describe('updateFeatureVote', () => {
|
||||
const feat = 'FEATURE_A' as FeatureRequest;
|
||||
|
||||
test('přidá hlas pro nového uživatele', async () => {
|
||||
const result = await updateFeatureVote('alice', feat, true);
|
||||
expect(result['alice']).toContain(feat);
|
||||
});
|
||||
|
||||
test('vyhodí chybu při duplicitním hlasování', async () => {
|
||||
await updateFeatureVote('alice', feat, true);
|
||||
await expect(updateFeatureVote('alice', feat, true)).rejects.toThrow('hlasovali');
|
||||
});
|
||||
|
||||
test('odebere hlas', async () => {
|
||||
await updateFeatureVote('alice', feat, true);
|
||||
await updateFeatureVote('alice', feat, false);
|
||||
const stats = await getVotingStats();
|
||||
expect(stats[feat] ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
test('odebrání neexistujícího hlasu je no-op', async () => {
|
||||
await expect(updateFeatureVote('alice', feat, false)).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
test('vyhodí chybu po 4 hlasech', async () => {
|
||||
const features = ['FA', 'FB', 'FC', 'FD'] as FeatureRequest[];
|
||||
for (const f of features) {
|
||||
await updateFeatureVote('alice', f, true);
|
||||
}
|
||||
await expect(updateFeatureVote('alice', 'FE' as FeatureRequest, true)).rejects.toThrow('4');
|
||||
});
|
||||
beforeEach(() => {
|
||||
resetMemoryStorage();
|
||||
});
|
||||
|
||||
describe('getVotingStats', () => {
|
||||
test('vrátí agregované počty hlasů', async () => {
|
||||
await updateFeatureVote('alice', 'FA' as FeatureRequest, true);
|
||||
await updateFeatureVote('bob', 'FA' as FeatureRequest, true);
|
||||
await updateFeatureVote('bob', 'FB' as FeatureRequest, true);
|
||||
|
||||
const stats = await getVotingStats();
|
||||
expect(stats['FA']).toBe(2);
|
||||
expect(stats['FB']).toBe(1);
|
||||
});
|
||||
|
||||
test('vrátí prázdný objekt bez hlasů', async () => {
|
||||
const stats = await getVotingStats();
|
||||
expect(stats).toEqual({});
|
||||
});
|
||||
test('přidání hlasu a přečtení přes getUserVotes', async () => {
|
||||
await updateFeatureVote('jannovak', OPT_A, true);
|
||||
const votes = await getUserVotes('jannovak');
|
||||
expect(votes).toContain(OPT_A);
|
||||
});
|
||||
|
||||
test('opakované přidání stejného hlasu vyhodí chybu', async () => {
|
||||
await updateFeatureVote('jannovak', OPT_A, true);
|
||||
await expect(updateFeatureVote('jannovak', OPT_A, true))
|
||||
.rejects.toThrow('Pro tuto možnost jste již hlasovali');
|
||||
});
|
||||
|
||||
test('překročení limitu 4 hlasů vyhodí chybu', async () => {
|
||||
const options = Object.values(FeatureRequest);
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await updateFeatureVote('jannovak', options[i], true);
|
||||
}
|
||||
await expect(updateFeatureVote('jannovak', options[4], true))
|
||||
.rejects.toThrow('maximálně 4 možnosti');
|
||||
});
|
||||
|
||||
test('odebrání hlasu funguje správně', async () => {
|
||||
await updateFeatureVote('jannovak', OPT_A, true);
|
||||
await updateFeatureVote('jannovak', OPT_A, false);
|
||||
const votes = await getUserVotes('jannovak');
|
||||
expect(votes).not.toContain(OPT_A);
|
||||
});
|
||||
|
||||
test('odebrání posledního hlasu odstraní login ze storage', async () => {
|
||||
await updateFeatureVote('jannovak', OPT_A, true);
|
||||
const data = await updateFeatureVote('jannovak', OPT_A, false);
|
||||
expect('jannovak' in data).toBe(false);
|
||||
});
|
||||
|
||||
test('getVotingStats vrátí prázdný objekt, pokud nikdo nehlasoval', async () => {
|
||||
const stats = await getVotingStats();
|
||||
expect(stats).toEqual({});
|
||||
});
|
||||
|
||||
test('getVotingStats správně agreguje hlasy více uživatelů', async () => {
|
||||
await updateFeatureVote('jannovak', OPT_A, true);
|
||||
await updateFeatureVote('jannovak', OPT_B, true);
|
||||
await updateFeatureVote('petrfree', OPT_A, true);
|
||||
const stats = await getVotingStats();
|
||||
expect(stats[OPT_A]).toBe(2);
|
||||
expect(stats[OPT_B]).toBe(1);
|
||||
});
|
||||
|
||||
test('getUserVotes vrátí prázdné pole pro uživatele bez hlasů', async () => {
|
||||
const votes = await getUserVotes('neexistujici');
|
||||
expect(votes).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');
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
"../types/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"src/tests/**/*"
|
||||
"src/tests"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
|
||||
+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