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

        const rawResponseBody = {
            id: "24",
            external_id: "123",
            external_created_at: 1571672154,
            external_updated_at: 1571672154,
            created_at: 1734537748,
            updated_at: 1734537748,
            type: "Order",
            custom_attributes: { order_number: "ORDER-12345", total_amount: "custom_attributes" },
        };
        server
            .mockEndpoint()
            .get("/custom_object_instances/Order")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customObjectInstances.getCustomObjectInstancesByExternalId({
            custom_object_type_identifier: "Order",
            external_id: "external_id",
        });
        expect(response).toEqual({
            id: "24",
            external_id: "123",
            external_created_at: 1571672154,
            external_updated_at: 1571672154,
            created_at: 1734537748,
            updated_at: 1734537748,
            type: "Order",
            custom_attributes: {
                order_number: "ORDER-12345",
                total_amount: "custom_attributes",
            },
        });
    });

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

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

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

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

        await expect(async () => {
            return await client.customObjectInstances.getCustomObjectInstancesByExternalId({
                custom_object_type_identifier: "custom_object_type_identifier",
                external_id: "external_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("createCustomObjectInstances (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            external_id: "123",
            external_created_at: 1392036272,
            external_updated_at: 1392036272,
            custom_attributes: { order_number: "ORDER-12345", total_amount: "custom_attributes" },
        };
        const rawResponseBody = {
            id: "22",
            external_id: "123",
            external_created_at: 1392036272,
            external_updated_at: 1392036272,
            created_at: 1734537745,
            updated_at: 1734537745,
            type: "Order",
            custom_attributes: { order_number: "ORDER-12345", total_amount: "custom_attributes" },
        };
        server
            .mockEndpoint()
            .post("/custom_object_instances/Order")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customObjectInstances.createCustomObjectInstances({
            custom_object_type_identifier: "Order",
            external_id: "123",
            external_created_at: 1392036272,
            external_updated_at: 1392036272,
            custom_attributes: {
                order_number: "ORDER-12345",
                total_amount: "custom_attributes",
            },
        });
        expect(response).toEqual({
            id: "22",
            external_id: "123",
            external_created_at: 1392036272,
            external_updated_at: 1392036272,
            created_at: 1734537745,
            updated_at: 1734537745,
            type: "Order",
            custom_attributes: {
                order_number: "ORDER-12345",
                total_amount: "custom_attributes",
            },
        });
    });

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

        await expect(async () => {
            return await client.customObjectInstances.createCustomObjectInstances({
                custom_object_type_identifier: "custom_object_type_identifier",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("createCustomObjectInstances (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/custom_object_instances/custom_object_type_identifier")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.customObjectInstances.createCustomObjectInstances({
                custom_object_type_identifier: "custom_object_type_identifier",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = { object: "Order", id: "26", deleted: true };
        server
            .mockEndpoint()
            .delete("/custom_object_instances/Order")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customObjectInstances.deleteCustomObjectInstancesById({
            custom_object_type_identifier: "Order",
            external_id: "external_id",
        });
        expect(response).toEqual({
            object: "Order",
            id: "26",
            deleted: true,
        });
    });

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

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

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

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/custom_object_instances/custom_object_type_identifier")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.customObjectInstances.deleteCustomObjectInstancesById({
                custom_object_type_identifier: "custom_object_type_identifier",
                external_id: "external_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = {
            id: "25",
            external_id: "123",
            external_created_at: 1571672154,
            external_updated_at: 1571672154,
            created_at: 1734537750,
            updated_at: 1734537750,
            type: "Order",
            custom_attributes: { order_number: "ORDER-12345", total_amount: "custom_attributes" },
        };
        server
            .mockEndpoint()
            .get("/custom_object_instances/Order/custom_object_instance_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customObjectInstances.getCustomObjectInstancesById({
            custom_object_type_identifier: "Order",
            custom_object_instance_id: "custom_object_instance_id",
        });
        expect(response).toEqual({
            id: "25",
            external_id: "123",
            external_created_at: 1571672154,
            external_updated_at: 1571672154,
            created_at: 1734537750,
            updated_at: 1734537750,
            type: "Order",
            custom_attributes: {
                order_number: "ORDER-12345",
                total_amount: "custom_attributes",
            },
        });
    });

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

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

        await expect(async () => {
            return await client.customObjectInstances.getCustomObjectInstancesById({
                custom_object_type_identifier: "custom_object_type_identifier",
                custom_object_instance_id: "custom_object_instance_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("getCustomObjectInstancesById (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("/custom_object_instances/custom_object_type_identifier/custom_object_instance_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.customObjectInstances.getCustomObjectInstancesById({
                custom_object_type_identifier: "custom_object_type_identifier",
                custom_object_instance_id: "custom_object_instance_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = { object: "Order", id: "26", deleted: true };
        server
            .mockEndpoint()
            .delete("/custom_object_instances/Order/custom_object_instance_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.customObjectInstances.deleteCustomObjectInstancesByExternalId({
            custom_object_type_identifier: "Order",
            custom_object_instance_id: "custom_object_instance_id",
        });
        expect(response).toEqual({
            object: "Order",
            id: "26",
            deleted: true,
        });
    });

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

        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/custom_object_instances/custom_object_type_identifier/custom_object_instance_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.customObjectInstances.deleteCustomObjectInstancesByExternalId({
                custom_object_type_identifier: "custom_object_type_identifier",
                custom_object_instance_id: "custom_object_instance_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/custom_object_instances/custom_object_type_identifier/custom_object_instance_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.customObjectInstances.deleteCustomObjectInstancesByExternalId({
                custom_object_type_identifier: "custom_object_type_identifier",
                custom_object_instance_id: "custom_object_instance_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });
});
