936b33cc80
CI / Generate TypeScript types (push) Successful in 18s
CI / Generate TypeScript types (pull_request) Successful in 9s
CI / Server unit tests (push) Successful in 21s
CI / Build client (push) Successful in 40s
CI / Server unit tests (pull_request) Successful in 21s
CI / Build server (pull_request) Successful in 24s
CI / Build server (push) Has been cancelled
CI / Playwright E2E tests (push) Has been cancelled
CI / Build and push Docker image (push) Has been cancelled
CI / Notify (push) Has been cancelled
CI / Build client (pull_request) Has been cancelled
CI / Playwright E2E tests (pull_request) Has been cancelled
CI / Build and push Docker image (pull_request) Has been cancelled
CI / Notify (pull_request) Has been cancelled
Nahrazuje /vecere novou stránkou /objednani. Místo jednoho OBJEDNAVAM bucketu umožňuje vytvářet více skupin, kde každá objednává z jiného obchodu. - Skupiny mají stavový automat: open → locked → ordered - Obchody spravuje admin heslem (ADMIN_PASSWORD env var) přes modal „Správa obchodů" - Při stavu ordered zakladatel generuje QR kódy platby (nový PayForGroupModal – volné částky bez menu) - PayForAllModal (oběd) upraven: plátce nyní vidí svůj vlastní díl jako informační řádek - Nové testy: stores.test.ts + groups.test.ts (36 testů)
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { resetMemoryStorage } from '../storage/memory';
|
|
import { getStores, addStore, removeStore } from '../stores';
|
|
|
|
const ADMIN_PW = 'testadmin';
|
|
|
|
beforeEach(() => {
|
|
resetMemoryStorage();
|
|
process.env.ADMIN_PASSWORD = ADMIN_PW;
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete process.env.ADMIN_PASSWORD;
|
|
});
|
|
|
|
describe('getStores', () => {
|
|
test('vrátí prázdné pole, pokud seznam neexistuje', async () => {
|
|
const stores = await getStores();
|
|
expect(stores).toEqual([]);
|
|
});
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
test('vyhodí UNAUTHORIZED s nesprávným heslem', async () => {
|
|
await expect(addStore('KFC', 'spatne')).rejects.toThrow('UNAUTHORIZED');
|
|
});
|
|
|
|
test('vyhodí UNAUTHORIZED pokud ADMIN_PASSWORD není nastaven', async () => {
|
|
delete process.env.ADMIN_PASSWORD;
|
|
await expect(addStore('KFC', '')).rejects.toThrow('UNAUTHORIZED');
|
|
});
|
|
|
|
test('odmítne prázdný název', async () => {
|
|
await expect(addStore(' ', ADMIN_PW)).rejects.toThrow('prázdný');
|
|
});
|
|
|
|
test('odmítne duplikát (case-insensitive)', async () => {
|
|
await addStore('McDonald\'s', ADMIN_PW);
|
|
await expect(addStore('mcdonald\'s', ADMIN_PW)).rejects.toThrow('existuje');
|
|
});
|
|
|
|
test('vrátí aktualizovaný seznam', async () => {
|
|
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');
|
|
});
|
|
});
|
|
|
|
describe('removeStore', () => {
|
|
beforeEach(async () => {
|
|
await addStore('McDonald\'s', ADMIN_PW);
|
|
});
|
|
|
|
test('odebere obchod se správným heslem', async () => {
|
|
const stores = await removeStore('McDonald\'s', ADMIN_PW);
|
|
expect(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');
|
|
});
|
|
|
|
test('vyhodí UNAUTHORIZED s nesprávným heslem', async () => {
|
|
await expect(removeStore('McDonald\'s', 'spatne')).rejects.toThrow('UNAUTHORIZED');
|
|
});
|
|
|
|
test('odebrání neexistujícího obchodu nic nerozbije', async () => {
|
|
const stores = await removeStore('Neexistuje', ADMIN_PW);
|
|
expect(stores).toContain('McDonald\'s');
|
|
});
|
|
});
|