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

        const rawResponseBody = {
            type: "job",
            id: "2",
            url: "https://api.intercom.io/jobs/status/20",
            status: "success",
            resource_type: "ticket",
            resource_id: "20",
            resource_url: "https://api.intercom.io/tickets/20",
        };
        server.mockEndpoint().get("/jobs/status/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.jobs.status({
            id: "id",
        });
        expect(response).toEqual({
            type: "job",
            id: "2",
            url: "https://api.intercom.io/jobs/status/20",
            status: "success",
            resource_type: "ticket",
            resource_id: "20",
            resource_url: "https://api.intercom.io/tickets/20",
        });
    });

    test("status (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("/jobs/status/id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.jobs.status({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("status (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("/jobs/status/id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.jobs.status({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });
});
