// 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("retrieve (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: "offset_pages", page: 1, next: "next", per_page: 2, total_pages: 13 },
            total_count: 100,
            data: [
                {
                    type: "company",
                    id: "531ee472cce572a6ec000006",
                    name: "Blue Sun",
                    app_id: "ecahpwf5",
                    plan: { type: "plan", id: "269315", name: "Pro" },
                    company_id: "6",
                    remote_created_at: 1663597223,
                    created_at: 1663597223,
                    updated_at: 1663597223,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 100,
                    session_count: 100,
                    user_count: 100,
                    custom_attributes: { paid_subscriber: true, monthly_spend: 155.5, team_mates: 9 },
                },
            ],
        };
        server.mockEndpoint().get("/companies").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.companies.retrieve({
            name: "my company",
            company_id: "12345",
            tag_id: "678910",
            segment_id: "98765",
            page: 1,
            per_page: 1,
        });
        expect(response).toEqual({
            type: "list",
            pages: {
                type: "offset_pages",
                page: 1,
                next: "next",
                per_page: 2,
                total_pages: 13,
            },
            total_count: 100,
            data: [
                {
                    type: "company",
                    id: "531ee472cce572a6ec000006",
                    name: "Blue Sun",
                    app_id: "ecahpwf5",
                    plan: {
                        type: "plan",
                        id: "269315",
                        name: "Pro",
                    },
                    company_id: "6",
                    remote_created_at: 1663597223,
                    created_at: 1663597223,
                    updated_at: 1663597223,
                    last_request_at: 1663597223,
                    size: 100,
                    website: "https://www.intercom.com",
                    industry: "Software",
                    monthly_spend: 100,
                    session_count: 100,
                    user_count: 100,
                    custom_attributes: {
                        paid_subscriber: true,
                        monthly_spend: 155.5,
                        team_mates: 9,
                    },
                },
            ],
        });
    });

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

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

    test("retrieve (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.companies.retrieve();
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("createOrUpdate (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "my company", company_id: "company_remote_id", remote_created_at: 1374138000 };
        const rawResponseBody = {
            type: "company",
            id: "6762f0761bb69f9f2193bae2",
            name: "my company",
            app_id: "this_is_an_id147_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "company_remote_id",
            remote_created_at: 1374138000,
            created_at: 1734537334,
            updated_at: 1734537334,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: { creation_source: "api" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .post("/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.createOrUpdate({
            name: "my company",
            company_id: "company_remote_id",
            remote_created_at: 1374138000,
        });
        expect(response).toEqual({
            type: "company",
            id: "6762f0761bb69f9f2193bae2",
            name: "my company",
            app_id: "this_is_an_id147_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "company_remote_id",
            remote_created_at: 1374138000,
            created_at: 1734537334,
            updated_at: 1734537334,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: {
                creation_source: "api",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
        });
    });

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

        const rawResponseBody = {
            type: "company",
            id: "6762f0761bb69f9f2193bae2",
            name: "my company",
            app_id: "this_is_an_id147_that_should_be_at_least_",
            plan: { type: "plan", id: "269315", name: "Pro" },
            company_id: "company_remote_id",
            remote_created_at: 1374138000,
            created_at: 1734537334,
            updated_at: 1734537334,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: { creation_source: "api" },
            tags: { type: "tag.list", tags: [{ key: "value" }] },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
        };
        server.mockEndpoint().post("/companies").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.companies.createOrUpdate();
        expect(response).toEqual({
            type: "company",
            id: "6762f0761bb69f9f2193bae2",
            name: "my company",
            app_id: "this_is_an_id147_that_should_be_at_least_",
            plan: {
                type: "plan",
                id: "269315",
                name: "Pro",
            },
            company_id: "company_remote_id",
            remote_created_at: 1374138000,
            created_at: 1734537334,
            updated_at: 1734537334,
            last_request_at: 1663597223,
            size: 100,
            website: "https://www.intercom.com",
            industry: "Software",
            monthly_spend: 0,
            session_count: 0,
            user_count: 0,
            custom_attributes: {
                creation_source: "api",
            },
            tags: {
                type: "tag.list",
                tags: [
                    {
                        key: "value",
                    },
                ],
            },
            segments: {
                type: "segment.list",
                segments: [
                    {
                        id: "56203d253cba154d39010062",
                        name: "Active",
                        created_at: 1394621988,
                        updated_at: 1394622004,
                        count: 3,
                    },
                ],
            },
        });
    });

    test("createOrUpdate (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().post("/companies").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.companies.createOrUpdate(undefined);
        }).rejects.toThrow(Intercom.BadRequestError);
    });

    test("createOrUpdate (4)", 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("/companies").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

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

    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: "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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .get("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.find({
            company_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,
                    },
                ],
            },
        });
    });

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

        await expect(async () => {
            return await client.companies.find({
                company_id: "company_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 = { key: "value" };
        server
            .mockEndpoint()
            .get("/companies/company_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.companies.find({
                company_id: "company_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 = { name: "my company", website: "http://www.mycompany.com/" };
        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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .put("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.update({
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            body: {
                name: "my company",
                website: "http://www.mycompany.com/",
            },
        });
        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,
                    },
                ],
            },
        });
    });

    test("update (2)", 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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .put("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.update({
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
            body: {},
        });
        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,
                    },
                ],
            },
        });
    });

    test("update (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()
            .put("/companies/company_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.companies.update({
                company_id: "company_id",
                body: undefined,
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("update (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()
            .put("/companies/company_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.companies.update({
                company_id: "company_id",
                body: undefined,
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("delete (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.companies.delete({
            company_id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            id: "6762f0881bb69f9f2193bb09",
            object: "company",
            deleted: true,
        });
    });

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

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

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

        await expect(async () => {
            return await client.companies.delete({
                company_id: "company_id",
            });
        }).rejects.toThrow(Intercom.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",
                    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: "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.companies.listAttachedContacts({
            company_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",
                    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: "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: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .get("/companies/company_id/contacts")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.companies.listAttachedContacts({
                company_id: "company_id",
            });
        }).rejects.toThrow(Intercom.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/company_id/contacts")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

    test("listAttachedSegments (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.companies.listAttachedSegments({
            company_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("listAttachedSegments (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("/companies/company_id/segments")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("listAttachedSegments (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/company_id/segments")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const rawResponseBody = {
            type: "list",
            pages: { type: "offset_pages", page: 1, next: "next", 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,
                            },
                        ],
                    },
                },
            ],
        };
        server
            .mockEndpoint({ once: false })
            .post("/companies/list")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            type: "list",
            pages: {
                type: "offset_pages",
                page: 1,
                next: "next",
                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,
                            },
                        ],
                    },
                },
            ],
        };
        const page = await client.companies.list({
            page: 1,
            per_page: 1,
            order: "desc",
        });

        expect(expected.data).toEqual(page.data);
        expect(page.hasNextPage()).toBe(true);
        const nextPage = await page.getNextPage();
        expect(expected.data).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 })
            .post("/companies/list")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("scroll (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,
                            },
                        ],
                    },
                },
            ],
            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({ once: false })
            .get("/companies/scroll")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            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,
                            },
                        ],
                    },
                },
            ],
            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",
        };
        const page = await client.companies.scroll({
            scroll_param: "scroll_param",
        });

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

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

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

    test("attachContact (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { 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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/contact_id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.attachContact({
            contact_id: "contact_id",
            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,
                    },
                ],
            },
        });
    });

    test("attachContact (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { 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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/contact_id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.attachContact({
            contact_id: "contact_id",
            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,
                    },
                ],
            },
        });
    });

    test("attachContact (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { 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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/contact_id/companies")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.attachContact({
            contact_id: "contact_id",
            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,
                    },
                ],
            },
        });
    });

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

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

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

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

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

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

    test("detachContact (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,
                    },
                ],
            },
        };
        server
            .mockEndpoint()
            .delete("/contacts/58a430d35458202d41b1e65b/companies/58a430d35458202d41b1e65b")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.companies.detachContact({
            contact_id: "58a430d35458202d41b1e65b",
            company_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,
                    },
                ],
            },
        });
    });

    test("detachContact (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("/contacts/contact_id/companies/company_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("detachContact (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/company_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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