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

        const rawResponseBody = {
            type: "list",
            companies: [
                {
                    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 },
                },
            ],
            total_count: 1,
            pages: { type: "pages", page: 1, next: "next", per_page: 50, total_pages: 1 },
        };
        server
            .mockEndpoint({ once: false })
            .get("/contacts/63a07ddf05a32042dffac965/companies")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            type: "list",
            companies: [
                {
                    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,
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: "next",
                per_page: 50,
                total_pages: 1,
            },
        };
        const page = await client.contacts.listAttachedCompanies({
            contact_id: "63a07ddf05a32042dffac965",
            page: 1,
            per_page: 1,
        });

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

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

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

    test("listAttachedCompanies (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({ once: false })
            .get("/contacts/contact_id/companies")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.contacts.listAttachedCompanies({
                contact_id: "contact_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: "6762f0b21bb69f9f2193bb65",
                    name: "segment",
                    created_at: 1734537394,
                    updated_at: 1734537394,
                    person_type: "user",
                    count: 3,
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/contacts/63a07ddf05a32042dffac965/segments")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.listAttachedSegments({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "segment",
                    id: "6762f0b21bb69f9f2193bb65",
                    name: "segment",
                    created_at: 1734537394,
                    updated_at: 1734537394,
                    person_type: "user",
                    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("/contacts/contact_id/segments")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.contacts.listAttachedSegments({
                contact_id: "contact_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("/contacts/contact_id/segments")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

    test("listAttachedSubscriptions (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: "subscription",
                    id: "91",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
                    consent_type: "opt_out",
                    content_types: ["email"],
                },
                {
                    type: "subscription",
                    id: "93",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
                    consent_type: "opt_in",
                    content_types: ["sms_message"],
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/contacts/63a07ddf05a32042dffac965/subscriptions")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.listAttachedSubscriptions({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "subscription",
                    id: "91",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [
                        {
                            name: "Newsletters",
                            description: "Lorem ipsum dolor sit amet",
                            locale: "en",
                        },
                    ],
                    consent_type: "opt_out",
                    content_types: ["email"],
                },
                {
                    type: "subscription",
                    id: "93",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [
                        {
                            name: "Newsletters",
                            description: "Lorem ipsum dolor sit amet",
                            locale: "en",
                        },
                    ],
                    consent_type: "opt_in",
                    content_types: ["sms_message"],
                },
            ],
        });
    });

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

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

    test("listAttachedSubscriptions (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("/contacts/contact_id/subscriptions")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

    test("attachSubscription (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "37846", consent_type: "opt_in" };
        const rawResponseBody = {
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: { name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" },
            translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/subscriptions")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.attachSubscription({
            contact_id: "63a07ddf05a32042dffac965",
            id: "37846",
            consent_type: "opt_in",
        });
        expect(response).toEqual({
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: {
                name: "Newsletters",
                description: "Lorem ipsum dolor sit amet",
                locale: "en",
            },
            translations: [
                {
                    name: "Newsletters",
                    description: "Lorem ipsum dolor sit amet",
                    locale: "en",
                },
            ],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        });
    });

    test("attachSubscription (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "37846", consent_type: "opt_in" };
        const rawResponseBody = {
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: { name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" },
            translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/subscriptions")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.attachSubscription({
            contact_id: "63a07ddf05a32042dffac965",
            id: "37846",
            consent_type: "opt_in",
        });
        expect(response).toEqual({
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: {
                name: "Newsletters",
                description: "Lorem ipsum dolor sit amet",
                locale: "en",
            },
            translations: [
                {
                    name: "Newsletters",
                    description: "Lorem ipsum dolor sit amet",
                    locale: "en",
                },
            ],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        });
    });

    test("attachSubscription (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "invalid_id", consent_type: "opt_in" };
        const rawResponseBody = {
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: { name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" },
            translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/subscriptions")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.attachSubscription({
            contact_id: "63a07ddf05a32042dffac965",
            id: "invalid_id",
            consent_type: "opt_in",
        });
        expect(response).toEqual({
            type: "subscription",
            id: "106",
            state: "live",
            default_translation: {
                name: "Newsletters",
                description: "Lorem ipsum dolor sit amet",
                locale: "en",
            },
            translations: [
                {
                    name: "Newsletters",
                    description: "Lorem ipsum dolor sit amet",
                    locale: "en",
                },
            ],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        });
    });

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

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

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

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

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

        const rawResponseBody = {
            type: "subscription",
            id: "122",
            state: "live",
            default_translation: { name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" },
            translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        };
        server
            .mockEndpoint()
            .delete("/contacts/63a07ddf05a32042dffac965/subscriptions/37846")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.detachSubscription({
            contact_id: "63a07ddf05a32042dffac965",
            subscription_id: "37846",
        });
        expect(response).toEqual({
            type: "subscription",
            id: "122",
            state: "live",
            default_translation: {
                name: "Newsletters",
                description: "Lorem ipsum dolor sit amet",
                locale: "en",
            },
            translations: [
                {
                    name: "Newsletters",
                    description: "Lorem ipsum dolor sit amet",
                    locale: "en",
                },
            ],
            consent_type: "opt_in",
            content_types: ["sms_message"],
        });
    });

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

        await expect(async () => {
            return await client.contacts.detachSubscription({
                contact_id: "contact_id",
                subscription_id: "subscription_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        await expect(async () => {
            return await client.contacts.detachSubscription({
                contact_id: "contact_id",
                subscription_id: "subscription_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("listAttachedTags (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: "tag",
                    id: "80",
                    name: "Manual tag",
                    applied_at: 1663597223,
                    applied_by: { type: "contact", id: "1a2b3c" },
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/contacts/63a07ddf05a32042dffac965/tags")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.listAttachedTags({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "tag",
                    id: "80",
                    name: "Manual tag",
                    applied_at: 1663597223,
                    applied_by: {
                        type: "contact",
                        id: "1a2b3c",
                    },
                },
            ],
        });
    });

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

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

    test("listAttachedTags (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("/contacts/contact_id/tags")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const rawResponseBody = {
            type: "contact",
            id: "6762f0d01bb69f9f2193bb7d",
            external_id: "70",
            workspace_id: "this_is_an_id283_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537424,
            updated_at: 1734537424,
            signed_up_at: 1734537424,
            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: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .get("/contacts/63a07ddf05a32042dffac965")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.find({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0d01bb69f9f2193bb7d",
            external_id: "70",
            workspace_id: "this_is_an_id283_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537424,
            updated_at: 1734537424,
            signed_up_at: 1734537424,
            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: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0d01bb69f9f2193bb7d/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

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

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { email: "joebloggs@intercom.io", name: "joe bloggs" };
        const rawResponseBody = {
            type: "contact",
            id: "6762f0cd1bb69f9f2193bb7c",
            external_id: "70",
            workspace_id: "this_is_an_id279_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "joe bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537421,
            updated_at: 1734537422,
            signed_up_at: 1734537421,
            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: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .put("/contacts/63a07ddf05a32042dffac965")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.update({
            contact_id: "63a07ddf05a32042dffac965",
            email: "joebloggs@intercom.io",
            name: "joe bloggs",
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0cd1bb69f9f2193bb7c",
            external_id: "70",
            workspace_id: "this_is_an_id279_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "joe bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537421,
            updated_at: 1734537422,
            signed_up_at: 1734537421,
            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: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

    test("update (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { custom_attributes: { order: ["21"] } };
        const rawResponseBody = {
            type: "contact",
            id: "6762f0cd1bb69f9f2193bb7c",
            external_id: "70",
            workspace_id: "this_is_an_id279_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "joe bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537421,
            updated_at: 1734537422,
            signed_up_at: 1734537421,
            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: {
                order: {
                    type: "Order.list",
                    instances: [
                        {
                            id: "21",
                            external_id: "123",
                            external_created_at: 1392036272,
                            external_updated_at: 1392036272,
                            custom_attributes: { order_number: "ORDER-12345", total_amount: 99.99 },
                            type: "Order",
                        },
                    ],
                },
            },
            avatar: "https://example.org/128Wash.jpg",
            tags: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .put("/contacts/63a07ddf05a32042dffac965")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.update({
            contact_id: "63a07ddf05a32042dffac965",
            custom_attributes: {
                order: ["21"],
            },
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0cd1bb69f9f2193bb7c",
            external_id: "70",
            workspace_id: "this_is_an_id279_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "joe bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537421,
            updated_at: 1734537422,
            signed_up_at: 1734537421,
            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: {
                order: {
                    type: "Order.list",
                    instances: [
                        {
                            id: "21",
                            external_id: "123",
                            external_created_at: 1392036272,
                            external_updated_at: 1392036272,
                            custom_attributes: {
                                order_number: "ORDER-12345",
                                total_amount: 99.99,
                            },
                            type: "Order",
                        },
                    ],
                },
            },
            avatar: "https://example.org/128Wash.jpg",
            tags: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0cd1bb69f9f2193bb7c/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

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

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

        const rawResponseBody = { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70", deleted: true };
        server
            .mockEndpoint()
            .delete("/contacts/contact_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.delete({
            contact_id: "contact_id",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            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("/contacts/contact_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("mergeLeadInUser (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { from: "6762f0d51bb69f9f2193bb7f", into: "6762f0d51bb69f9f2193bb80" };
        const rawResponseBody = {
            type: "contact",
            id: "6762f0d51bb69f9f2193bb80",
            external_id: "70",
            workspace_id: "this_is_an_id291_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537429,
            updated_at: 1734537430,
            signed_up_at: 1734537429,
            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: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0d51bb69f9f2193bb80/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0d51bb69f9f2193bb80/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0d51bb69f9f2193bb80/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .post("/contacts/merge")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.mergeLeadInUser({
            from: "6762f0d51bb69f9f2193bb7f",
            into: "6762f0d51bb69f9f2193bb80",
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0d51bb69f9f2193bb80",
            external_id: "70",
            workspace_id: "this_is_an_id291_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537429,
            updated_at: 1734537430,
            signed_up_at: 1734537429,
            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: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0d51bb69f9f2193bb80/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0d51bb69f9f2193bb80/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0d51bb69f9f2193bb80/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

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

    test("search (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            query: { operator: "AND", value: [{ field: "created_at", operator: ">", value: "1306054154" }] },
            pagination: { per_page: 5 },
        };
        const rawResponseBody = {
            type: "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: 5,
                total_pages: 0,
            },
        };
        server
            .mockEndpoint({ once: false })
            .post("/contacts/search")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            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: 5,
                total_pages: 0,
            },
        };
        const page = await client.contacts.search({
            query: {
                operator: "AND",
                value: [
                    {
                        field: "created_at",
                        operator: ">",
                        value: "1306054154",
                    },
                ],
            },
            pagination: {
                per_page: 5,
            },
        });

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

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

        await expect(async () => {
            return await client.contacts.search({
                query: {},
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "contact",
                    id: "id",
                    external_id: "external_id",
                    workspace_id: "workspace_id",
                    role: "role",
                    email: "email",
                    email_domain: "email_domain",
                    phone: "phone",
                    name: "name",
                    owner_id: 1,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1,
                    updated_at: 1,
                    signed_up_at: 1,
                    last_seen_at: 1,
                    last_replied_at: 1,
                    last_contacted_at: 1,
                    last_email_opened_at: 1,
                    last_email_clicked_at: 1,
                    language_override: "language_override",
                    browser: "browser",
                    browser_version: "browser_version",
                    browser_language: "browser_language",
                    os: "os",
                    android_app_name: "android_app_name",
                    android_app_version: "android_app_version",
                    android_device: "android_device",
                    android_os_version: "android_os_version",
                    android_sdk_version: "android_sdk_version",
                    android_last_seen_at: 1,
                    ios_app_name: "ios_app_name",
                    ios_app_version: "ios_app_version",
                    ios_device: "ios_device",
                    ios_os_version: "ios_os_version",
                    ios_sdk_version: "ios_sdk_version",
                    ios_last_seen_at: 1,
                    custom_attributes: { custom_attributes: { key: "value" } },
                    avatar: "avatar",
                    tags: {
                        data: [
                            { type: "type", id: "id", url: "url" },
                            { type: "type", id: "id", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    notes: {
                        data: [
                            { type: "type", id: "id", url: "url" },
                            { type: "type", id: "id", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    companies: {
                        data: [
                            { id: "id", type: "company", url: "url" },
                            { id: "id", type: "company", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    location: { type: "type", country: "country", region: "region", city: "city" },
                    social_profiles: {
                        data: [
                            { type: "social_profile", name: "name", url: "url" },
                            { type: "social_profile", name: "name", url: "url" },
                        ],
                    },
                },
                {
                    type: "contact",
                    id: "id",
                    external_id: "external_id",
                    workspace_id: "workspace_id",
                    role: "role",
                    email: "email",
                    email_domain: "email_domain",
                    phone: "phone",
                    name: "name",
                    owner_id: 1,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1,
                    updated_at: 1,
                    signed_up_at: 1,
                    last_seen_at: 1,
                    last_replied_at: 1,
                    last_contacted_at: 1,
                    last_email_opened_at: 1,
                    last_email_clicked_at: 1,
                    language_override: "language_override",
                    browser: "browser",
                    browser_version: "browser_version",
                    browser_language: "browser_language",
                    os: "os",
                    android_app_name: "android_app_name",
                    android_app_version: "android_app_version",
                    android_device: "android_device",
                    android_os_version: "android_os_version",
                    android_sdk_version: "android_sdk_version",
                    android_last_seen_at: 1,
                    ios_app_name: "ios_app_name",
                    ios_app_version: "ios_app_version",
                    ios_device: "ios_device",
                    ios_os_version: "ios_os_version",
                    ios_sdk_version: "ios_sdk_version",
                    ios_last_seen_at: 1,
                    custom_attributes: { custom_attributes: { key: "value" } },
                    avatar: "avatar",
                    tags: {
                        data: [
                            { type: "type", id: "id", url: "url" },
                            { type: "type", id: "id", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    notes: {
                        data: [
                            { type: "type", id: "id", url: "url" },
                            { type: "type", id: "id", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    companies: {
                        data: [
                            { id: "id", type: "company", url: "url" },
                            { id: "id", type: "company", url: "url" },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    location: { type: "type", country: "country", region: "region", city: "city" },
                    social_profiles: {
                        data: [
                            { type: "social_profile", name: "name", url: "url" },
                            { type: "social_profile", name: "name", url: "url" },
                        ],
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 1, starting_after: "starting_after" },
                per_page: 1,
                total_pages: 1,
            },
        };
        server
            .mockEndpoint({ once: false })
            .get("/contacts")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const expected = {
            type: "list",
            data: [
                {
                    type: "contact",
                    id: "id",
                    external_id: "external_id",
                    workspace_id: "workspace_id",
                    role: "role",
                    email: "email",
                    email_domain: "email_domain",
                    phone: "phone",
                    name: "name",
                    owner_id: 1,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1,
                    updated_at: 1,
                    signed_up_at: 1,
                    last_seen_at: 1,
                    last_replied_at: 1,
                    last_contacted_at: 1,
                    last_email_opened_at: 1,
                    last_email_clicked_at: 1,
                    language_override: "language_override",
                    browser: "browser",
                    browser_version: "browser_version",
                    browser_language: "browser_language",
                    os: "os",
                    android_app_name: "android_app_name",
                    android_app_version: "android_app_version",
                    android_device: "android_device",
                    android_os_version: "android_os_version",
                    android_sdk_version: "android_sdk_version",
                    android_last_seen_at: 1,
                    ios_app_name: "ios_app_name",
                    ios_app_version: "ios_app_version",
                    ios_device: "ios_device",
                    ios_os_version: "ios_os_version",
                    ios_sdk_version: "ios_sdk_version",
                    ios_last_seen_at: 1,
                    custom_attributes: {
                        custom_attributes: {
                            key: "value",
                        },
                    },
                    avatar: "avatar",
                    tags: {
                        data: [
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    notes: {
                        data: [
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    companies: {
                        data: [
                            {
                                id: "id",
                                type: "company",
                                url: "url",
                            },
                            {
                                id: "id",
                                type: "company",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    location: {
                        type: "type",
                        country: "country",
                        region: "region",
                        city: "city",
                    },
                    social_profiles: {
                        data: [
                            {
                                type: "social_profile",
                                name: "name",
                                url: "url",
                            },
                            {
                                type: "social_profile",
                                name: "name",
                                url: "url",
                            },
                        ],
                    },
                },
                {
                    type: "contact",
                    id: "id",
                    external_id: "external_id",
                    workspace_id: "workspace_id",
                    role: "role",
                    email: "email",
                    email_domain: "email_domain",
                    phone: "phone",
                    name: "name",
                    owner_id: 1,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1,
                    updated_at: 1,
                    signed_up_at: 1,
                    last_seen_at: 1,
                    last_replied_at: 1,
                    last_contacted_at: 1,
                    last_email_opened_at: 1,
                    last_email_clicked_at: 1,
                    language_override: "language_override",
                    browser: "browser",
                    browser_version: "browser_version",
                    browser_language: "browser_language",
                    os: "os",
                    android_app_name: "android_app_name",
                    android_app_version: "android_app_version",
                    android_device: "android_device",
                    android_os_version: "android_os_version",
                    android_sdk_version: "android_sdk_version",
                    android_last_seen_at: 1,
                    ios_app_name: "ios_app_name",
                    ios_app_version: "ios_app_version",
                    ios_device: "ios_device",
                    ios_os_version: "ios_os_version",
                    ios_sdk_version: "ios_sdk_version",
                    ios_last_seen_at: 1,
                    custom_attributes: {
                        custom_attributes: {
                            key: "value",
                        },
                    },
                    avatar: "avatar",
                    tags: {
                        data: [
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    notes: {
                        data: [
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                            {
                                type: "type",
                                id: "id",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    companies: {
                        data: [
                            {
                                id: "id",
                                type: "company",
                                url: "url",
                            },
                            {
                                id: "id",
                                type: "company",
                                url: "url",
                            },
                        ],
                        url: "url",
                        total_count: 1,
                        has_more: true,
                    },
                    location: {
                        type: "type",
                        country: "country",
                        region: "region",
                        city: "city",
                    },
                    social_profiles: {
                        data: [
                            {
                                type: "social_profile",
                                name: "name",
                                url: "url",
                            },
                            {
                                type: "social_profile",
                                name: "name",
                                url: "url",
                            },
                        ],
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 1,
                    starting_after: "starting_after",
                },
                per_page: 1,
                total_pages: 1,
            },
        };
        const page = await client.contacts.list();

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

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

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { email: "joebloggs@intercom.io" };
        const rawResponseBody = {
            type: "contact",
            id: "6762f0dd1bb69f9f2193bb83",
            external_id: "f3b87a2e09d514c6c2e79b9a",
            workspace_id: "this_is_an_id303_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "John Doe",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537437,
            updated_at: 1734537437,
            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: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .post("/contacts")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.create({
            email: "joebloggs@intercom.io",
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0dd1bb69f9f2193bb83",
            external_id: "f3b87a2e09d514c6c2e79b9a",
            workspace_id: "this_is_an_id303_that_should_be_at_least_",
            role: "user",
            email: "joebloggs@intercom.io",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "John Doe",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537437,
            updated_at: 1734537437,
            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: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0dd1bb69f9f2193bb83/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

        await expect(async () => {
            return await client.contacts.create({
                email: "email",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "contact",
            id: "6762f0df1bb69f9f2193bb84",
            external_id: "70",
            workspace_id: "this_is_an_id307_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537439,
            updated_at: 1734537439,
            signed_up_at: 1734537439,
            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: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0df1bb69f9f2193bb84/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [{ type: "note", id: "123", url: "/contacts/5ba682d23d7cf92bef87bfd4/notes" }],
                url: "/contacts/6762f0df1bb69f9f2193bb84/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [{ id: "5ba682d23d7cf92bef87bfd4", url: "/companies/5ba682d23d7cf92bef87bfd4" }],
                url: "/contacts/6762f0df1bb69f9f2193bb84/companies",
                total_count: 0,
                has_more: false,
            },
            location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
            social_profiles: { data: [{ name: "Facebook", url: "http://twitter.com/th1sland" }] },
            enabled_push_messaging: true,
        };
        server
            .mockEndpoint()
            .get("/contacts/find_by_external_id/cdd29344-5e0c-4ef0-ac56-f9ba2979bc27")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.showContactByExternalId({
            external_id: "cdd29344-5e0c-4ef0-ac56-f9ba2979bc27",
        });
        expect(response).toEqual({
            type: "contact",
            id: "6762f0df1bb69f9f2193bb84",
            external_id: "70",
            workspace_id: "this_is_an_id307_that_should_be_at_least_",
            role: "user",
            email: "joe@bloggs.com",
            email_domain: "example.com",
            phone: "+1123456789",
            name: "Joe Bloggs",
            owner_id: 123,
            has_hard_bounced: false,
            marked_email_as_spam: false,
            unsubscribed_from_emails: false,
            created_at: 1734537439,
            updated_at: 1734537439,
            signed_up_at: 1734537439,
            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: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0df1bb69f9f2193bb84/tags",
                total_count: 0,
                has_more: false,
            },
            notes: {
                data: [
                    {
                        type: "note",
                        id: "123",
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/notes",
                    },
                ],
                url: "/contacts/6762f0df1bb69f9f2193bb84/notes",
                total_count: 0,
                has_more: false,
            },
            companies: {
                data: [
                    {
                        id: "5ba682d23d7cf92bef87bfd4",
                        url: "/companies/5ba682d23d7cf92bef87bfd4",
                    },
                ],
                url: "/contacts/6762f0df1bb69f9f2193bb84/companies",
                total_count: 0,
                has_more: false,
            },
            location: {
                type: "location",
                country: "Ireland",
                region: "Dublin",
                city: "Dublin",
            },
            social_profiles: {
                data: [
                    {
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

    test("ShowContactByExternalId (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("/contacts/find_by_external_id/external_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.contacts.showContactByExternalId({
                external_id: "external_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70", archived: true };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/archive")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.archive({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            archived: true,
        });
    });

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

        const rawResponseBody = { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70", archived: false };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/unarchive")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.unarchive({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            archived: false,
        });
    });

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

        const rawResponseBody = { type: "contact", id: "5ba682d23d7cf92bef87bfd4", external_id: "70", blocked: true };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/block")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.contacts.blockContact({
            contact_id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            blocked: true,
        });
    });
});
