feat: zadávání cen
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 28s
CI / Build server (push) Successful in 37s
CI / Build client (push) Successful in 45s
CI / Playwright E2E tests (push) Successful in 2m15s
CI / Build and push Docker image (push) Successful in 45s
CI / Notify (push) Successful in 2s

This commit is contained in:
Ondřej Anděl committed 2026-10-21 09:42:04 +02:00
1 parent 96dc3f0053
commit 9a3987a2fa
13 files changed
+244 -11

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import getStorage from '../storage';
import { resetMemoryStorage } from '../storage/memory';
import { updatePrice } from '../service';
import { ClientData } from '../../../types/gen/types.gen';
const storage = getStorage();
const USER = 'petr';
const DATE = new Date('2025-03-04');
const ISO_DATE = '2025-03-04';
/** Uloží volby uživatelů pro testovací den. */
async function saveChoices(choices: ClientData["choices"]) {
await storage.setData<Partial<ClientData>>(ISO_DATE, { choices });
}
beforeEach(() => {
resetMemoryStorage();
});
describe('updatePrice', () => {
test('nastaví a odstraní cenu u volby podniku', async () => {
await saveChoices({ SPSE: { [USER]: { note: 'polévka' } } });
let data = await updatePrice(USER, false, 9500, DATE);
expect(data.choices.SPSE?.[USER]).toMatchObject({ price: 9500, note: 'polévka' });
data = await updatePrice(USER, false, undefined, DATE);
expect(data.choices.SPSE?.[USER]?.price).toBeUndefined();
expect(data.choices.SPSE?.[USER]?.note).toBe('polévka');
});
test.each(['OBJEDNAVAM', 'PIZZA', 'NEOBEDVAM', 'ROZHODUJI'])('odmítne cenu u volby %s', async (choice) => {
await saveChoices({ [choice]: { [USER]: {} } });
await expect(updatePrice(USER, false, 10000, DATE)).rejects.toThrow('K této volbě nelze zadat cenu');
});
test('odmítne cenu bez vybrané volby i zápornou cenu', async () => {
await saveChoices({ SPSE: { tomas: {} } });
await expect(updatePrice(USER, false, 10000, DATE)).rejects.toThrow('Cenu lze zadat jen k vybrané volbě');
await expect(updatePrice(USER, false, -1, DATE)).rejects.toThrow('Neplatná cena');
});
});
+8
View File
@@ -67,6 +67,14 @@ describe('getUserExportRows', () => {
});
});
test('u volby podniku vyplní uživatelem zadanou cenu', async () => {
await saveLunch('2025-03-04', { SPSE: { [USER]: { price: 9500 } } });
const rows = await getUserExportRows(USER, YEAR, MONTH);
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({ type: 'SPŠE', amount: 9500 });
});
test('u volby "budu objednávat" sloučí záznam s objednávkovou skupinou včetně ceny po slevě', async () => {
await saveLunch('2025-03-06', { OBJEDNAVAM: { [USER]: { note: 'platím kartou' } } });
await saveExtra('2025-03-06', [{