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
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
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');
|
|
});
|
|
});
|