var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import React from "react";
import { describe, beforeEach, it, expect, vi } from "vitest";
import { renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useCommute } from "./index";
const queryClient = new QueryClient();
const wrapper = ({ children }) => (React.createElement(QueryClientProvider, { client: queryClient }, children));
// Mock the state manager context
vi.mock("~/context/stateManager", () => ({
    useStateManagerContext: () => ({
        sdkState: {
            apiKey: "test-api-key",
            globalOptions: {},
            options: {},
            location: { lat: 40.7128, lng: -74.006 },
        },
        setSdkState: vi.fn(),
        onChange: vi.fn(),
        followerNode: undefined,
    }),
}));
const fetchMock = vi.fn(() => Promise.resolve({
    status: 200,
    json: () => Promise.resolve({ data: { routes: [] } }),
}));
global.fetch = fetchMock;
describe("useCommute", () => {
    beforeEach(() => {
        vi.resetAllMocks();
    });
    it("should return the correct initial state", () => {
        const { result } = renderHook(() => useCommute({}), { wrapper });
        expect(result.current.isLoading).toBe(false);
        expect(result.current.isFetching).toBe(false);
        expect(result.current.data).toBeUndefined();
    });
    it("should use the api proxy endpoint for Maptiler", () => __awaiter(void 0, void 0, void 0, function* () {
        fetchMock.mockReturnValueOnce(Promise.resolve({
            status: 200,
            json: () => Promise.resolve({
                data: {
                    code: "Ok",
                    routes: [
                        {
                            duration: 900,
                            distance: 200,
                            geometry: {
                                coordinates: [],
                            },
                        },
                    ],
                },
            }),
        }));
        const { result } = renderHook(() => useCommute({
            label: "Test Commute",
            origin: { lat: 40.7128, lng: -74.006 },
            destination: { lat: 34.0522, lng: -118.2437 },
        }), { wrapper });
        yield waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));
        expect(fetchMock).toHaveBeenCalledWith(`${import.meta.env.VITE_PROVIDERS_ENDPOINT}/v1/directions/walking/-74.006,40.7128;-118.2437,34.0522?geometries=geojson`, expect.objectContaining({
            method: "GET",
            headers: expect.objectContaining({
                Accept: "application/json",
                Authorization: expect.any(String),
            }),
        }));
        yield waitFor(() => {
            expect(result.current.data).toEqual({
                mode: "walking",
                duration: 900,
                distance: 200,
                destination: { lat: 34.0522, lng: -118.2437 },
                label: "Test Commute",
                geometry: [],
            });
        });
    }));
});
//# sourceMappingURL=index.test.js.map