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

import * as Intercom from "../../../src/api/index";
import { IntercomClient } from "../../../src/Client";
import { mockServerPool } from "../../mock-server/MockServerPool";

describe("DataEventsClient", () => {
    test("lisDataEvents (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "event.summary",
            email: "email",
            intercom_user_id: "intercom_user_id",
            user_id: "user_id",
            events: [
                { name: "name", first: "first", last: "last", count: 1, description: "description" },
                { name: "name", first: "first", last: "last", count: 1, description: "description" },
            ],
        };
        server.mockEndpoint().get("/events").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.dataEvents.lisDataEvents({
            filter: {
                user_id: "user_id",
            },
            type: "type",
        });
        expect(response).toEqual({
            type: "event.summary",
            email: "email",
            intercom_user_id: "intercom_user_id",
            user_id: "user_id",
            events: [
                {
                    name: "name",
                    first: "first",
                    last: "last",
                    count: 1,
                    description: "description",
                },
                {
                    name: "name",
                    first: "first",
                    last: "last",
                    count: 1,
                    description: "description",
                },
            ],
        });
    });

    test("lisDataEvents (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server.mockEndpoint().get("/events").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.dataEvents.lisDataEvents({
                filter: {
                    user_id: "user_id",
                },
                type: "type",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("createDataEvent (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { key: "value" };

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

        const response = await client.unstable.dataEvents.createDataEvent({
            key: "value",
        });
        expect(response).toEqual(undefined);
    });

    test("createDataEvent (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { key: "value" };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/events")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.dataEvents.createDataEvent({
                key: "value",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("dataEventSummaries (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};

        server.mockEndpoint().post("/events/summaries").jsonBody(rawRequestBody).respondWith().statusCode(200).build();

        const response = await client.unstable.dataEvents.dataEventSummaries();
        expect(response).toEqual(undefined);
    });

    test("dataEventSummaries (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/events/summaries")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.dataEvents.dataEventSummaries();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });
});
