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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "ticket_type",
                    id: "67",
                    category: "Customer",
                    name: "Bug Report",
                    description: "Bug Report Template",
                    icon: "🎟️",
                    workspace_id: "this_is_an_id648_that_should_be_at_least_",
                    ticket_type_attributes: { type: "list" },
                    ticket_states: {
                        type: "list",
                        data: [
                            {
                                type: "ticket_state",
                                id: "8321",
                                category: "submitted",
                                internal_label: "Submitted",
                                external_label: "Submitted",
                            },
                            {
                                type: "ticket_state",
                                id: "8322",
                                category: "in_progress",
                                internal_label: "In progress",
                                external_label: "In progress",
                            },
                            {
                                type: "ticket_state",
                                id: "8323",
                                category: "waiting_on_customer",
                                internal_label: "Waiting on customer",
                                external_label: "Waiting on you",
                            },
                            {
                                type: "ticket_state",
                                id: "8324",
                                category: "resolved",
                                internal_label: "Resolved",
                                external_label: "Resolved",
                            },
                        ],
                    },
                    archived: false,
                    created_at: 1734537866,
                    updated_at: 1734537866,
                },
            ],
        };
        server.mockEndpoint().get("/ticket_types").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.ticketTypes.list();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "ticket_type",
                    id: "67",
                    category: "Customer",
                    name: "Bug Report",
                    description: "Bug Report Template",
                    icon: "\uD83C\uDF9F\uFE0F",
                    workspace_id: "this_is_an_id648_that_should_be_at_least_",
                    ticket_type_attributes: {
                        type: "list",
                    },
                    ticket_states: {
                        type: "list",
                        data: [
                            {
                                type: "ticket_state",
                                id: "8321",
                                category: "submitted",
                                internal_label: "Submitted",
                                external_label: "Submitted",
                            },
                            {
                                type: "ticket_state",
                                id: "8322",
                                category: "in_progress",
                                internal_label: "In progress",
                                external_label: "In progress",
                            },
                            {
                                type: "ticket_state",
                                id: "8323",
                                category: "waiting_on_customer",
                                internal_label: "Waiting on customer",
                                external_label: "Waiting on you",
                            },
                            {
                                type: "ticket_state",
                                id: "8324",
                                category: "resolved",
                                internal_label: "Resolved",
                                external_label: "Resolved",
                            },
                        ],
                    },
                    archived: false,
                    created_at: 1734537866,
                    updated_at: 1734537866,
                },
            ],
        });
    });

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

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

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            name: "Customer Issue",
            description: "Customer Report Template",
            category: "Customer",
            icon: "🎟️",
        };
        const rawResponseBody = {
            type: "ticket_type",
            id: "70",
            category: "Customer",
            name: "Customer Issue",
            description: "Customer Report Template",
            icon: "🎟️",
            workspace_id: "this_is_an_id652_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: { key: "value" },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8337",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8338",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8339",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8340",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537869,
            updated_at: 1734537869,
        };
        server
            .mockEndpoint()
            .post("/ticket_types")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.ticketTypes.create({
            name: "Customer Issue",
            description: "Customer Report Template",
            category: "Customer",
            icon: "\uD83C\uDF9F\uFE0F",
        });
        expect(response).toEqual({
            type: "ticket_type",
            id: "70",
            category: "Customer",
            name: "Customer Issue",
            description: "Customer Report Template",
            icon: "\uD83C\uDF9F\uFE0F",
            workspace_id: "this_is_an_id652_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: {
                            key: "value",
                        },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8337",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8338",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8339",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8340",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537869,
            updated_at: 1734537869,
        });
    });

    test("create (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().post("/ticket_types").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.ticketTypes.create(undefined);
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "ticket_type",
            id: "72",
            category: "Customer",
            name: "Bug Report",
            description: "Bug Report Template",
            icon: "🎟️",
            workspace_id: "this_is_an_id656_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: { key: "value" },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8353",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8354",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8355",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8356",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537870,
            updated_at: 1734537870,
        };
        server
            .mockEndpoint()
            .get("/ticket_types/ticket_type_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.ticketTypes.get({
            ticket_type_id: "ticket_type_id",
        });
        expect(response).toEqual({
            type: "ticket_type",
            id: "72",
            category: "Customer",
            name: "Bug Report",
            description: "Bug Report Template",
            icon: "\uD83C\uDF9F\uFE0F",
            workspace_id: "this_is_an_id656_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: {
                            key: "value",
                        },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8353",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8354",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8355",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8356",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537870,
            updated_at: 1734537870,
        });
    });

    test("get (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("/ticket_types/ticket_type_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.ticketTypes.get({
                ticket_type_id: "ticket_type_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "Bug Report 2" };
        const rawResponseBody = {
            type: "ticket_type",
            id: "74",
            category: "Customer",
            name: "Bug Report 2",
            description: "Bug Report Template",
            icon: "🎟️",
            workspace_id: "this_is_an_id660_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: { key: "value" },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8369",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8370",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8371",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8372",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537873,
            updated_at: 1734537874,
        };
        server
            .mockEndpoint()
            .put("/ticket_types/ticket_type_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.ticketTypes.update({
            ticket_type_id: "ticket_type_id",
            name: "Bug Report 2",
        });
        expect(response).toEqual({
            type: "ticket_type",
            id: "74",
            category: "Customer",
            name: "Bug Report 2",
            description: "Bug Report Template",
            icon: "\uD83C\uDF9F\uFE0F",
            workspace_id: "this_is_an_id660_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        input_options: {
                            key: "value",
                        },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8369",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8370",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8371",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8372",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537873,
            updated_at: 1734537874,
        });
    });

    test("update (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: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/ticket_types/ticket_type_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.ticketTypes.update({
                ticket_type_id: "ticket_type_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });
});
