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

        const rawResponseBody = {
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 15,
                total_pages: 1,
            },
            total_count: 1,
            data: [
                {
                    type: "company",
                    id: "6762f07a1bb69f9f2193baea",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id153_that_should_be_at_least_",
                    plan: { type: "plan", id: "269315", name: "Pro" },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537338,
                    created_at: 1734537338,
                    updated_at: 1734537338,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: { key: "value" },
                    tags: { type: "tag.list" },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: { type: "note.list" },
                },
            ],
        };
        server.mockEndpoint().get("/companies").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.companies.retrieveCompany({
            name: "my company",
            company_id: "12345",
            tag_id: "678910",
            segment_id: "98765",
            page: 1,
            per_page: 1,
        });
        expect(response).toEqual({
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 15,
                total_pages: 1,
            },
            total_count: 1,
            data: [
                {
                    type: "company",
                    id: "6762f07a1bb69f9f2193baea",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id153_that_should_be_at_least_",
                    plan: {
                        type: "plan",
                        id: "269315",
                        name: "Pro",
                    },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537338,
                    created_at: 1734537338,
                    updated_at: 1734537338,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: {
                        key: "value",
                    },
                    tags: {
                        type: "tag.list",
                    },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: {
                        type: "note.list",
                    },
                },
            ],
        });
    });

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

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

        await expect(async () => {
            return await client.unstable.companies.retrieveCompany();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

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

        await expect(async () => {
            return await client.unstable.companies.retrieveCompany();
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("createOrUpdateCompany (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { key: "value" };
        const rawResponseBody = {
            type: "company",
            id: "id",
            name: "name",
            app_id: "app_id",
            plan: { type: "type", id: "id", name: "name" },
            company_id: "company_id",
            remote_created_at: 1,
            created_at: 1,
            updated_at: 1,
            last_request_at: 1,
            size: 1,
            website: "website",
            industry: "industry",
            monthly_spend: 1,
            session_count: 1,
            user_count: 1,
            custom_attributes: { custom_attributes: "custom_attributes" },
            tags: { type: "tag.list", tags: [{ key: "value" }, { key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        type: "segment",
                        id: "id",
                        name: "name",
                        created_at: 1,
                        updated_at: 1,
                        person_type: "contact",
                        count: 1,
                    },
                    {
                        type: "segment",
                        id: "id",
                        name: "name",
                        created_at: 1,
                        updated_at: 1,
                        person_type: "contact",
                        count: 1,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "type",
                        id: "id",
                        created_at: 1,
                        company: { type: "type", id: "id" },
                        author: {
                            type: "type",
                            id: "id",
                            name: "name",
                            email: "email",
                            job_title: "job_title",
                            away_mode_enabled: true,
                            away_mode_reassign: true,
                            away_status_reason_id: 1,
                            has_inbox_seat: true,
                            team_ids: [1, 1],
                            avatar: "avatar",
                            team_priority_level: {},
                        },
                        body: "body",
                    },
                    {
                        type: "type",
                        id: "id",
                        created_at: 1,
                        company: { type: "type", id: "id" },
                        author: {
                            type: "type",
                            id: "id",
                            name: "name",
                            email: "email",
                            job_title: "job_title",
                            away_mode_enabled: true,
                            away_mode_reassign: true,
                            away_status_reason_id: 1,
                            has_inbox_seat: true,
                            team_ids: [1, 1],
                            avatar: "avatar",
                            team_priority_level: {},
                        },
                        body: "body",
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .post("/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.createOrUpdateCompany({
            key: "value",
        });
        expect(response).toEqual({
            type: "company",
            id: "id",
            name: "name",
            app_id: "app_id",
            plan: {
                type: "type",
                id: "id",
                name: "name",
            },
            company_id: "company_id",
            remote_created_at: 1,
            created_at: 1,
            updated_at: 1,
            last_request_at: 1,
            size: 1,
            website: "website",
            industry: "industry",
            monthly_spend: 1,
            session_count: 1,
            user_count: 1,
            custom_attributes: {
                custom_attributes: "custom_attributes",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        type: "segment",
                        id: "id",
                        name: "name",
                        created_at: 1,
                        updated_at: 1,
                        person_type: "contact",
                        count: 1,
                    },
                    {
                        type: "segment",
                        id: "id",
                        name: "name",
                        created_at: 1,
                        updated_at: 1,
                        person_type: "contact",
                        count: 1,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "type",
                        id: "id",
                        created_at: 1,
                        company: {
                            type: "type",
                            id: "id",
                        },
                        author: {
                            type: "type",
                            id: "id",
                            name: "name",
                            email: "email",
                            job_title: "job_title",
                            away_mode_enabled: true,
                            away_mode_reassign: true,
                            away_status_reason_id: 1,
                            has_inbox_seat: true,
                            team_ids: [1, 1],
                            avatar: "avatar",
                            team_priority_level: {},
                        },
                        body: "body",
                    },
                    {
                        type: "type",
                        id: "id",
                        created_at: 1,
                        company: {
                            type: "type",
                            id: "id",
                        },
                        author: {
                            type: "type",
                            id: "id",
                            name: "name",
                            email: "email",
                            job_title: "job_title",
                            away_mode_enabled: true,
                            away_mode_reassign: true,
                            away_status_reason_id: 1,
                            has_inbox_seat: true,
                            team_ids: [1, 1],
                            avatar: "avatar",
                            team_priority_level: {},
                        },
                        body: "body",
                    },
                ],
            },
        });
    });

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

        await expect(async () => {
            return await client.unstable.companies.createOrUpdateCompany({
                key: "value",
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

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

        await expect(async () => {
            return await client.unstable.companies.createOrUpdateCompany({
                key: "value",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "company",
            id: "6762f07f1bb69f9f2193baf5",
            name: "company1",
            app_id: "this_is_an_id159_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537343,
            created_at: 1734537343,
            updated_at: 1734537343,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .get("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.retrieveACompanyById({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f07f1bb69f9f2193baf5",
            name: "company1",
            app_id: "this_is_an_id159_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537343,
            created_at: 1734537343,
            updated_at: 1734537343,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

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

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

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

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

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

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

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

        const rawResponseBody = {
            type: "company",
            id: "6762f0841bb69f9f2193baff",
            name: "company2",
            app_id: "this_is_an_id165_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537348,
            created_at: 1734537348,
            updated_at: 1734537348,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .put("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.updateCompany({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f0841bb69f9f2193baff",
            name: "company2",
            app_id: "this_is_an_id165_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537348,
            created_at: 1734537348,
            updated_at: 1734537348,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

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

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server.mockEndpoint().put("/companies/id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().put("/companies/id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

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

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

        const rawResponseBody = { id: "6762f0881bb69f9f2193bb09", object: "company", deleted: true };
        server
            .mockEndpoint()
            .delete("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.deleteCompany({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            id: "6762f0881bb69f9f2193bb09",
            object: "company",
            deleted: true,
        });
    });

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

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

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().delete("/companies/id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

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

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "f3b87a2e09d514c6c2e79b9a",
                    workspace_id: "ecahpwf5",
                    role: "user",
                    email: "joe@example.com",
                    email_domain: "example.com",
                    phone: "+1123456789",
                    formatted_phone: "+1123456789",
                    name: "John Doe",
                    owner_id: 123,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1571672154,
                    updated_at: 1571672154,
                    signed_up_at: 1571672154,
                    last_seen_at: 1571672154,
                    last_replied_at: 1571672154,
                    last_contacted_at: 1571672154,
                    last_email_opened_at: 1571672154,
                    last_email_clicked_at: 1571672154,
                    language_override: "en",
                    browser: "Chrome",
                    browser_version: "80.0.3987.132",
                    browser_language: "en-US",
                    os: "Mac OS X",
                    android_app_name: "Intercom",
                    android_app_version: "5.0.0",
                    android_device: "Pixel 3",
                    android_os_version: "10",
                    android_sdk_version: "28",
                    android_last_seen_at: 1571672154,
                    ios_app_name: "Intercom",
                    ios_app_version: "5.0.0",
                    ios_device: "iPhone 11",
                    ios_os_version: "13.3.1",
                    ios_sdk_version: "13.3.1",
                    ios_last_seen_at: 1571672154,
                    custom_attributes: { key: "value" },
                    avatar: { type: "avatar", image_url: "https://example.org/128Wash.jpg" },
                    tags: { url: "/contacts/5ba682d23d7cf92bef87bfd4/tags", total_count: 100, has_more: true },
                    notes: { url: "/contacts/5ba682d23d7cf92bef87bfd4/notes", total_count: 100, has_more: true },
                    companies: {
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/companies",
                        total_count: 100,
                        has_more: true,
                    },
                    location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
                },
            ],
            total_count: 0,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 50,
                total_pages: 0,
            },
        };
        server
            .mockEndpoint()
            .get("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632/contacts")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.listAttachedContacts({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "contact",
                    id: "5ba682d23d7cf92bef87bfd4",
                    external_id: "f3b87a2e09d514c6c2e79b9a",
                    workspace_id: "ecahpwf5",
                    role: "user",
                    email: "joe@example.com",
                    email_domain: "example.com",
                    phone: "+1123456789",
                    formatted_phone: "+1123456789",
                    name: "John Doe",
                    owner_id: 123,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1571672154,
                    updated_at: 1571672154,
                    signed_up_at: 1571672154,
                    last_seen_at: 1571672154,
                    last_replied_at: 1571672154,
                    last_contacted_at: 1571672154,
                    last_email_opened_at: 1571672154,
                    last_email_clicked_at: 1571672154,
                    language_override: "en",
                    browser: "Chrome",
                    browser_version: "80.0.3987.132",
                    browser_language: "en-US",
                    os: "Mac OS X",
                    android_app_name: "Intercom",
                    android_app_version: "5.0.0",
                    android_device: "Pixel 3",
                    android_os_version: "10",
                    android_sdk_version: "28",
                    android_last_seen_at: 1571672154,
                    ios_app_name: "Intercom",
                    ios_app_version: "5.0.0",
                    ios_device: "iPhone 11",
                    ios_os_version: "13.3.1",
                    ios_sdk_version: "13.3.1",
                    ios_last_seen_at: 1571672154,
                    custom_attributes: {
                        key: "value",
                    },
                    avatar: {
                        type: "avatar",
                        image_url: "https://example.org/128Wash.jpg",
                    },
                    tags: {
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/tags",
                        total_count: 100,
                        has_more: true,
                    },
                    notes: {
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                        total_count: 100,
                        has_more: true,
                    },
                    companies: {
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/companies",
                        total_count: 100,
                        has_more: true,
                    },
                    location: {
                        type: "location",
                        country: "Ireland",
                        region: "Dublin",
                        city: "Dublin",
                    },
                },
            ],
            total_count: 0,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 50,
                total_pages: 0,
            },
        });
    });

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

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

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

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

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

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

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "segment",
                    id: "56203d253cba154d39010062",
                    name: "Active",
                    created_at: 1394621988,
                    updated_at: 1394622004,
                    person_type: "contact",
                    count: 3,
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632/segments")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.listAttachedSegmentsForCompanies({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "segment",
                    id: "56203d253cba154d39010062",
                    name: "Active",
                    created_at: 1394621988,
                    updated_at: 1394622004,
                    person_type: "contact",
                    count: 3,
                },
            ],
        });
    });

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

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

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

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

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

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

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

        const rawResponseBody = {
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 15,
                total_pages: 1,
            },
            total_count: 1,
            data: [
                {
                    type: "company",
                    id: "6762f0941bb69f9f2193bb25",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id189_that_should_be_at_least_",
                    plan: { type: "plan", id: "269315", name: "Pro" },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537364,
                    created_at: 1734537364,
                    updated_at: 1734537364,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: { key: "value" },
                    tags: { type: "tag.list" },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: { type: "note.list" },
                },
            ],
        };
        server.mockEndpoint().post("/companies/list").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.companies.listAllCompanies({
            page: 1,
            per_page: 1,
            order: "desc",
        });
        expect(response).toEqual({
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 15,
                total_pages: 1,
            },
            total_count: 1,
            data: [
                {
                    type: "company",
                    id: "6762f0941bb69f9f2193bb25",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id189_that_should_be_at_least_",
                    plan: {
                        type: "plan",
                        id: "269315",
                        name: "Pro",
                    },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537364,
                    created_at: 1734537364,
                    updated_at: 1734537364,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: {
                        key: "value",
                    },
                    tags: {
                        type: "tag.list",
                    },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: {
                        type: "note.list",
                    },
                },
            ],
        });
    });

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

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

        await expect(async () => {
            return await client.unstable.companies.listAllCompanies();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "company",
                    id: "6762f0971bb69f9f2193bb2b",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id193_that_should_be_at_least_",
                    plan: { type: "plan", id: "269315", name: "Pro" },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537367,
                    created_at: 1734537367,
                    updated_at: 1734537367,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: { key: "value" },
                    tags: { type: "tag.list" },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: { type: "note.list" },
                },
            ],
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 2,
                total_pages: 13,
            },
            total_count: 100,
            scroll_param: "69352cd2-ab5b-42ac-b004-a13d4e55e9b0",
        };
        server.mockEndpoint().get("/companies/scroll").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.companies.scrollOverAllCompanies({
            scroll_param: "scroll_param",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "company",
                    id: "6762f0971bb69f9f2193bb2b",
                    name: "IntercomQATest1",
                    app_id: "this_is_an_id193_that_should_be_at_least_",
                    plan: {
                        type: "plan",
                        id: "269315",
                        name: "Pro",
                    },
                    company_id: "remote_companies_scroll_2",
                    remote_created_at: 1734537367,
                    created_at: 1734537367,
                    updated_at: 1734537367,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 0,
                    session_count: 0,
                    user_count: 4,
                    custom_attributes: {
                        key: "value",
                    },
                    tags: {
                        type: "tag.list",
                    },
                    segments: {
                        type: "segment.list",
                        segments: [
                            {
                                id: "56203d253cba154d39010062",
                                name: "Active",
                                created_at: 1394621988,
                                updated_at: 1394622004,
                                count: 3,
                            },
                        ],
                    },
                    notes: {
                        type: "note.list",
                    },
                },
            ],
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 2,
                total_pages: 13,
            },
            total_count: 100,
            scroll_param: "69352cd2-ab5b-42ac-b004-a13d4e55e9b0",
        });
    });

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

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

        await expect(async () => {
            return await client.unstable.companies.scrollOverAllCompanies();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("attachContactToACompany (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { company_id: "6762f09a1bb69f9f2193bb34" };
        const rawResponseBody = {
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.attachContactToACompany({
            id: "id",
            company_id: "6762f09a1bb69f9f2193bb34",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

    test("attachContactToACompany (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { company_id: "58a430d35458202d41b1e65b" };
        const rawResponseBody = {
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.attachContactToACompany({
            id: "id",
            company_id: "58a430d35458202d41b1e65b",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

    test("attachContactToACompany (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { company_id: "123" };
        const rawResponseBody = {
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.attachContactToACompany({
            id: "id",
            company_id: "123",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f09a1bb69f9f2193bb34",
            name: "company6",
            app_id: "this_is_an_id197_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537370,
            created_at: 1734537370,
            updated_at: 1734537370,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 1,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

    test("attachContactToACompany (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { company_id: "company_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/contacts/id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

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

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

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

    test("attachContactToACompany (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { company_id: "company_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/contacts/id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const rawResponseBody = {
            type: "company",
            id: "6762f0a01bb69f9f2193bb44",
            name: "company8",
            app_id: "this_is_an_id205_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "1",
            remote_created_at: 1734537376,
            created_at: 1734537376,
            updated_at: 1734537377,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: { key: "value" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [{ type: "note", id: "17495962", created_at: 1674589321, body: "<p>Text for the note.</p>" }],
            },
        };
        server
            .mockEndpoint()
            .delete("/contacts/58a430d35458202d41b1e65b/companies/58a430d35458202d41b1e65b")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.companies.detachContactFromACompany({
            contact_id: "58a430d35458202d41b1e65b",
            id: "58a430d35458202d41b1e65b",
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f0a01bb69f9f2193bb44",
            name: "company8",
            app_id: "this_is_an_id205_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "1",
            remote_created_at: 1734537376,
            created_at: 1734537376,
            updated_at: 1734537377,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: {
                key: "value",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
            notes: {
                type: "note.list",
                notes: [
                    {
                        type: "note",
                        id: "17495962",
                        created_at: 1674589321,
                        body: "<p>Text for the note.</p>",
                    },
                ],
            },
        });
    });

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

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/contacts/contact_id/companies/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/contacts/contact_id/companies/id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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