feat: proklik na stránky podniku ze stránky objednávek
CI / Generate TypeScript types (push) Successful in 9s
CI / Server unit tests (push) Successful in 21s
CI / Build server (push) Successful in 25s
CI / Build client (push) Successful in 37s
CI / Playwright E2E tests (push) Successful in 1m18s
CI / Build and push Docker image (push) Successful in 39s
CI / Notify (push) Successful in 2s

This commit is contained in:
2026-06-10 19:09:20 +02:00
parent cc09ddbd2c
commit 88b9e20e2d
11 changed files with 154 additions and 36 deletions
+35 -6
View File
@@ -1,8 +1,12 @@
import { resetMemoryStorage } from '../storage/memory';
import getStorage from '../storage';
import { getStores, addStore, removeStore } from '../stores';
const ADMIN_PW = 'testadmin';
/** Vrátí pole názvů obchodů pro snadné porovnání v testech. */
const names = (stores: { name: string }[]) => stores.map(s => s.name);
beforeEach(() => {
resetMemoryStorage();
process.env.ADMIN_PASSWORD = ADMIN_PW;
@@ -17,12 +21,37 @@ describe('getStores', () => {
const stores = await getStores();
expect(stores).toEqual([]);
});
test('převede starý formát (pole řetězců) na objekty', async () => {
// Simulace dat uložených ve starším formátu (před zavedením URL)
await getStorage().setData('stores', ['McDonald\'s', 'KFC']);
const stores = await getStores();
expect(stores).toEqual([{ name: 'McDonald\'s' }, { name: 'KFC' }]);
});
});
describe('addStore', () => {
test('přidá obchod se správným heslem', async () => {
const stores = await addStore('McDonald\'s', ADMIN_PW);
expect(stores).toContain('McDonald\'s');
expect(names(stores)).toContain('McDonald\'s');
});
test('uloží volitelnou URL a ořízne mezery', async () => {
const stores = await addStore('Bistro', ADMIN_PW, ' https://wolt.com/bistro ');
expect(stores).toContainEqual({ name: 'Bistro', url: 'https://wolt.com/bistro' });
});
test('bez URL uloží obchod bez pole url', async () => {
const stores = await addStore('KFC', ADMIN_PW, ' ');
expect(stores).toContainEqual({ name: 'KFC' });
});
test('odmítne URL s nepovoleným schématem (javascript:)', async () => {
await expect(addStore('Zlo', ADMIN_PW, 'javascript:alert(1)')).rejects.toThrow('http');
});
test('odmítne nevalidní URL', async () => {
await expect(addStore('Zlo', ADMIN_PW, 'nfdjska')).rejects.toThrow('Neplatná URL');
});
test('vyhodí UNAUTHORIZED s nesprávným heslem', async () => {
@@ -47,8 +76,8 @@ describe('addStore', () => {
await addStore('McDonald\'s', ADMIN_PW);
const stores = await addStore('KFC', ADMIN_PW);
expect(stores).toHaveLength(2);
expect(stores).toContain('McDonald\'s');
expect(stores).toContain('KFC');
expect(names(stores)).toContain('McDonald\'s');
expect(names(stores)).toContain('KFC');
});
});
@@ -59,12 +88,12 @@ describe('removeStore', () => {
test('odebere obchod se správným heslem', async () => {
const stores = await removeStore('McDonald\'s', ADMIN_PW);
expect(stores).not.toContain('McDonald\'s');
expect(names(stores)).not.toContain('McDonald\'s');
});
test('case-insensitive odebrání', async () => {
const stores = await removeStore('MCDONALD\'S', ADMIN_PW);
expect(stores).not.toContain('McDonald\'s');
expect(names(stores)).not.toContain('McDonald\'s');
});
test('vyhodí UNAUTHORIZED s nesprávným heslem', async () => {
@@ -73,6 +102,6 @@ describe('removeStore', () => {
test('odebrání neexistujícího obchodu nic nerozbije', async () => {
const stores = await removeStore('Neexistuje', ADMIN_PW);
expect(stores).toContain('McDonald\'s');
expect(names(stores)).toContain('McDonald\'s');
});
});