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

        const rawResponseBody = {
            type: "conversation.list",
            conversations: [
                {
                    type: "conversation",
                    id: "471",
                    title: "Conversation Title",
                    created_at: 1734537460,
                    updated_at: 1734537460,
                    waiting_since: 1663597260,
                    snoozed_until: 1663597260,
                    open: false,
                    state: "closed",
                    read: false,
                    priority: "not_priority",
                    admin_assignee_id: 0,
                    team_assignee_id: "5017691",
                    company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
                    tags: {
                        type: "tag.list",
                        tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }],
                    },
                    conversation_rating: { rating: 5, remark: "", created_at: 1671028894, updated_at: 1671028894 },
                    source: {
                        type: "conversation",
                        id: "403918320",
                        delivered_as: "admin_initiated",
                        subject: "",
                        body: "<p>this is the message body</p>",
                        author: {
                            type: "admin",
                            id: "991267628",
                            name: "Ciaran166 Lee",
                            email: "admin166@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        redacted: false,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [{ type: "contact", id: "6762f0f31bb69f9f2193bb8b", external_id: "70" }],
                    },
                    teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
                    custom_attributes: { key: "value" },
                    first_contact_reply: {
                        created_at: 1663597223,
                        type: "conversation",
                        url: "https://developers.intercom.com/",
                    },
                    sla_applied: { type: "conversation_sla_summary", sla_name: "" },
                    statistics: {
                        type: "conversation_statistics",
                        time_to_assignment: 2310,
                        time_to_admin_reply: 2310,
                        time_to_first_close: 2310,
                        time_to_last_close: 2310,
                        median_time_to_reply: 2310,
                        first_contact_reply_at: 1663597233,
                        first_assignment_at: 1663597233,
                        first_admin_reply_at: 1663597233,
                        first_close_at: 1663597233,
                        last_assignment_at: 1663597233,
                        last_assignment_admin_reply_at: 1663597233,
                        last_contact_reply_at: 1663597233,
                        last_admin_reply_at: 1663597233,
                        last_close_at: 1663597233,
                        last_closed_by_id: "c3po",
                        count_reopens: 1,
                        count_assignments: 1,
                        count_conversation_parts: 1,
                        handling_time: 2310,
                        adjusted_handling_time: 1800,
                    },
                    conversation_parts: { total_count: 1 },
                    linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
                    ai_agent_participated: false,
                    ai_agent: {
                        source_title: "My AI Workflow",
                        rating: 4,
                        rating_remark: "Very helpful!",
                        created_at: 1663597260,
                        updated_at: 1663597260,
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 20,
                total_pages: 1,
            },
        };
        server
            .mockEndpoint({ once: false })
            .get("/conversations")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            type: "conversation.list",
            conversations: [
                {
                    type: "conversation",
                    id: "471",
                    title: "Conversation Title",
                    created_at: 1734537460,
                    updated_at: 1734537460,
                    waiting_since: 1663597260,
                    snoozed_until: 1663597260,
                    open: false,
                    state: "closed",
                    read: false,
                    priority: "not_priority",
                    admin_assignee_id: 0,
                    team_assignee_id: "5017691",
                    company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
                    tags: {
                        type: "tag.list",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                                applied_at: 1663597223,
                            },
                        ],
                    },
                    conversation_rating: {
                        rating: 5,
                        remark: "",
                        created_at: 1671028894,
                        updated_at: 1671028894,
                    },
                    source: {
                        type: "conversation",
                        id: "403918320",
                        delivered_as: "admin_initiated",
                        subject: "",
                        body: "<p>this is the message body</p>",
                        author: {
                            type: "admin",
                            id: "991267628",
                            name: "Ciaran166 Lee",
                            email: "admin166@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        redacted: false,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [
                            {
                                type: "contact",
                                id: "6762f0f31bb69f9f2193bb8b",
                                external_id: "70",
                            },
                        ],
                    },
                    teammates: {
                        type: "admin.list",
                        admins: [
                            {
                                type: "contact",
                                id: "1a2b3c",
                            },
                        ],
                    },
                    custom_attributes: {
                        key: "value",
                    },
                    first_contact_reply: {
                        created_at: 1663597223,
                        type: "conversation",
                        url: "https://developers.intercom.com/",
                    },
                    sla_applied: {
                        type: "conversation_sla_summary",
                        sla_name: "",
                    },
                    statistics: {
                        type: "conversation_statistics",
                        time_to_assignment: 2310,
                        time_to_admin_reply: 2310,
                        time_to_first_close: 2310,
                        time_to_last_close: 2310,
                        median_time_to_reply: 2310,
                        first_contact_reply_at: 1663597233,
                        first_assignment_at: 1663597233,
                        first_admin_reply_at: 1663597233,
                        first_close_at: 1663597233,
                        last_assignment_at: 1663597233,
                        last_assignment_admin_reply_at: 1663597233,
                        last_contact_reply_at: 1663597233,
                        last_admin_reply_at: 1663597233,
                        last_close_at: 1663597233,
                        last_closed_by_id: "c3po",
                        count_reopens: 1,
                        count_assignments: 1,
                        count_conversation_parts: 1,
                        handling_time: 2310,
                        adjusted_handling_time: 1800,
                    },
                    conversation_parts: {
                        total_count: 1,
                    },
                    linked_objects: {
                        type: "list",
                        total_count: 0,
                        has_more: false,
                        data: [
                            {
                                id: "7583",
                            },
                        ],
                    },
                    ai_agent_participated: false,
                    ai_agent: {
                        source_title: "My AI Workflow",
                        rating: 4,
                        rating_remark: "Very helpful!",
                        created_at: 1663597260,
                        updated_at: 1663597260,
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 20,
                total_pages: 1,
            },
        };
        const page = await client.conversations.list({
            per_page: 1,
            starting_after: "starting_after",
        });

        expect(expected.conversations).toEqual(page.data);
        expect(page.hasNextPage()).toBe(true);
        const nextPage = await page.getNextPage();
        expect(expected.conversations).toEqual(nextPage.data);
    });

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

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

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

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

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

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

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: { type: "user", id: "6762f11b1bb69f9f2193bba3" }, body: "Hello there" };
        const rawResponseBody = {
            type: "user_message",
            id: "403918330",
            created_at: 1734537501,
            subject: "Greetings",
            body: "Hello there",
            message_type: "inapp",
            conversation_id: "499",
        };
        server
            .mockEndpoint()
            .post("/conversations")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.create({
            from: {
                type: "user",
                id: "6762f11b1bb69f9f2193bba3",
            },
            body: "Hello there",
        });
        expect(response).toEqual({
            type: "user_message",
            id: "403918330",
            created_at: 1734537501,
            subject: "Greetings",
            body: "Hello there",
            message_type: "inapp",
            conversation_id: "499",
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: { type: "user", id: "123_doesnt_exist" }, body: "Hello there" };
        const rawResponseBody = {
            type: "user_message",
            id: "403918330",
            created_at: 1734537501,
            subject: "Greetings",
            body: "Hello there",
            message_type: "inapp",
            conversation_id: "499",
        };
        server
            .mockEndpoint()
            .post("/conversations")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.create({
            from: {
                type: "user",
                id: "123_doesnt_exist",
            },
            body: "Hello there",
        });
        expect(response).toEqual({
            type: "user_message",
            id: "403918330",
            created_at: 1734537501,
            subject: "Greetings",
            body: "Hello there",
            message_type: "inapp",
            conversation_id: "499",
        });
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: { type: "lead", id: "blackcurrant............" }, body: "body" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.create({
                from: {
                    type: "lead",
                    id: "blackcurrant............",
                },
                body: "body",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: { type: "lead", id: "blackcurrant............" }, body: "body" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.create({
                from: {
                    type: "lead",
                    id: "blackcurrant............",
                },
                body: "body",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: { type: "lead", id: "blackcurrant............" }, body: "body" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/conversations")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.create({
                from: {
                    type: "lead",
                    id: "blackcurrant............",
                },
                body: "body",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = {
            type: "conversation",
            id: "503",
            title: "Conversation Title",
            created_at: 1734537511,
            updated_at: 1734537511,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                        applied_by: { type: "contact", id: "1a2b3c" },
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918334",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267645",
                    name: "Ciaran176 Lee",
                    email: "admin176@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1261bb69f9f2193bba7", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        assigned_to: { type: "contact", id: "1a2b3c" },
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Operator",
                            email: "operator+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [{ type: "tag", id: "123456", name: "Test tag" }],
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "custom_action_started",
                        body: "<p>Okay!</p>",
                        created_at: 1740141842,
                        updated_at: 1740141842,
                        notified_at: 1740141842,
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Jamie Oliver",
                            email: "jamie+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [{ type: "tag", id: "123456", name: "Test tag" }],
                        event_details: { action: { name: "Jira Create Issue" } },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1740141851,
                        updated_at: 1740141851,
                        notified_at: 1740141851,
                        author: {
                            type: "bot",
                            id: "278",
                            name: "Fin",
                            email: "operator+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [{ type: "tag", id: "123456", name: "Test tag" }],
                        event_details: { attribute: { name: "jira_issue_key" }, value: { name: "PROJ-007" } },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "custom_action_finished",
                        body: "<p>Okay!</p>",
                        created_at: 1740141857,
                        updated_at: 1740141857,
                        notified_at: 1740141857,
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Jamie Oliver",
                            email: "jamie+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "closed",
                        tags: [{ type: "tag", id: "123456", name: "Test tag" }],
                        event_details: { action: { name: "Jira Create Issue", result: "success" } },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 4,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server.mockEndpoint().get("/conversations/123").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.conversations.find({
            conversation_id: "123",
            display_as: "plaintext",
            include_translations: true,
        });
        expect(response).toEqual({
            type: "conversation",
            id: "503",
            title: "Conversation Title",
            created_at: 1734537511,
            updated_at: 1734537511,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                        applied_by: {
                            type: "contact",
                            id: "1a2b3c",
                        },
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918334",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267645",
                    name: "Ciaran176 Lee",
                    email: "admin176@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1261bb69f9f2193bba7",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        assigned_to: {
                            type: "contact",
                            id: "1a2b3c",
                        },
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Operator",
                            email: "operator+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                            },
                        ],
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "custom_action_started",
                        body: "<p>Okay!</p>",
                        created_at: 1740141842,
                        updated_at: 1740141842,
                        notified_at: 1740141842,
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Jamie Oliver",
                            email: "jamie+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                            },
                        ],
                        event_details: {
                            action: {
                                name: "Jira Create Issue",
                            },
                        },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1740141851,
                        updated_at: 1740141851,
                        notified_at: 1740141851,
                        author: {
                            type: "bot",
                            id: "278",
                            name: "Fin",
                            email: "operator+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "open",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                            },
                        ],
                        event_details: {
                            attribute: {
                                name: "jira_issue_key",
                            },
                            value: {
                                name: "PROJ-007",
                            },
                        },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "custom_action_finished",
                        body: "<p>Okay!</p>",
                        created_at: 1740141857,
                        updated_at: 1740141857,
                        notified_at: 1740141857,
                        author: {
                            type: "admin",
                            id: "274",
                            name: "Jamie Oliver",
                            email: "jamie+abcd1234@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        state: "closed",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                            },
                        ],
                        event_details: {
                            action: {
                                name: "Jira Create Issue",
                                result: "success",
                            },
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 4,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

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

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

        await expect(async () => {
            return await client.conversations.find({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

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

        await expect(async () => {
            return await client.conversations.find({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

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

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

        await expect(async () => {
            return await client.conversations.find({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            read: true,
            title: "new conversation title",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = {
            type: "conversation",
            id: "507",
            title: "Conversation Title",
            created_at: 1734537521,
            updated_at: 1734537523,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918338",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267653",
                    name: "Ciaran180 Lee",
                    email: "admin180@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1301bb69f9f2193bbab", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { issue_type: "Billing", priority: "High" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "129",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "130",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 2,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .put("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.update({
            conversation_id: "conversation_id",
            display_as: "plaintext",
            read: true,
            title: "new conversation title",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "507",
            title: "Conversation Title",
            created_at: 1734537521,
            updated_at: 1734537523,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918338",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267653",
                    name: "Ciaran180 Lee",
                    email: "admin180@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1301bb69f9f2193bbab",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "129",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "130",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 2,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("update (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { custom_attributes: { order: {} } };
        const rawResponseBody = {
            type: "conversation",
            id: "508",
            title: "Conversation Title",
            created_at: 1734537525,
            updated_at: 1734537525,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918339",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267659",
                    name: "Ciaran185 Lee",
                    email: "admin185@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1341bb69f9f2193bbac", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                order: {
                    type: "Order.list",
                    instances: [
                        {
                            id: "21",
                            external_id: "123",
                            external_created_at: 1392036272,
                            external_updated_at: 1392036272,
                            created_at: 1671028894,
                            updated_at: 1671028894,
                            type: "Order",
                            custom_attributes: { order_number: "ORDER-12345", total_amount: "custom_attributes" },
                        },
                    ],
                },
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 0,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .put("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.update({
            conversation_id: "conversation_id",
            display_as: "plaintext",
            custom_attributes: {
                order: {},
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "508",
            title: "Conversation Title",
            created_at: 1734537525,
            updated_at: 1734537525,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918339",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267659",
                    name: "Ciaran185 Lee",
                    email: "admin185@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1341bb69f9f2193bbac",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                order: {
                    type: "Order.list",
                    instances: [
                        {
                            id: "21",
                            external_id: "123",
                            external_created_at: 1392036272,
                            external_updated_at: 1392036272,
                            created_at: 1671028894,
                            updated_at: 1671028894,
                            type: "Order",
                            custom_attributes: {
                                order_number: "ORDER-12345",
                                total_amount: "custom_attributes",
                            },
                        },
                    ],
                },
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 0,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("update (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            read: true,
            title: "new conversation title",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = {
            type: "conversation",
            id: "507",
            title: "Conversation Title",
            created_at: 1734537521,
            updated_at: 1734537523,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918338",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267653",
                    name: "Ciaran180 Lee",
                    email: "admin180@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1301bb69f9f2193bbab", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { issue_type: "Billing", priority: "High" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "129",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "130",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 2,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .put("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.update({
            conversation_id: "conversation_id",
            display_as: "plaintext",
            read: true,
            title: "new conversation title",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "507",
            title: "Conversation Title",
            created_at: 1734537521,
            updated_at: 1734537523,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918338",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267653",
                    name: "Ciaran180 Lee",
                    email: "admin180@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1301bb69f9f2193bbab",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "129",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                    {
                        type: "conversation_part",
                        id: "130",
                        part_type: "conversation_attribute_updated_by_admin",
                        body: "<p>Okay!</p>",
                        created_at: 1734537523,
                        updated_at: 1734537523,
                        notified_at: 1734537523,
                        author: {
                            type: "bot",
                            id: "991267654",
                            name: "Fin",
                            email: "operator+this_is_an_id354_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 2,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("update (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("update (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.update({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("update (6)", 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("/conversations/conversation_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.update({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = { id: "512", object: "conversation", deleted: true };
        server
            .mockEndpoint()
            .delete("/conversations/1")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.deleteConversation({
            conversation_id: 1,
        });
        expect(response).toEqual({
            id: "512",
            object: "conversation",
            deleted: true,
        });
    });

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

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

        await expect(async () => {
            return await client.conversations.deleteConversation({
                conversation_id: 1,
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/conversations/1")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.deleteConversation({
                conversation_id: 1,
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("search", 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: "conversation.list",
            conversations: [
                {
                    type: "conversation",
                    id: "515",
                    title: "Conversation Title",
                    created_at: 1734537546,
                    updated_at: 1734537546,
                    waiting_since: 1663597260,
                    snoozed_until: 1663597260,
                    open: false,
                    state: "closed",
                    read: false,
                    priority: "not_priority",
                    admin_assignee_id: 0,
                    team_assignee_id: "5017691",
                    company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
                    tags: {
                        type: "tag.list",
                        tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }],
                    },
                    conversation_rating: { rating: 5, remark: "", created_at: 1671028894, updated_at: 1671028894 },
                    source: {
                        type: "conversation",
                        id: "403918346",
                        delivered_as: "admin_initiated",
                        subject: "",
                        body: "<p>this is the message body</p>",
                        author: {
                            type: "admin",
                            id: "991267691",
                            name: "Ciaran210 Lee",
                            email: "admin210@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        redacted: false,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [{ type: "contact", id: "6762f14a1bb69f9f2193bbb3", external_id: "70" }],
                    },
                    teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
                    custom_attributes: { key: "value" },
                    first_contact_reply: {
                        created_at: 1663597223,
                        type: "conversation",
                        url: "https://developers.intercom.com/",
                    },
                    sla_applied: { type: "conversation_sla_summary", sla_name: "" },
                    statistics: {
                        type: "conversation_statistics",
                        time_to_assignment: 2310,
                        time_to_admin_reply: 2310,
                        time_to_first_close: 2310,
                        time_to_last_close: 2310,
                        median_time_to_reply: 2310,
                        first_contact_reply_at: 1663597233,
                        first_assignment_at: 1663597233,
                        first_admin_reply_at: 1663597233,
                        first_close_at: 1663597233,
                        last_assignment_at: 1663597233,
                        last_assignment_admin_reply_at: 1663597233,
                        last_contact_reply_at: 1663597233,
                        last_admin_reply_at: 1663597233,
                        last_close_at: 1663597233,
                        last_closed_by_id: "c3po",
                        count_reopens: 1,
                        count_assignments: 1,
                        count_conversation_parts: 1,
                        handling_time: 2310,
                        adjusted_handling_time: 1800,
                    },
                    conversation_parts: { total_count: 1 },
                    linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
                    ai_agent_participated: false,
                    ai_agent: {
                        source_title: "My AI Workflow",
                        rating: 4,
                        rating_remark: "Very helpful!",
                        created_at: 1663597260,
                        updated_at: 1663597260,
                    },
                },
            ],
            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({ once: false })
            .post("/conversations/search")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            type: "conversation.list",
            conversations: [
                {
                    type: "conversation",
                    id: "515",
                    title: "Conversation Title",
                    created_at: 1734537546,
                    updated_at: 1734537546,
                    waiting_since: 1663597260,
                    snoozed_until: 1663597260,
                    open: false,
                    state: "closed",
                    read: false,
                    priority: "not_priority",
                    admin_assignee_id: 0,
                    team_assignee_id: "5017691",
                    company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
                    tags: {
                        type: "tag.list",
                        tags: [
                            {
                                type: "tag",
                                id: "123456",
                                name: "Test tag",
                                applied_at: 1663597223,
                            },
                        ],
                    },
                    conversation_rating: {
                        rating: 5,
                        remark: "",
                        created_at: 1671028894,
                        updated_at: 1671028894,
                    },
                    source: {
                        type: "conversation",
                        id: "403918346",
                        delivered_as: "admin_initiated",
                        subject: "",
                        body: "<p>this is the message body</p>",
                        author: {
                            type: "admin",
                            id: "991267691",
                            name: "Ciaran210 Lee",
                            email: "admin210@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        attachments: [
                            {
                                type: "upload",
                                name: "example.png",
                                url: "https://picsum.photos/200/300",
                                content_type: "image/png",
                                filesize: 100,
                                width: 100,
                                height: 100,
                            },
                        ],
                        redacted: false,
                    },
                    contacts: {
                        type: "contact.list",
                        contacts: [
                            {
                                type: "contact",
                                id: "6762f14a1bb69f9f2193bbb3",
                                external_id: "70",
                            },
                        ],
                    },
                    teammates: {
                        type: "admin.list",
                        admins: [
                            {
                                type: "contact",
                                id: "1a2b3c",
                            },
                        ],
                    },
                    custom_attributes: {
                        key: "value",
                    },
                    first_contact_reply: {
                        created_at: 1663597223,
                        type: "conversation",
                        url: "https://developers.intercom.com/",
                    },
                    sla_applied: {
                        type: "conversation_sla_summary",
                        sla_name: "",
                    },
                    statistics: {
                        type: "conversation_statistics",
                        time_to_assignment: 2310,
                        time_to_admin_reply: 2310,
                        time_to_first_close: 2310,
                        time_to_last_close: 2310,
                        median_time_to_reply: 2310,
                        first_contact_reply_at: 1663597233,
                        first_assignment_at: 1663597233,
                        first_admin_reply_at: 1663597233,
                        first_close_at: 1663597233,
                        last_assignment_at: 1663597233,
                        last_assignment_admin_reply_at: 1663597233,
                        last_contact_reply_at: 1663597233,
                        last_admin_reply_at: 1663597233,
                        last_close_at: 1663597233,
                        last_closed_by_id: "c3po",
                        count_reopens: 1,
                        count_assignments: 1,
                        count_conversation_parts: 1,
                        handling_time: 2310,
                        adjusted_handling_time: 1800,
                    },
                    conversation_parts: {
                        total_count: 1,
                    },
                    linked_objects: {
                        type: "list",
                        total_count: 0,
                        has_more: false,
                        data: [
                            {
                                id: "7583",
                            },
                        ],
                    },
                    ai_agent_participated: false,
                    ai_agent: {
                        source_title: "My AI Workflow",
                        rating: 4,
                        rating_remark: "Very helpful!",
                        created_at: 1663597260,
                        updated_at: 1663597260,
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 5,
                total_pages: 1,
            },
        };
        const page = await client.conversations.search({
            query: {
                operator: "AND",
                value: [
                    {
                        field: "created_at",
                        operator: ">",
                        value: "1306054154",
                    },
                ],
            },
            pagination: {
                per_page: 5,
            },
        });

        expect(expected.conversations).toEqual(page.data);
        expect(page.hasNextPage()).toBe(true);
        const nextPage = await page.getNextPage();
        expect(expected.conversations).toEqual(nextPage.data);
    });

    test("reply (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: "6762f1571bb69f9f2193bbbb",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1571bb69f9f2193bbbb", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f1571bb69f9f2193bbbb",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1571bb69f9f2193bbbb",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (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: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1571bb69f9f2193bbbb", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            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: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1571bb69f9f2193bbbb",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (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: "a5e1c524-5ddd-4c3e-9328-6bca5d6e3edb" },
                { text: "No", uuid: "f4a98af1-be56-4948-a57e-e1a83f8484c6" },
            ],
        };
        const rawResponseBody = {
            type: "conversation",
            id: "526",
            title: "Conversation Title",
            created_at: 1734537567,
            updated_at: 1734537568,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918351",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267698",
                    name: "Ciaran214 Lee",
                    email: "admin214@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f15e1bb69f9f2193bbbd", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "134",
                        part_type: "quick_reply",
                        body: "<p>Okay!</p>",
                        created_at: 1734537568,
                        updated_at: 1734537568,
                        notified_at: 1734537568,
                        author: {
                            type: "admin",
                            id: "991267698",
                            name: "Ciaran214 Lee",
                            email: "admin214@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "quick_reply",
                type: "admin",
                admin_id: "3156780",
                reply_options: [
                    {
                        text: "Yes",
                        uuid: "a5e1c524-5ddd-4c3e-9328-6bca5d6e3edb",
                    },
                    {
                        text: "No",
                        uuid: "f4a98af1-be56-4948-a57e-e1a83f8484c6",
                    },
                ],
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "526",
            title: "Conversation Title",
            created_at: 1734537567,
            updated_at: 1734537568,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918351",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267698",
                    name: "Ciaran214 Lee",
                    email: "admin214@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f15e1bb69f9f2193bbbd",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "134",
                        part_type: "quick_reply",
                        body: "<p>Okay!</p>",
                        created_at: 1734537568,
                        updated_at: 1734537568,
                        notified_at: 1734537568,
                        author: {
                            type: "admin",
                            id: "991267698",
                            name: "Ciaran214 Lee",
                            email: "admin214@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (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: "body",
            reply_options: [{ text: "Yes", uuid: "a5e1c524-5ddd-4c3e-9328-6bca5d6e3edb" }],
            intercom_user_id: "6762f1621bb69f9f2193bbbe",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1571bb69f9f2193bbbb", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "body",
                reply_options: [
                    {
                        text: "Yes",
                        uuid: "a5e1c524-5ddd-4c3e-9328-6bca5d6e3edb",
                    },
                ],
                intercom_user_id: "6762f1621bb69f9f2193bbbe",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1571bb69f9f2193bbbb",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (5)", 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: "6762f1661bb69f9f2193bbbf",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1571bb69f9f2193bbbb", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f1661bb69f9f2193bbbf",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1571bb69f9f2193bbbb",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (6)", 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: "6762f1571bb69f9f2193bbbb",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1571bb69f9f2193bbbb", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f1571bb69f9f2193bbbb",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "524",
            title: "Conversation Title",
            created_at: 1734537559,
            updated_at: 1734537561,
            waiting_since: 1734537561,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918349",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267694",
                    name: "Ciaran212 Lee",
                    email: "admin212@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1571bb69f9f2193bbbb",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537561,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "132",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537561,
                        updated_at: 1734537561,
                        notified_at: 1734537561,
                        author: {
                            type: "user",
                            id: "6762f1571bb69f9f2193bbbb",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (7)", 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: "6762f1571bb69f9f2193bbbb",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "525",
            title: "Conversation Title",
            created_at: 1734537563,
            updated_at: 1734537565,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918350",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267696",
                    name: "Ciaran213 Lee",
                    email: "admin213@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f15b1bb69f9f2193bbbc", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "133",
                        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: 1734537565,
                        updated_at: 1734537565,
                        notified_at: 1734537565,
                        author: {
                            type: "admin",
                            id: "991267696",
                            name: "Ciaran213 Lee",
                            email: "admin213@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f1571bb69f9f2193bbbb",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "525",
            title: "Conversation Title",
            created_at: 1734537563,
            updated_at: 1734537565,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918350",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267696",
                    name: "Ciaran213 Lee",
                    email: "admin213@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f15b1bb69f9f2193bbbc",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "133",
                        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: 1734537565,
                        updated_at: 1734537565,
                        notified_at: 1734537565,
                        author: {
                            type: "admin",
                            id: "991267696",
                            name: "Ciaran213 Lee",
                            email: "admin213@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (8)", 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: "6762f1571bb69f9f2193bbbb",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "527",
            title: "Conversation Title",
            created_at: 1734537571,
            updated_at: 1734537572,
            waiting_since: 1734537572,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918352",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267700",
                    name: "Ciaran215 Lee",
                    email: "admin215@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1621bb69f9f2193bbbe", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537572,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "135",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537572,
                        updated_at: 1734537572,
                        notified_at: 1734537572,
                        author: {
                            type: "user",
                            id: "6762f1621bb69f9f2193bbbe",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123%20or%20%22last%22/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.reply({
            conversation_id: '123 or "last"',
            body: {
                message_type: "comment",
                type: "user",
                body: "Thanks again :)",
                intercom_user_id: "6762f1571bb69f9f2193bbbb",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "527",
            title: "Conversation Title",
            created_at: 1734537571,
            updated_at: 1734537572,
            waiting_since: 1734537572,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918352",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267700",
                    name: "Ciaran215 Lee",
                    email: "admin215@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1621bb69f9f2193bbbe",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537572,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "135",
                        part_type: "open",
                        body: "<p>Thanks again :)</p>",
                        created_at: 1734537572,
                        updated_at: 1734537572,
                        notified_at: 1734537572,
                        author: {
                            type: "user",
                            id: "6762f1621bb69f9f2193bbbe",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("reply (9)", 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: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.reply({
                conversation_id: "conversation_id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("reply (10)", 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: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.reply({
                conversation_id: "conversation_id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("reply (11)", 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("/conversations/conversation_id/reply")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.reply({
                conversation_id: "conversation_id",
                body: {
                    intercom_user_id: "intercom_user_id",
                    message_type: "comment",
                    type: "user",
                    body: "body",
                },
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("manage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "close", type: "admin", admin_id: "12345" };
        const rawResponseBody = {
            type: "conversation",
            id: "531",
            title: "Conversation Title",
            created_at: 1734537582,
            updated_at: 1734537584,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918356",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267708",
                    name: "Ciaran219 Lee",
                    email: "admin219@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f16e1bb69f9f2193bbc2", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "136",
                        part_type: "close",
                        body: "<p>Goodbye :)</p>",
                        created_at: 1734537584,
                        updated_at: 1734537584,
                        notified_at: 1734537584,
                        author: {
                            type: "admin",
                            id: "991267708",
                            name: "Ciaran219 Lee",
                            email: "admin219@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.manage({
            conversation_id: "123",
            body: {
                message_type: "close",
                type: "admin",
                admin_id: "12345",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "531",
            title: "Conversation Title",
            created_at: 1734537582,
            updated_at: 1734537584,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918356",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267708",
                    name: "Ciaran219 Lee",
                    email: "admin219@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f16e1bb69f9f2193bbc2",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "136",
                        part_type: "close",
                        body: "<p>Goodbye :)</p>",
                        created_at: 1734537584,
                        updated_at: 1734537584,
                        notified_at: 1734537584,
                        author: {
                            type: "admin",
                            id: "991267708",
                            name: "Ciaran219 Lee",
                            email: "admin219@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("manage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "snoozed", admin_id: "5017691", snoozed_until: 1673609604 };
        const rawResponseBody = {
            type: "conversation",
            id: "532",
            title: "Conversation Title",
            created_at: 1734537586,
            updated_at: 1734537587,
            waiting_since: 1663597260,
            snoozed_until: 1734541187,
            open: true,
            state: "snoozed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918357",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267710",
                    name: "Ciaran220 Lee",
                    email: "admin220@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1711bb69f9f2193bbc3", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "137",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537587,
                        updated_at: 1734537587,
                        notified_at: 1734537587,
                        author: {
                            type: "admin",
                            id: "991267710",
                            name: "Ciaran220 Lee",
                            email: "admin220@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.manage({
            conversation_id: "123",
            body: {
                message_type: "snoozed",
                admin_id: "5017691",
                snoozed_until: 1673609604,
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "532",
            title: "Conversation Title",
            created_at: 1734537586,
            updated_at: 1734537587,
            waiting_since: 1663597260,
            snoozed_until: 1734541187,
            open: true,
            state: "snoozed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918357",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267710",
                    name: "Ciaran220 Lee",
                    email: "admin220@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1711bb69f9f2193bbc3",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "137",
                        part_type: "snoozed",
                        body: "<p>Okay!</p>",
                        created_at: 1734537587,
                        updated_at: 1734537587,
                        notified_at: 1734537587,
                        author: {
                            type: "admin",
                            id: "991267710",
                            name: "Ciaran220 Lee",
                            email: "admin220@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("manage (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "open", admin_id: "5017690" };
        const rawResponseBody = {
            type: "conversation",
            id: "537",
            title: "",
            created_at: 1734537587,
            updated_at: 1734537601,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918358",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267712",
                    name: "Ciaran221 Lee",
                    email: "admin221@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1781bb69f9f2193bbc8", external_id: "74" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "139",
                        part_type: "open",
                        body: "<p>Okay!</p>",
                        created_at: 1734537601,
                        updated_at: 1734537601,
                        notified_at: 1734537601,
                        author: {
                            type: "admin",
                            id: "991267712",
                            name: "Ciaran221 Lee",
                            email: "admin221@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.manage({
            conversation_id: "123",
            body: {
                message_type: "open",
                admin_id: "5017690",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "537",
            title: "",
            created_at: 1734537587,
            updated_at: 1734537601,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918358",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267712",
                    name: "Ciaran221 Lee",
                    email: "admin221@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1781bb69f9f2193bbc8",
                        external_id: "74",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "139",
                        part_type: "open",
                        body: "<p>Okay!</p>",
                        created_at: 1734537601,
                        updated_at: 1734537601,
                        notified_at: 1734537601,
                        author: {
                            type: "admin",
                            id: "991267712",
                            name: "Ciaran221 Lee",
                            email: "admin221@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("manage (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "assignment", type: "admin", admin_id: "12345", assignee_id: "4324241" };
        const rawResponseBody = {
            type: "conversation",
            id: "542",
            title: "Conversation Title",
            created_at: 1734537603,
            updated_at: 1734537605,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 991267715,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918361",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267715",
                    name: "Ciaran223 Lee",
                    email: "admin223@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1831bb69f9f2193bbcc", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "140",
                        part_type: "assign_and_reopen",
                        body: "<p>Okay!</p>",
                        created_at: 1734537605,
                        updated_at: 1734537605,
                        notified_at: 1734537605,
                        assigned_to: { type: "admin", id: "991267715" },
                        author: {
                            type: "admin",
                            id: "991267715",
                            name: "Ciaran223 Lee",
                            email: "admin223@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.manage({
            conversation_id: "123",
            body: {
                message_type: "assignment",
                type: "admin",
                admin_id: "12345",
                assignee_id: "4324241",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "542",
            title: "Conversation Title",
            created_at: 1734537603,
            updated_at: 1734537605,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 991267715,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918361",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267715",
                    name: "Ciaran223 Lee",
                    email: "admin223@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1831bb69f9f2193bbcc",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "140",
                        part_type: "assign_and_reopen",
                        body: "<p>Okay!</p>",
                        created_at: 1734537605,
                        updated_at: 1734537605,
                        notified_at: 1734537605,
                        assigned_to: {
                            type: "admin",
                            id: "991267715",
                        },
                        author: {
                            type: "admin",
                            id: "991267715",
                            name: "Ciaran223 Lee",
                            email: "admin223@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("manage (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "close", type: "admin", admin_id: "12345" };
        const rawResponseBody = {
            type: "conversation",
            id: "531",
            title: "Conversation Title",
            created_at: 1734537582,
            updated_at: 1734537584,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918356",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267708",
                    name: "Ciaran219 Lee",
                    email: "admin219@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f16e1bb69f9f2193bbc2", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "136",
                        part_type: "close",
                        body: "<p>Goodbye :)</p>",
                        created_at: 1734537584,
                        updated_at: 1734537584,
                        notified_at: 1734537584,
                        author: {
                            type: "admin",
                            id: "991267708",
                            name: "Ciaran219 Lee",
                            email: "admin219@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.manage({
            conversation_id: "123",
            body: {
                message_type: "close",
                type: "admin",
                admin_id: "12345",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "531",
            title: "Conversation Title",
            created_at: 1734537582,
            updated_at: 1734537584,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918356",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267708",
                    name: "Ciaran219 Lee",
                    email: "admin219@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f16e1bb69f9f2193bbc2",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "136",
                        part_type: "close",
                        body: "<p>Goodbye :)</p>",
                        created_at: 1734537584,
                        updated_at: 1734537584,
                        notified_at: 1734537584,
                        author: {
                            type: "admin",
                            id: "991267708",
                            name: "Ciaran219 Lee",
                            email: "admin219@email.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("manage (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "close", type: "admin", admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.manage({
                conversation_id: "conversation_id",
                body: {
                    message_type: "close",
                    type: "admin",
                    admin_id: "admin_id",
                },
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("manage (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "close", type: "admin", admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.manage({
                conversation_id: "conversation_id",
                body: {
                    message_type: "close",
                    type: "admin",
                    admin_id: "admin_id",
                },
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("manage (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { message_type: "close", type: "admin", admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/parts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.manage({
                conversation_id: "conversation_id",
                body: {
                    message_type: "close",
                    type: "admin",
                    admin_id: "admin_id",
                },
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("attachContactAsAdmin (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "12345", customer: { intercom_user_id: "6762f19b1bb69f9f2193bbd4" } };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/customers")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.attachContactAsAdmin({
            conversation_id: "123",
            admin_id: "12345",
            customer: {
                intercom_user_id: "6762f19b1bb69f9f2193bbd4",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("attachContactAsAdmin (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "12345", customer: { intercom_user_id: "6762f19e1bb69f9f2193bbd5" } };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/customers")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.attachContactAsAdmin({
            conversation_id: "123",
            admin_id: "12345",
            customer: {
                intercom_user_id: "6762f19e1bb69f9f2193bbd5",
            },
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("attachContactAsAdmin (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/customers")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.attachContactAsAdmin({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("attachContactAsAdmin (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/customers")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.attachContactAsAdmin({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("attachContactAsAdmin (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()
            .post("/conversations/conversation_id/customers")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.attachContactAsAdmin({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("detachContactAsAdmin (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "5017690" };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .delete("/conversations/123/customers/123")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.detachContactAsAdmin({
            conversation_id: "123",
            contact_id: "123",
            admin_id: "5017690",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("detachContactAsAdmin (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "5017690" };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .delete("/conversations/123/customers/123")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.detachContactAsAdmin({
            conversation_id: "123",
            contact_id: "123",
            admin_id: "5017690",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("detachContactAsAdmin (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "5017690" };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .delete("/conversations/123/customers/123")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.detachContactAsAdmin({
            conversation_id: "123",
            contact_id: "123",
            admin_id: "5017690",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("detachContactAsAdmin (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "5017690" };
        const rawResponseBody = {
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: { type: "contact.list", contacts: [{ id: "5ba682d23d7cf92bef87bfd4", external_id: "70" }] },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: {
                paid_subscriber: { type: "order.list", instances: [] },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 100, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .delete("/conversations/123/customers/123")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.detachContactAsAdmin({
            conversation_id: "123",
            contact_id: "123",
            admin_id: "5017690",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "1295",
            title: "Conversation Title",
            created_at: 1663597223,
            updated_at: 1663597260,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "3",
                delivered_as: "operator_initiated",
                subject: "",
                body: "<p>Hey there!</p>",
                author: {
                    type: "admin",
                    id: "274",
                    name: "Operator",
                    email: "operator+abcd1234@intercom.io",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                paid_subscriber: {
                    type: "order.list",
                    instances: [],
                },
                monthly_spend: "155.5",
                team_mates: 9,
                start_date_iso8601: "2023-03-04T09:46:14Z",
                end_date_timestamp: 1677923174,
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "3",
                        part_type: "comment",
                        body: "<p>Okay!</p>",
                        created_at: 1663597223,
                        updated_at: 1663597260,
                        notified_at: 1663597260,
                        external_id: "abcd1234",
                        redacted: false,
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 100,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: true,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("detachContactAsAdmin (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/customers/contact_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.detachContactAsAdmin({
                conversation_id: "conversation_id",
                contact_id: "contact_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("detachContactAsAdmin (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/customers/contact_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.detachContactAsAdmin({
                conversation_id: "conversation_id",
                contact_id: "contact_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("detachContactAsAdmin (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/customers/contact_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.detachContactAsAdmin({
                conversation_id: "conversation_id",
                contact_id: "contact_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("detachContactAsAdmin (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/customers/contact_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.detachContactAsAdmin({
                conversation_id: "conversation_id",
                contact_id: "contact_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnprocessableEntityError);
    });

    test("redactConversationPart (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            type: "conversation_part",
            conversation_id: "19894788788",
            conversation_part_id: "19381789428",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "608",
            title: "Conversation Title",
            created_at: 1734537721,
            updated_at: 1734537724,
            waiting_since: 1734537722,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918391",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267757",
                    name: "Ciaran247 Lee",
                    email: "admin247@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1f81bb69f9f2193bc09", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537722,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "149",
                        part_type: "open",
                        body: "<p><i>This message was deleted</i></p>",
                        created_at: 1734537722,
                        updated_at: 1734537724,
                        notified_at: 1734537722,
                        author: {
                            type: "user",
                            id: "6762f1f81bb69f9f2193bc09",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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: true,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/redact")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.redactConversationPart({
            type: "conversation_part",
            conversation_id: "19894788788",
            conversation_part_id: "19381789428",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "608",
            title: "Conversation Title",
            created_at: 1734537721,
            updated_at: 1734537724,
            waiting_since: 1734537722,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918391",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267757",
                    name: "Ciaran247 Lee",
                    email: "admin247@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1f81bb69f9f2193bc09",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537722,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "149",
                        part_type: "open",
                        body: "<p><i>This message was deleted</i></p>",
                        created_at: 1734537722,
                        updated_at: 1734537724,
                        notified_at: 1734537722,
                        author: {
                            type: "user",
                            id: "6762f1f81bb69f9f2193bc09",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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: true,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("redactConversationPart (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            type: "conversation_part",
            conversation_id: "really_123_doesnt_exist",
            conversation_part_id: "really_123_doesnt_exist",
        };
        const rawResponseBody = {
            type: "conversation",
            id: "608",
            title: "Conversation Title",
            created_at: 1734537721,
            updated_at: 1734537724,
            waiting_since: 1734537722,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918391",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267757",
                    name: "Ciaran247 Lee",
                    email: "admin247@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f1f81bb69f9f2193bc09", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1734537722,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "149",
                        part_type: "open",
                        body: "<p><i>This message was deleted</i></p>",
                        created_at: 1734537722,
                        updated_at: 1734537724,
                        notified_at: 1734537722,
                        author: {
                            type: "user",
                            id: "6762f1f81bb69f9f2193bc09",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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: true,
                        metadata: { quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000" },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/redact")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.redactConversationPart({
            type: "conversation_part",
            conversation_id: "really_123_doesnt_exist",
            conversation_part_id: "really_123_doesnt_exist",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "608",
            title: "Conversation Title",
            created_at: 1734537721,
            updated_at: 1734537724,
            waiting_since: 1734537722,
            snoozed_until: 1663597260,
            open: true,
            state: "open",
            read: true,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918391",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267757",
                    name: "Ciaran247 Lee",
                    email: "admin247@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f1f81bb69f9f2193bc09",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1734537722,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "149",
                        part_type: "open",
                        body: "<p><i>This message was deleted</i></p>",
                        created_at: 1734537722,
                        updated_at: 1734537724,
                        notified_at: 1734537722,
                        author: {
                            type: "user",
                            id: "6762f1f81bb69f9f2193bc09",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.com",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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: true,
                        metadata: {
                            quick_reply_uuid: "123e4567-e89b-12d3-a456-426614174000",
                        },
                        app_package_code: "test-integration",
                    },
                ],
                total_count: 1,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

    test("redactConversationPart (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            type: "conversation_part",
            conversation_id: "conversation_id",
            conversation_part_id: "conversation_part_id",
        };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/redact")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.redactConversationPart({
                type: "conversation_part",
                conversation_id: "conversation_id",
                conversation_part_id: "conversation_part_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("redactConversationPart (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            type: "conversation_part",
            conversation_id: "conversation_id",
            conversation_part_id: "conversation_part_id",
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/conversations/redact")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.redactConversationPart({
                type: "conversation_part",
                conversation_id: "conversation_id",
                conversation_part_id: "conversation_part_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("convertToTicket (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: "53" };
        const rawResponseBody = {
            type: "ticket",
            id: "611",
            ticket_id: "22",
            category: "Customer",
            ticket_attributes: { key: "value" },
            ticket_state: {
                type: "ticket_state",
                id: "7493",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "53",
                category: "Customer",
                name: "my-ticket-type-1",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id442_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537737,
                updated_at: 1734537737,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f2041bb69f9f2193bc0c", external_id: "70" }],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537732,
            updated_at: 1734537737,
            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: "151",
                        part_type: "comment",
                        body: "<p>Comment for message</p>",
                        created_at: 1734537732,
                        updated_at: 1734537732,
                        author: {
                            type: "user",
                            id: "6762f2041bb69f9f2193bc0c",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.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",
                    },
                    {
                        type: "ticket_part",
                        id: "152",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537737,
                        updated_at: 1734537737,
                        author: {
                            type: "bot",
                            id: "991267767",
                            name: "Fin",
                            email: "operator+this_is_an_id442_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",
                    },
                ],
                total_count: 2,
            },
            is_shared: true,
        };
        server
            .mockEndpoint()
            .post("/conversations/1/convert")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.convertToTicket({
            conversation_id: 1,
            ticket_type_id: "53",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "611",
            ticket_id: "22",
            category: "Customer",
            ticket_attributes: {
                key: "value",
            },
            ticket_state: {
                type: "ticket_state",
                id: "7493",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "53",
                category: "Customer",
                name: "my-ticket-type-1",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id442_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537737,
                updated_at: 1734537737,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2041bb69f9f2193bc0c",
                        external_id: "70",
                    },
                ],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537732,
            updated_at: 1734537737,
            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: "151",
                        part_type: "comment",
                        body: "<p>Comment for message</p>",
                        created_at: 1734537732,
                        updated_at: 1734537732,
                        author: {
                            type: "user",
                            id: "6762f2041bb69f9f2193bc0c",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.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",
                    },
                    {
                        type: "ticket_part",
                        id: "152",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537737,
                        updated_at: 1734537737,
                        author: {
                            type: "bot",
                            id: "991267767",
                            name: "Fin",
                            email: "operator+this_is_an_id442_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",
                    },
                ],
                total_count: 2,
            },
            is_shared: true,
        });
    });

    test("convertToTicket (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: "54" };
        const rawResponseBody = {
            type: "ticket",
            id: "611",
            ticket_id: "22",
            category: "Customer",
            ticket_attributes: { key: "value" },
            ticket_state: {
                type: "ticket_state",
                id: "7493",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "53",
                category: "Customer",
                name: "my-ticket-type-1",
                description: "my ticket type description is awesome.",
                icon: "🦁",
                workspace_id: "this_is_an_id442_that_should_be_at_least_",
                ticket_type_attributes: { type: "list", ticket_type_attributes: [] },
                ticket_states: { type: "list", data: [] },
                archived: false,
                created_at: 1734537737,
                updated_at: 1734537737,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "6762f2041bb69f9f2193bc0c", external_id: "70" }],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537732,
            updated_at: 1734537737,
            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: "151",
                        part_type: "comment",
                        body: "<p>Comment for message</p>",
                        created_at: 1734537732,
                        updated_at: 1734537732,
                        author: {
                            type: "user",
                            id: "6762f2041bb69f9f2193bc0c",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.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",
                    },
                    {
                        type: "ticket_part",
                        id: "152",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537737,
                        updated_at: 1734537737,
                        author: {
                            type: "bot",
                            id: "991267767",
                            name: "Fin",
                            email: "operator+this_is_an_id442_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",
                    },
                ],
                total_count: 2,
            },
            is_shared: true,
        };
        server
            .mockEndpoint()
            .post("/conversations/1/convert")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.convertToTicket({
            conversation_id: 1,
            ticket_type_id: "54",
        });
        expect(response).toEqual({
            type: "ticket",
            id: "611",
            ticket_id: "22",
            category: "Customer",
            ticket_attributes: {
                key: "value",
            },
            ticket_state: {
                type: "ticket_state",
                id: "7493",
                category: "submitted",
                internal_label: "Submitted",
                external_label: "Submitted",
            },
            ticket_type: {
                type: "ticket_type",
                id: "53",
                category: "Customer",
                name: "my-ticket-type-1",
                description: "my ticket type description is awesome.",
                icon: "\uD83E\uDD81",
                workspace_id: "this_is_an_id442_that_should_be_at_least_",
                ticket_type_attributes: {
                    type: "list",
                    ticket_type_attributes: [],
                },
                ticket_states: {
                    type: "list",
                    data: [],
                },
                archived: false,
                created_at: 1734537737,
                updated_at: 1734537737,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "6762f2041bb69f9f2193bc0c",
                        external_id: "70",
                    },
                ],
            },
            admin_assignee_id: "0",
            team_assignee_id: "0",
            created_at: 1734537732,
            updated_at: 1734537737,
            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: "151",
                        part_type: "comment",
                        body: "<p>Comment for message</p>",
                        created_at: 1734537732,
                        updated_at: 1734537732,
                        author: {
                            type: "user",
                            id: "6762f2041bb69f9f2193bc0c",
                            name: "Joe Bloggs",
                            email: "joe@bloggs.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",
                    },
                    {
                        type: "ticket_part",
                        id: "152",
                        part_type: "ticket_state_updated_by_admin",
                        body: "<p>Okay!</p>",
                        previous_ticket_state: "submitted",
                        ticket_state: "submitted",
                        created_at: 1734537737,
                        updated_at: 1734537737,
                        author: {
                            type: "bot",
                            id: "991267767",
                            name: "Fin",
                            email: "operator+this_is_an_id442_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",
                    },
                ],
                total_count: 2,
            },
            is_shared: true,
        });
    });

    test("convertToTicket (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" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/conversations/1/convert")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.convertToTicket({
                conversation_id: 1,
                ticket_type_id: "ticket_type_id",
            });
        }).rejects.toThrow(Intercom.BadRequestError);
    });

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

        const rawResponseBody = {
            type: "conversation",
            id: "409",
            title: "Conversation Title",
            created_at: 1719492880,
            updated_at: 1719492881,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: { type: "tag.list", tags: [{ type: "tag", id: "123456", name: "Test tag", applied_at: 1663597223 }] },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70" },
                teammate: { type: "contact", id: "1a2b3c" },
            },
            source: {
                type: "conversation",
                id: "403918285",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267623",
                    name: "Ciaran197 Lee",
                    email: "admin197@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [{ type: "contact", id: "667d61108a68186f43bafe09", external_id: "70" }],
            },
            teammates: { type: "admin.list", admins: [{ type: "contact", id: "1a2b3c" }] },
            custom_attributes: { key: "value" },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: { type: "conversation_sla_summary", sla_name: "", sla_status: "hit" },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    { team_id: 100, team_name: "Team One", response_time: 2310 },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "107",
                        part_type: "default_assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1719492881,
                        updated_at: 1719492881,
                        notified_at: 1719492881,
                        assigned_to: { type: "nobody_admin", id: "1a2b3c" },
                        author: {
                            type: "bot",
                            id: "991267624",
                            name: "Operator",
                            email: "operator+this_is_an_id364_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
            },
            linked_objects: { type: "list", total_count: 0, has_more: false, data: [{ id: "7583" }] },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        };
        server
            .mockEndpoint()
            .post("/conversations/123/run_assignment_rules")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.conversations.runAssignmentRules({
            conversation_id: "123",
        });
        expect(response).toEqual({
            type: "conversation",
            id: "409",
            title: "Conversation Title",
            created_at: 1719492880,
            updated_at: 1719492881,
            waiting_since: 1663597260,
            snoozed_until: 1663597260,
            open: false,
            state: "closed",
            read: false,
            priority: "not_priority",
            admin_assignee_id: 0,
            team_assignee_id: "5017691",
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            tags: {
                type: "tag.list",
                tags: [
                    {
                        type: "tag",
                        id: "123456",
                        name: "Test tag",
                        applied_at: 1663597223,
                    },
                ],
            },
            conversation_rating: {
                rating: 5,
                remark: "",
                created_at: 1671028894,
                updated_at: 1671028894,
                contact: {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "70",
                },
                teammate: {
                    type: "contact",
                    id: "1a2b3c",
                },
            },
            source: {
                type: "conversation",
                id: "403918285",
                delivered_as: "admin_initiated",
                subject: "",
                body: "<p>this is the message body</p>",
                author: {
                    type: "admin",
                    id: "991267623",
                    name: "Ciaran197 Lee",
                    email: "admin197@email.com",
                    from_ai_agent: true,
                    is_ai_answer: false,
                },
                attachments: [
                    {
                        type: "upload",
                        name: "example.png",
                        url: "https://picsum.photos/200/300",
                        content_type: "image/png",
                        filesize: 100,
                        width: 100,
                        height: 100,
                    },
                ],
                url: "url",
                redacted: false,
            },
            contacts: {
                type: "contact.list",
                contacts: [
                    {
                        type: "contact",
                        id: "667d61108a68186f43bafe09",
                        external_id: "70",
                    },
                ],
            },
            teammates: {
                type: "admin.list",
                admins: [
                    {
                        type: "contact",
                        id: "1a2b3c",
                    },
                ],
            },
            custom_attributes: {
                key: "value",
            },
            first_contact_reply: {
                created_at: 1663597223,
                type: "conversation",
                url: "https://developers.intercom.com/",
            },
            sla_applied: {
                type: "conversation_sla_summary",
                sla_name: "",
                sla_status: "hit",
            },
            statistics: {
                type: "conversation_statistics",
                time_to_assignment: 2310,
                time_to_admin_reply: 2310,
                time_to_first_close: 2310,
                time_to_last_close: 2310,
                median_time_to_reply: 2310,
                first_contact_reply_at: 1663597233,
                first_assignment_at: 1663597233,
                first_admin_reply_at: 1663597233,
                first_close_at: 1663597233,
                last_assignment_at: 1663597233,
                last_assignment_admin_reply_at: 1663597233,
                last_contact_reply_at: 1663597233,
                last_admin_reply_at: 1663597233,
                last_close_at: 1663597233,
                last_closed_by_id: "c3po",
                count_reopens: 1,
                count_assignments: 1,
                count_conversation_parts: 1,
                assigned_team_first_response_time_by_team: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                assigned_team_first_response_time_in_office_hours: [
                    {
                        team_id: 100,
                        team_name: "Team One",
                        response_time: 2310,
                    },
                ],
                handling_time: 2310,
                adjusted_handling_time: 1800,
            },
            conversation_parts: {
                type: "conversation_part.list",
                conversation_parts: [
                    {
                        type: "conversation_part",
                        id: "107",
                        part_type: "default_assignment",
                        body: "<p>Okay!</p>",
                        created_at: 1719492881,
                        updated_at: 1719492881,
                        notified_at: 1719492881,
                        assigned_to: {
                            type: "nobody_admin",
                            id: "1a2b3c",
                        },
                        author: {
                            type: "bot",
                            id: "991267624",
                            name: "Operator",
                            email: "operator+this_is_an_id364_that_should_be_at_least_@intercom.io",
                            from_ai_agent: true,
                            is_ai_answer: false,
                        },
                        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,
            },
            linked_objects: {
                type: "list",
                total_count: 0,
                has_more: false,
                data: [
                    {
                        id: "7583",
                    },
                ],
            },
            ai_agent_participated: false,
            ai_agent: {
                source_type: "essentials_plan_setup",
                source_title: "My AI Workflow",
                last_answer_type: "ai_answer",
                resolution_state: "assumed_resolution",
                rating: 4,
                rating_remark: "Very helpful!",
                created_at: 1663597260,
                updated_at: 1663597260,
                content_sources: {
                    type: "content_source.list",
                    total_count: 1,
                    content_sources: [
                        {
                            url: "/fin-ai-agent/content?content=content_snippet&id=3234924",
                            title: "My internal content snippet",
                            locale: "en",
                        },
                    ],
                },
            },
        });
    });

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

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

        await expect(async () => {
            return await client.conversations.runAssignmentRules({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/run_assignment_rules")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.runAssignmentRules({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.ForbiddenError);
    });

    test("runAssignmentRules (4)", 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()
            .post("/conversations/conversation_id/run_assignment_rules")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.conversations.runAssignmentRules({
                conversation_id: "conversation_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });
});
