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

        const rawResponseBody = [
            {
                type: "away_status_reason",
                id: "id",
                label: "On a break",
                emoji: "☕",
                order: 1,
                deleted: false,
                created_at: 1734537243,
                updated_at: 1734537243,
            },
        ];
        server
            .mockEndpoint()
            .get("/away_status_reasons")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.awayStatusReasons.listAwayStatusReasons();
        expect(response).toEqual([
            {
                type: "away_status_reason",
                id: "id",
                label: "On a break",
                emoji: "\u2615",
                order: 1,
                deleted: false,
                created_at: 1734537243,
                updated_at: 1734537243,
            },
        ]);
    });

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

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

        await expect(async () => {
            return await client.awayStatusReasons.listAwayStatusReasons();
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });
});
