test: rozšíření serverových testů
ci/woodpecker/push/workflow Pipeline failed

This commit is contained in:
mates committed 2026-04-29 15:42:08 +02:00
1 parent 1e1e23df80
commit 64d85036fd
29 files changed
+1250 -10

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
import * as fs from 'fs';
import * as path from 'path';
import axios from 'axios';
import { downloadSalaty } from '../chefie';
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
const fixturesDir = path.join(__dirname, 'fixtures');
const loadFixture = (name: string) => fs.readFileSync(path.join(fixturesDir, name), 'utf-8');
beforeEach(() => {
jest.resetAllMocks();
// První volání = stránka se seznamem salátů, následující volání = jednotlivé stránky salátů
mockedAxios.get = jest.fn()
.mockResolvedValueOnce({ data: loadFixture('chefie-salaty.html') })
.mockResolvedValueOnce({ data: loadFixture('chefie-salat-caesar.html') })
.mockResolvedValueOnce({ data: loadFixture('chefie-salat-recky.html') });
});
test('downloadSalaty vrátí seznam salátů', async () => {
const salaty = await downloadSalaty(false);
expect(salaty).toHaveLength(2);
});
test('saláty mají name a ingredients', async () => {
const salaty = await downloadSalaty(false);
expect(salaty[0].name).toBe('Caesar salát');
expect(salaty[0].ingredients).toContain('Kuřecí maso');
});
test('cena salátu zahrnuje pevný příplatek 13 Kč za obal', async () => {
const salaty = await downloadSalaty(false);
// Caesar sticker price = 129, box = 13
expect(salaty[0].price).toBe(129 + 13);
// Řecký sticker price = 119, box = 13
expect(salaty[1].price).toBe(119 + 13);
});