// 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("TicketsClient", () => {
    test("replyTicket (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            message_type: "comment",
            type: "user",
            body: "Thanks again :)",
            intercom_user_id: "6762f2971bb69f9f2193bc49",
        };
        const rawResponseBody = {
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: { type: "admin", id: "991267943", name: "Ciaran419 Lee", email: "admin419@email.com" },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        };
        server
            .mockEndpoint()
            .post("/tickets/123/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.replyTicket({
            id: "123",
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f2971bb69f9f2193bc49",
            },
        });
        expect(response).toEqual({
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: {
                type: "admin",
                id: "991267943",
                name: "Ciaran419 Lee",
                email: "admin419@email.com",
            },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        });
    });

    test("replyTicket (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            message_type: "note",
            type: "admin",
            body: "<html> <body>  <h2>An Unordered HTML List</h2>  <ul>   <li>Coffee</li>   <li>Tea</li>   <li>Milk</li> </ul>    <h2>An Ordered HTML List</h2>  <ol>   <li>Coffee</li>   <li>Tea</li>   <li>Milk</li> </ol>   </body> </html>",
            admin_id: "3156780",
        };
        const rawResponseBody = {
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: { type: "admin", id: "991267943", name: "Ciaran419 Lee", email: "admin419@email.com" },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        };
        server
            .mockEndpoint()
            .post("/tickets/123/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.replyTicket({
            id: "123",
            body: {
                message_type: "note",
                type: "admin",
                body: "<html> <body>  <h2>An Unordered HTML List</h2>  <ul>   <li>Coffee</li>   <li>Tea</li>   <li>Milk</li> </ul>    <h2>An Ordered HTML List</h2>  <ol>   <li>Coffee</li>   <li>Tea</li>   <li>Milk</li> </ol>   </body> </html>",
                admin_id: "3156780",
            },
        });
        expect(response).toEqual({
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: {
                type: "admin",
                id: "991267943",
                name: "Ciaran419 Lee",
                email: "admin419@email.com",
            },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        });
    });

    test("replyTicket (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            message_type: "quick_reply",
            type: "admin",
            admin_id: "3156780",
            reply_options: [
                { text: "Yes", uuid: "0df48b85-9a93-4c66-a167-753eff0baaec" },
                { text: "No", uuid: "4f0b5145-4193-4b4f-8cad-ce19478a3938" },
            ],
        };
        const rawResponseBody = {
            type: "ticket_part",
            id: "158",
            part_type: "quick_reply",
            body: "<p>Okay!</p>",
            created_at: 1734537890,
            updated_at: 1734537890,
            author: { type: "admin", id: "991267948", name: "Ciaran423 Lee", email: "admin423@email.com" },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        };
        server
            .mockEndpoint()
            .post("/tickets/123/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.replyTicket({
            id: "123",
            body: {
                message_type: "quick_reply",
                type: "admin",
                admin_id: "3156780",
                reply_options: [
                    {
                        text: "Yes",
                        uuid: "0df48b85-9a93-4c66-a167-753eff0baaec",
                    },
                    {
                        text: "No",
                        uuid: "4f0b5145-4193-4b4f-8cad-ce19478a3938",
                    },
                ],
            },
        });
        expect(response).toEqual({
            type: "ticket_part",
            id: "158",
            part_type: "quick_reply",
            body: "<p>Okay!</p>",
            created_at: 1734537890,
            updated_at: 1734537890,
            author: {
                type: "admin",
                id: "991267948",
                name: "Ciaran423 Lee",
                email: "admin423@email.com",
            },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        });
    });

    test("replyTicket (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            message_type: "comment",
            type: "user",
            body: "Thanks again :)",
            intercom_user_id: "6762f2a41bb69f9f2193bc4c",
        };
        const rawResponseBody = {
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: { type: "admin", id: "991267943", name: "Ciaran419 Lee", email: "admin419@email.com" },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        };
        server
            .mockEndpoint()
            .post("/tickets/123/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.replyTicket({
            id: "123",
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f2a41bb69f9f2193bc4c",
            },
        });
        expect(response).toEqual({
            type: "ticket_part",
            id: "156",
            part_type: "note",
            body: "<h2>An Unordered HTML List</h2>\n<ul>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ul>\n<h2>An Ordered HTML List</h2>\n<ol>\n<li>Coffee</li>\n<li>Tea</li>\n<li>Milk</li>\n</ol>",
            created_at: 1734537884,
            updated_at: 1734537884,
            author: {
                type: "admin",
                id: "991267943",
                name: "Ciaran419 Lee",
                email: "admin419@email.com",
            },
            attachments: [
                {
                    type: "upload",
                    name: "example.png",
                    url: "https://picsum.photos/200/300",
                    content_type: "image/png",
                    filesize: 100,
                    width: 100,
                    height: 100,
                },
            ],
            redacted: false,
        });
    });

    test("replyTicket (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            intercom_user_id: "intercom_user_id",
            message_type: "comment",
            type: "user",
            body: "body",
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/tickets/id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.replyTicket({
                id: "id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("replyTicket (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            intercom_user_id: "intercom_user_id",
            message_type: "comment",
            type: "user",
            body: "body",
        };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/tickets/id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.replyTicket({
                id: "id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("replyTicket (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            intercom_user_id: "intercom_user_id",
            message_type: "comment",
            type: "user",
            body: "body",
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/tickets/id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.replyTicket({
                id: "id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("enqueueCreateTicket (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { ticket_type_id: "1234", contacts: [{ id: "6762f2d81bb69f9f2193bc54" }] };
        const rawResponseBody = {
            type: "job",
            id: "20",
            url: "https://api.intercom.io/jobs/status/20",
            status: "pending",
            resource_type: "ticket",
            resource_id: "resource_id",
            resource_url: "http://api.intercom.io/tickets/123",
        };
        server
            .mockEndpoint()
            .post("/tickets/enqueue")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.enqueueCreateTicket({
            ticket_type_id: "1234",
            contacts: [
                {
                    id: "6762f2d81bb69f9f2193bc54",
                },
            ],
        });
        expect(response).toEqual({
            type: "job",
            id: "20",
            url: "https://api.intercom.io/jobs/status/20",
            status: "pending",
            resource_type: "ticket",
            resource_id: "resource_id",
            resource_url: "http://api.intercom.io/tickets/123",
        });
    });

    test("enqueueCreateTicket (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { ticket_type_id: "ticket_type_id", contacts: [{ id: "id" }, { id: "id" }] };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/tickets/enqueue")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.enqueueCreateTicket({
                ticket_type_id: "ticket_type_id",
                contacts: [
                    {
                        id: "id",
                    },
                    {
                        id: "id",
                    },
                ],
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("enqueueCreateTicket (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { ticket_type_id: "ticket_type_id", contacts: [{ id: "id" }, { id: "id" }] };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/tickets/enqueue")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.enqueueCreateTicket({
                ticket_type_id: "ticket_type_id",
                contacts: [
                    {
                        id: "id",
                    },
                    {
                        id: "id",
                    },
                ],
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "ticket",
            id: "631",
            ticket_id: "38",
            category: "Back-office",
            ticket_attributes: { _default_title_: "attribute_value", _default_description_: "ticket_attributes" },
            ticket_state: {
                type: "ticket_state",
                id: "8537",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "95",
                category: "Back-office",
                name: "my-ticket-type-30",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id702_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537973,
                updated_at: 1734537973,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2f61bb69f9f2193bc59",
                        external_id: "b16afa36-2637-4880-adee-a46d145bc27f",
                    },
                ],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537974,
            updated_at: 1734537976,
            open: true,
            snoozed_until: 1663597260,
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "185",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537975,
                        updated_at: 1734537975,
                        author: { type: "admin", id: "991268047", name: "Ciaran509 Lee", email: "admin509@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            is_shared: false,
        };
        server.mockEndpoint().get("/tickets/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.tickets.getTicket({
            id: "id",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "631",
            ticket_id: "38",
            category: "Back-office",
            ticket_attributes: {
                _default_title_: "attribute_value",
                _default_description_: "ticket_attributes",
            },
            ticket_state: {
                type: "ticket_state",
                id: "8537",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "95",
                category: "Back-office",
                name: "my-ticket-type-30",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id702_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537973,
                updated_at: 1734537973,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2f61bb69f9f2193bc59",
                        external_id: "b16afa36-2637-4880-adee-a46d145bc27f",
                    },
                ],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537974,
            updated_at: 1734537976,
            open: true,
            snoozed_until: 1663597260,
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "185",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537975,
                        updated_at: 1734537975,
                        author: {
                            type: "admin",
                            id: "991268047",
                            name: "Ciaran509 Lee",
                            email: "admin509@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            is_shared: false,
        });
    });

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

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

    test("updateTicket (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state_id: "123",
            open: true,
            snoozed_until: 1673609604,
            admin_id: 991268011,
            assignee_id: "123",
        };
        const rawResponseBody = {
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "10", label: "Photo" },
                            value: { type: "value", id: [2], label: ["photo.png"] },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "7", label: "Progress" },
                            value: { type: "value", id: "Fast", label: "Fast" },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: { type: "admin", id: "991268013" },
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.updateTicket({
            id: "id",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state_id: "123",
            open: true,
            snoozed_until: 1673609604,
            admin_id: 991268011,
            assignee_id: "123",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "10",
                                label: "Photo",
                            },
                            value: {
                                type: "value",
                                id: [2],
                                label: ["photo.png"],
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "7",
                                label: "Progress",
                            },
                            value: {
                                type: "value",
                                id: "Fast",
                                label: "Fast",
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: {
                            type: "admin",
                            id: "991268013",
                        },
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        });
    });

    test("updateTicket (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state_id: "123",
            admin_id: 991268011,
            assignee_id: "123",
        };
        const rawResponseBody = {
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "10", label: "Photo" },
                            value: { type: "value", id: [2], label: ["photo.png"] },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "7", label: "Progress" },
                            value: { type: "value", id: "Fast", label: "Fast" },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: { type: "admin", id: "991268013" },
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.updateTicket({
            id: "id",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state_id: "123",
            admin_id: 991268011,
            assignee_id: "123",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "10",
                                label: "Photo",
                            },
                            value: {
                                type: "value",
                                id: [2],
                                label: ["photo.png"],
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "7",
                                label: "Progress",
                            },
                            value: {
                                type: "value",
                                id: "Fast",
                                label: "Fast",
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: {
                            type: "admin",
                            id: "991268013",
                        },
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        });
    });

    test("updateTicket (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state_id: "123",
            admin_id: 991268011,
            assignee_id: "123",
        };
        const rawResponseBody = {
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "10", label: "Photo" },
                            value: { type: "value", id: [2], label: ["photo.png"] },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "7", label: "Progress" },
                            value: { type: "value", id: "Fast", label: "Fast" },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: { type: "admin", id: "991268013" },
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.updateTicket({
            id: "id",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state_id: "123",
            admin_id: 991268011,
            assignee_id: "123",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "10",
                                label: "Photo",
                            },
                            value: {
                                type: "value",
                                id: [2],
                                label: ["photo.png"],
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "7",
                                label: "Progress",
                            },
                            value: {
                                type: "value",
                                id: "Fast",
                                label: "Fast",
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: {
                            type: "admin",
                            id: "991268013",
                        },
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        });
    });

    test("updateTicket (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { ticket_state_id: "123" };
        const rawResponseBody = {
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: { _default_title_: "example", _default_description_: "there is a problem" },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "10", label: "Photo" },
                            value: { type: "value", id: [2], label: ["photo.png"] },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: { type: "attribute", id: "7", label: "Progress" },
                            value: { type: "value", id: "Fast", label: "Fast" },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: { type: "admin", id: "991268013" },
                        author: { type: "admin", id: "991268011", name: "Ciaran477 Lee", email: "admin477@email.com" },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.updateTicket({
            id: "id",
            ticket_state_id: "123",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "627",
            ticket_id: "34",
            category: "Back-office",
            ticket_attributes: {
                _default_title_: "example",
                _default_description_: "there is a problem",
            },
            ticket_state: {
                type: "ticket_state",
                id: "8498",
                category: "in_progress",
                internal_label: "In progress",
                external_label: "In progress",
            },
            ticket_type: {
                type: "ticket_type",
                id: "90",
                category: "Back-office",
                name: "my-ticket-type-25",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id692_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537948,
                updated_at: 1734537948,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2dd1bb69f9f2193bc55",
                        external_id: "8df1fa21-b41d-4621-9229-d6f7a3a590ce",
                    },
                ],
            },
            admin_assignee_id: "991268013",
            team_assignee_id: "0",
            created_at: 1734537950,
            updated_at: 1734537955,
            open: true,
            snoozed_until: 1734627600,
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ticket_parts: {
                type: "ticket_part.list",
                ticket_parts: [
                    {
                        type: "ticket_part",
                        id: "176",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537951,
                        updated_at: 1734537951,
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "177",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "10",
                                label: "Photo",
                            },
                            value: {
                                type: "value",
                                id: [2],
                                label: ["photo.png"],
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "178",
                        part_type: "ticket_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537953,
                        updated_at: 1734537953,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                        updated_attribute_data: {
                            attribute: {
                                type: "attribute",
                                id: "7",
                                label: "Progress",
                            },
                            value: {
                                type: "value",
                                id: "Fast",
                                label: "Fast",
                            },
                        },
                    },
                    {
                        type: "ticket_part",
                        id: "179",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "in_progress",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "180",
                        part_type: "assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1734537954,
                        updated_at: 1734537954,
                        assigned_to: {
                            type: "admin",
                            id: "991268013",
                        },
                        author: {
                            type: "admin",
                            id: "991268011",
                            name: "Ciaran477 Lee",
                            email: "admin477@email.com",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                    {
                        type: "ticket_part",
                        id: "181",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537955,
                        updated_at: 1734537955,
                        author: {
                            type: "bot",
                            id: "991268012",
                            name: "Fin",
                            email: "operator+this_is_an_id692_that_should_be_at_least_@intercom.io",
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "text-integration",
                    },
                ],
                total_count: 6,
            },
            is_shared: false,
        });
    });

    test("updateTicket (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.tickets.updateTicket({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("updateTicket (6)", 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()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("updateTicket (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/tickets/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const rawResponseBody = { id: "632", object: "ticket", deleted: true };
        server.mockEndpoint().delete("/tickets/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.tickets.deleteTicket({
            id: "id",
        });
        expect(response).toEqual({
            id: "632",
            object: "ticket",
            deleted: true,
        });
    });

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

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

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

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

    test("searchTickets", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            query: { operator: "AND", value: [{ field: "created_at", operator: ">", value: "1306054154" }] },
            pagination: { per_page: 5 },
        };
        const rawResponseBody = {
            type: "ticket.list",
            tickets: [
                {
                    type: "ticket",
                    id: "633",
                    ticket_id: "40",
                    category: "Back-office",
                    ticket_attributes: { _default_title_: "attribute_value", _default_description_: undefined },
                    ticket_state: {
                        type: "ticket_state",
                        id: "8577",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    ticket_type: {
                        type: "ticket_type",
                        id: "100",
                        category: "Back-office",
                        name: "my-ticket-type-35",
                        description: "my ticket type description is awesome.",
                        icon: "🦁",
                        workspace_id: "this_is_an_id712_that_should_be_at_least_",
                        ticket_type_attributes: { type: "list" },
                        archived: false,
                        created_at: 1734537989,
                        updated_at: 1734537989,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [
                            {
                                type: "contact",
                                id: "6762f3061bb69f9f2193bc5b",
                                external_id: "9b913927-c084-4391-b1db-098341b5ffe3",
                            },
                        ],
                    },
                    admin_assignee_id: "0",
                    team_assignee_id: "0",
                    created_at: 1734537990,
                    updated_at: 1734537992,
                    open: true,
                    snoozed_until: 1663597260,
                    linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
                    ticket_parts: {
                        type: "ticket_part.list",
                        ticket_parts: [
                            {
                                type: "ticket_part",
                                id: "188",
                                part_type: "ticket_state_updated_by_admin",
                                body: "<p>Okay!</p>",
                                previous_ticket_state: "submitted",
                                ticket_state: "submitted",
                                created_at: 1734537991,
                                updated_at: 1734537991,
                                author: {
                                    type: "admin",
                                    id: "991268079",
                                    name: "Ciaran539 Lee",
                                    email: "admin539@email.com",
                                },
                                attachments: [
                                    {
                                        type: "upload",
                                        name: "example.png",
                                        url: "https://picsum.photos/200/300",
                                        content_type: "image/png",
                                        filesize: 100,
                                        width: 100,
                                        height: 100,
                                    },
                                ],
                                external_id: "abcd1234",
                                redacted: false,
                                app_package_code: "text-integration",
                            },
                        ],
                        total_count: 1,
                    },
                    is_shared: false,
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 5,
                total_pages: 1,
            },
        };
        server
            .mockEndpoint()
            .post("/tickets/search")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.tickets.searchTickets({
            query: {
                operator: "AND",
                value: [
                    {
                        field: "created_at",
                        operator: ">",
                        value: "1306054154",
                    },
                ],
            },
            pagination: {
                per_page: 5,
            },
        });
        expect(response).toEqual({
            type: "ticket.list",
            tickets: [
                {
                    type: "ticket",
                    id: "633",
                    ticket_id: "40",
                    category: "Back-office",
                    ticket_attributes: {
                        _default_title_: "attribute_value",
                    },
                    ticket_state: {
                        type: "ticket_state",
                        id: "8577",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    ticket_type: {
                        type: "ticket_type",
                        id: "100",
                        category: "Back-office",
                        name: "my-ticket-type-35",
                        description: "my ticket type description is awesome.",
                        icon: "\uD83E\uDD81",
                        workspace_id: "this_is_an_id712_that_should_be_at_least_",
                        ticket_type_attributes: {
                            type: "list",
                        },
                        archived: false,
                        created_at: 1734537989,
                        updated_at: 1734537989,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [
                            {
                                type: "contact",
                                id: "6762f3061bb69f9f2193bc5b",
                                external_id: "9b913927-c084-4391-b1db-098341b5ffe3",
                            },
                        ],
                    },
                    admin_assignee_id: "0",
                    team_assignee_id: "0",
                    created_at: 1734537990,
                    updated_at: 1734537992,
                    open: true,
                    snoozed_until: 1663597260,
                    linked_objects: {
                        type: "list",
                        total_count: 0,
                        has_more: false,
                        data: [
                            {
                                id: "7583",
                            },
                        ],
                    },
                    ticket_parts: {
                        type: "ticket_part.list",
                        ticket_parts: [
                            {
                                type: "ticket_part",
                                id: "188",
                                part_type: "ticket_state_updated_by_admin",
                                body: "<p>Okay!</p>",
                                previous_ticket_state: "submitted",
                                ticket_state: "submitted",
                                created_at: 1734537991,
                                updated_at: 1734537991,
                                author: {
                                    type: "admin",
                                    id: "991268079",
                                    name: "Ciaran539 Lee",
                                    email: "admin539@email.com",
                                },
                                attachments: [
                                    {
                                        type: "upload",
                                        name: "example.png",
                                        url: "https://picsum.photos/200/300",
                                        content_type: "image/png",
                                        filesize: 100,
                                        width: 100,
                                        height: 100,
                                    },
                                ],
                                external_id: "abcd1234",
                                redacted: false,
                                app_package_code: "text-integration",
                            },
                        ],
                        total_count: 1,
                    },
                    is_shared: false,
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 5,
                total_pages: 1,
            },
        });
    });
});
