Files
Nikita Kiselev 3cc82e45f0
Some checks are pending
Telegram Mini App Shop Builder / Compute version metadata (push) Waiting to run
Telegram Mini App Shop Builder / Run Frontend tests (push) Waiting to run
Telegram Mini App Shop Builder / Run Backend tests (push) Waiting to run
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Waiting to run
Telegram Mini App Shop Builder / Build module. (push) Blocked by required conditions
Telegram Mini App Shop Builder / release (push) Blocked by required conditions
Squashed commit message
2026-03-11 23:02:54 +03:00

80 lines
2.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { apiFetch, getCart, addToCart, setCoupon, setVoucher } from '@/utils/ftch.js';
import { ofetch } from 'ofetch';
// Мокаем ofetch
vi.mock('ofetch', () => ({
ofetch: {
create: vi.fn(() => vi.fn()),
},
}));
describe('ftch.js', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('apiFetch', () => {
it('должен создавать экземпляр ofetch с правильной конфигурацией', () => {
const fetchInstance = apiFetch;
expect(fetchInstance).toBeDefined();
});
it('должен быть определен', () => {
// Проверяем, что apiFetch экспортирован и определен
expect(apiFetch).toBeDefined();
expect(typeof apiFetch).toBe('function');
});
});
describe('getCart', () => {
it('должен вызывать API с правильным action', async () => {
const mockResponse = { data: { products: [] } };
const mockFetch = vi.fn().mockResolvedValue(mockResponse);
// Мокаем apiFetch
vi.doMock('@/utils/ftch.js', async () => {
const actual = await vi.importActual('@/utils/ftch.js');
return {
...actual,
apiFetch: mockFetch,
};
});
// В реальном тесте нужно будет мокать apiFetch по-другому
// или использовать MSW (Mock Service Worker)
expect(true).toBe(true); // Placeholder
});
});
describe('addToCart', () => {
it('должен отправлять POST запрос с FormData', async () => {
const formData = new FormData();
formData.append('product_id', '1');
formData.append('quantity', '2');
// В реальном тесте нужно мокать apiFetch
expect(true).toBe(true); // Placeholder
});
});
describe('setCoupon', () => {
it('должен отправлять купон в правильном формате', async () => {
const coupon = 'DISCOUNT10';
// В реальном тесте нужно мокать apiFetch
expect(true).toBe(true); // Placeholder
});
});
describe('setVoucher', () => {
it('должен отправлять ваучер в правильном формате', async () => {
const voucher = 'VOUCHER123';
// В реальном тесте нужно мокать apiFetch
expect(true).toBe(true); // Placeholder
});
});
});