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

        const response = await client.unstable.contacts.listCompaniesForAContact({
            id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            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: "custom_attributes",
                        monthly_spend: "custom_attributes",
                        team_mates: "custom_attributes",
                    },
                },
            ],
            total_count: 1,
            pages: {
                type: "pages",
                page: 1,
                next: "next",
                per_page: 50,
                total_pages: 1,
            },
        });
    });

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

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

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

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

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

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

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

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

    test("listSegmentsForAContact (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.unstable.contacts.listSegmentsForAContact({
                contact_id: "contact_id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

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

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

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

    test("listSubscriptionsForAContact (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.unstable.contacts.listSubscriptionsForAContact({
                contact_id: "contact_id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

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

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

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

    test("listTagsForAContact (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.unstable.contacts.listTagsForAContact({
                contact_id: "contact_id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("ShowContact (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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.contacts.showContact({
            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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

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

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

    test("UpdateContact (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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.contacts.updateContact({
            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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

    test("UpdateContact (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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.contacts.updateContact({
            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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

    test("UpdateContact (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/contacts/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

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

        const response = await client.unstable.contacts.deleteContact({
            id: "id",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            deleted: true,
        });
    });

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

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

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

    test("MergeContact (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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.contacts.mergeContact({
            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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

    test("MergeContact (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/contacts/merge")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("SearchContacts (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",
                    formatted_phone: "+1123456789",
                    name: "John Doe",
                    owner_id: 123,
                    has_hard_bounced: true,
                    marked_email_as_spam: true,
                    unsubscribed_from_emails: true,
                    created_at: 1571672154,
                    updated_at: 1571672154,
                    signed_up_at: 1571672154,
                    last_seen_at: 1571672154,
                    last_replied_at: 1571672154,
                    last_contacted_at: 1571672154,
                    last_email_opened_at: 1571672154,
                    last_email_clicked_at: 1571672154,
                    language_override: "en",
                    browser: "Chrome",
                    browser_version: "80.0.3987.132",
                    browser_language: "en-US",
                    os: "Mac OS X",
                    android_app_name: "Intercom",
                    android_app_version: "5.0.0",
                    android_device: "Pixel 3",
                    android_os_version: "10",
                    android_sdk_version: "28",
                    android_last_seen_at: 1571672154,
                    ios_app_name: "Intercom",
                    ios_app_version: "5.0.0",
                    ios_device: "iPhone 11",
                    ios_os_version: "13.3.1",
                    ios_sdk_version: "13.3.1",
                    ios_last_seen_at: 1571672154,
                    custom_attributes: { key: "value" },
                    avatar: { type: "avatar", image_url: "https://example.org/128Wash.jpg" },
                    tags: { url: "/contacts/5ba682d23d7cf92bef87bfd4/tags", total_count: 100, has_more: true },
                    notes: { url: "/contacts/5ba682d23d7cf92bef87bfd4/notes", total_count: 100, has_more: true },
                    companies: {
                        url: "/contacts/5ba682d23d7cf92bef87bfd4/companies",
                        total_count: 100,
                        has_more: true,
                    },
                    location: { type: "location", country: "Ireland", region: "Dublin", city: "Dublin" },
                },
            ],
            total_count: 0,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 5,
                total_pages: 0,
            },
        };
        server
            .mockEndpoint()
            .post("/contacts/search")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

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

    test("SearchContacts (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/contacts/search")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

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

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

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

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

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

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

    test("CreateContact (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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.contacts.createContact({
            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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        name: "Facebook",
                        url: "http://twitter.com/th1sland",
                    },
                ],
            },
            enabled_push_messaging: true,
        });
    });

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

        await expect(async () => {
            return await client.unstable.contacts.createContact({
                key: "value",
            });
        }).rejects.toThrow(Intercom.unstable.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",
            formatted_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: { type: "avatar", image_url: "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: [{ type: "social_profile", 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.unstable.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",
            formatted_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: {
                type: "avatar",
                image_url: "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: [
                    {
                        type: "social_profile",
                        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: "type", 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.unstable.contacts.showContactByExternalId({
                external_id: "external_id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("ArchiveContact", 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.unstable.contacts.archiveContact({
            id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            archived: true,
        });
    });

    test("UnarchiveContact", 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.unstable.contacts.unarchiveContact({
            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.unstable.contacts.blockContact({
            id: "63a07ddf05a32042dffac965",
        });
        expect(response).toEqual({
            type: "contact",
            id: "5ba682d23d7cf92bef87bfd4",
            external_id: "70",
            blocked: true,
        });
    });
});
