// 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: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = {
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_conversation")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customChannelEvents.notifyNewConversation({
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: {
                type: "user",
                external_id: "external_id",
            },
        });
        expect(response).toEqual({
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        });
    });

    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.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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: "error.list", 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.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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.customChannelEvents.notifyNewConversation({
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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 = {
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = {
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_new_message")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customChannelEvents.notifyNewMessage({
            body: "body",
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: {
                type: "user",
                external_id: "external_id",
            },
        });
        expect(response).toEqual({
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        });
    });

    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.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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: "error.list", 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.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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.customChannelEvents.notifyNewMessage({
                body: "body",
                event_id: "event_id",
                external_conversation_id: "external_conversation_id",
                contact: {
                    type: "user",
                    external_id: "external_id",
                },
            });
        }).rejects.toThrow(Intercom.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.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.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.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: "error.list", 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.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.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.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.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.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.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 = {
            attribute: { id: "id", value: "value" },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: { type: "user", external_id: "external_id" },
        };
        const rawResponseBody = {
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        };
        server
            .mockEndpoint()
            .post("/custom_channel_events/notify_attribute_collected")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customChannelEvents.notifyAttributeCollected({
            attribute: {
                id: "id",
                value: "value",
            },
            event_id: "event_id",
            external_conversation_id: "external_conversation_id",
            contact: {
                type: "user",
                external_id: "external_id",
            },
        });
        expect(response).toEqual({
            external_conversation_id: "external_conversation_id",
            conversation_id: "conversation_id",
            external_contact_id: "external_contact_id",
            contact_id: "contact_id",
        });
    });

    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.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.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: "error.list", 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.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.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.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.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.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.UnprocessableEntityError);
    });
});
