63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { render, screen, waitFor } from '@testing-library/react';
|
|
import { ping, fetchZones } from './Api';
|
|
import axios from 'axios';
|
|
|
|
jest.mock('axios');
|
|
|
|
describe('API Functions', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
|
|
axios.interceptors.request.use = jest.fn();
|
|
axios.interceptors.response.use = jest.fn();
|
|
});
|
|
|
|
test('ping function', async () => {
|
|
(axios.get as jest.Mock).mockResolvedValue({ data: 'Pong' });
|
|
|
|
// const response = await ping();
|
|
|
|
// expect(response).toEqual('Pong');
|
|
// expect(axios.get).toHaveBeenCalledWith('health');
|
|
});
|
|
|
|
// test('fetchZones function', async () => {
|
|
// const mockFlightData = [
|
|
// {
|
|
// id: 1,
|
|
// flight_code: "ABC123",
|
|
// origin: "City A",
|
|
// destination: "City X",
|
|
// departure_time: "2023-10-30 10:00 AM",
|
|
// arrival_time: "2023-10-30 12:00 PM",
|
|
// gate: "A1",
|
|
// status: "On Time"
|
|
// },
|
|
// {
|
|
// id: 2,
|
|
// flight_code: "XYZ789",
|
|
// origin: "City B",
|
|
// destination: "City Y",
|
|
// departure_time: "2023-10-31 01:30 PM",
|
|
// arrival_time: "2023-10-31 02:30 PM",
|
|
// gate: "B2",
|
|
// status: "Delayed"
|
|
// },
|
|
// ];
|
|
|
|
|
|
// (axios.get as jest.Mock).mockResolvedValue({ data: mockFlightData });
|
|
|
|
// const origin = 'TestOrigin';
|
|
// const destination = 'TestDestination';
|
|
// const lastUpdate = '2023-01-01T00:00:00Z';
|
|
|
|
// const response = await fetchZones(origin, destination, lastUpdate);
|
|
|
|
// expect(response).toEqual(mockFlightData);
|
|
// expect(axios.get).toHaveBeenCalledWith(
|
|
// `flights?origin=${origin}&destination=${destination}&lastUpdated=${lastUpdate}&future=true`
|
|
// );
|
|
// });
|
|
});
|