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'); }); });