// 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("DataExportClient", () => {
    test("exportReportingData (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            job_identifier: "job1",
            status: "complete",
            download_url: "",
            download_expires_at: "",
        };
        server
            .mockEndpoint()
            .get("/export/reporting_data/job_identifier")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataExport.exportReportingData({
            job_identifier: "job_identifier",
            app_id: "app_id",
            client_id: "client_id",
        });
        expect(response).toEqual({
            job_identifier: "job1",
            status: "complete",
            download_url: "",
            download_expires_at: "",
        });
    });

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

        const rawResponseBody = { job_identifier: "job1", status: "failed", download_url: "", download_expires_at: "" };
        server
            .mockEndpoint()
            .get("/export/reporting_data/job_identifier")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataExport.exportReportingData({
            job_identifier: "job_identifier",
            app_id: "app_id",
            client_id: "client_id",
        });
        expect(response).toEqual({
            job_identifier: "job1",
            status: "failed",
            download_url: "",
            download_expires_at: "",
        });
    });

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/export/reporting_data/job_identifier")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.dataExport.exportReportingData({
                job_identifier: "job_identifier",
                app_id: "app_id",
                client_id: "client_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        server
            .mockEndpoint()
            .get("/download/reporting_data/job_identifier")
            .header("Accept", "application/octet-stream")
            .respondWith()
            .statusCode(200)
            .build();

        const response = await client.dataExport.downloadReportingDataExport({
            job_identifier: "job_identifier",
            app_id: "app_id",
        });
        expect(response).toEqual(undefined);
    });

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/download/reporting_data/job_identifier")
            .header("Accept", "application/octet-stream")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.dataExport.downloadReportingDataExport({
                job_identifier: "job_identifier",
                app_id: "app_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("create", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { created_at_after: 1734519776, created_at_before: 1734537776 };
        const rawResponseBody = {
            job_identifier: "al9w983lwu88w1fd",
            status: "pending",
            download_expires_at: "",
            download_url: "",
        };
        server
            .mockEndpoint()
            .post("/export/content/data")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataExport.create({
            created_at_after: 1734519776,
            created_at_before: 1734537776,
        });
        expect(response).toEqual({
            job_identifier: "al9w983lwu88w1fd",
            status: "pending",
            download_expires_at: "",
            download_url: "",
        });
    });

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

        const rawResponseBody = {
            job_identifier: "braxwk3j039t6txy",
            status: "pending",
            download_expires_at: "",
            download_url: "",
        };
        server
            .mockEndpoint()
            .get("/export/content/data/job_identifier")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataExport.find({
            job_identifier: "job_identifier",
        });
        expect(response).toEqual({
            job_identifier: "braxwk3j039t6txy",
            status: "pending",
            download_expires_at: "",
            download_url: "",
        });
    });

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

        const rawResponseBody = {
            job_identifier: "v134nyc2bku9hj91",
            status: "canceled",
            download_expires_at: "",
            download_url: "",
        };
        server
            .mockEndpoint()
            .post("/export/cancel/job_identifier")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataExport.cancel({
            job_identifier: "job_identifier",
        });
        expect(response).toEqual({
            job_identifier: "v134nyc2bku9hj91",
            status: "canceled",
            download_expires_at: "",
            download_url: "",
        });
    });

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

        server.mockEndpoint().get("/download/content/data/job_identifier").respondWith().statusCode(200).build();

        const response = await client.dataExport.download({
            job_identifier: "job_identifier",
        });
        expect(response).toEqual(undefined);
    });
});
