// 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("CustomChannelEventsClient", () => {
    test("notifyNewConversation (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "evt_12345",
            external_conversation_id: "conv_67890",
            contact: { type: "user", external_id: "user_001", name: "Jane Doe", email: "jane.doe@example.com" },
        };
        const rawResponseBody = {
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.customChannelEvents.notifyNewConversation({
            event_id: "evt_12345",
            external_conversation_id: "conv_67890",
            contact: {
                type: "user",
                external_id: "user_001",
                name: "Jane Doe",
                email: "jane.doe@example.com",
            },
        });
        expect(response).toEqual({
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        });
    });

    test("notifyNewConversation (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("notifyNewConversation (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("notifyNewConversation (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("notifyNewConversation (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnprocessableEntityError);
    });

    test("notifyNewMessage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "evt_54321",
            external_conversation_id: "conv_98765",
            contact: { type: "user", external_id: "user_002", name: "John Smith", email: "john.smith@example.com" },
            body: "Hello, I need help with my order.",
        };
        const rawResponseBody = {
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.customChannelEvents.notifyNewMessage({
            event_id: "evt_54321",
            external_conversation_id: "conv_98765",
            contact: {
                type: "user",
                external_id: "user_002",
                name: "John Smith",
                email: "john.smith@example.com",
            },
            body: "Hello, I need help with my order.",
        });
        expect(response).toEqual({
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        });
    });

    test("notifyNewMessage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("notifyNewMessage (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("notifyNewMessage (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("notifyNewMessage (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnprocessableEntityError);
    });

    test("notifyQuickReplySelected (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "evt_67890",
            external_conversation_id: "conv_13579",
            contact: { type: "user", external_id: "user_003", name: "Alice Example", email: "alice@example.com" },
            quick_reply_option_id: "1234",
        };
        const rawResponseBody = {
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_quick_reply_selected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.customChannelEvents.notifyQuickReplySelected({
            event_id: "evt_67890",
            external_conversation_id: "conv_13579",
            contact: {
                type: "user",
                external_id: "user_003",
                name: "Alice Example",
                email: "alice@example.com",
            },
            quick_reply_option_id: "1234",
        });
        expect(response).toEqual({
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        });
    });

    test("notifyQuickReplySelected (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            quick_reply_option_id: "quick_reply_option_id",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_quick_reply_selected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyQuickReplySelected({
                quick_reply_option_id: "quick_reply_option_id",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("notifyQuickReplySelected (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            quick_reply_option_id: "quick_reply_option_id",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_quick_reply_selected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyQuickReplySelected({
                quick_reply_option_id: "quick_reply_option_id",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("notifyQuickReplySelected (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            quick_reply_option_id: "quick_reply_option_id",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_quick_reply_selected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyQuickReplySelected({
                quick_reply_option_id: "quick_reply_option_id",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("notifyQuickReplySelected (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            quick_reply_option_id: "quick_reply_option_id",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_quick_reply_selected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyQuickReplySelected({
                quick_reply_option_id: "quick_reply_option_id",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnprocessableEntityError);
    });

    test("notifyAttributeCollected (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            event_id: "evt_24680",
            external_conversation_id: "conv_11223",
            contact: { type: "user", external_id: "user_004", name: "Bob Example", email: "bob@example.com" },
            attribute: { id: "shipping_address", value: "123 Main St, Springfield" },
        };
        const rawResponseBody = {
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.customChannelEvents.notifyAttributeCollected({
            event_id: "evt_24680",
            external_conversation_id: "conv_11223",
            contact: {
                type: "user",
                external_id: "user_004",
                name: "Bob Example",
                email: "bob@example.com",
            },
            attribute: {
                id: "shipping_address",
                value: "123 Main St, Springfield",
            },
        });
        expect(response).toEqual({
            external_conversation_id: "customer_conversation_id_12",
            conversation_id: "intercom_conversation_id_34",
            external_contact_id: "customer_contact_id_56",
            contact_id: "intercom_contact_id_79",
        });
    });

    test("notifyAttributeCollected (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            attribute: { id: "id", value: "value" },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyAttributeCollected({
                attribute: {
                    id: "id",
                    value: "value",
                },
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("notifyAttributeCollected (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            attribute: { id: "id", value: "value" },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyAttributeCollected({
                attribute: {
                    id: "id",
                    value: "value",
                },
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("notifyAttributeCollected (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            attribute: { id: "id", value: "value" },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyAttributeCollected({
                attribute: {
                    id: "id",
                    value: "value",
                },
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("notifyAttributeCollected (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            attribute: { id: "id", value: "value" },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.customChannelEvents.notifyAttributeCollected({
                attribute: {
                    id: "id",
                    value: "value",
                },
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.unstable.UnprocessableEntityError);
    });
});
