// This file was auto-generated by Fern from our API Definition.

import { VapiClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("AnalyticsClient", () => {
    test("get", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = {
            queries: [{ table: "call", name: "name", operations: [{ operation: "sum", column: "id" }] }],
        };
        const rawResponseBody = [
            {
                name: "name",
                timeRange: {
                    step: "second",
                    start: "2024-01-15T09:30:00Z",
                    end: "2024-01-15T09:30:00Z",
                    timezone: "timezone",
                },
                result: [{ key: "value" }],
            },
        ];

        server
            .mockEndpoint()
            .post("/analytics")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.analytics.get({
            queries: [
                {
                    table: "call",
                    name: "name",
                    operations: [
                        {
                            operation: "sum",
                            column: "id",
                        },
                    ],
                },
            ],
        });
        expect(response).toEqual([
            {
                name: "name",
                timeRange: {
                    step: "second",
                    start: "2024-01-15T09:30:00Z",
                    end: "2024-01-15T09:30:00Z",
                    timezone: "timezone",
                },
                result: [
                    {
                        key: "value",
                    },
                ],
            },
        ]);
    });
});
