// This file was auto-generated by Fern from our API Definition.

import * as Cohere from "../../src/api/index";
import { CohereClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("Connectors", () => {
    test("list (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            connectors: [
                {
                    id: "id",
                    organization_id: "organization_id",
                    name: "name",
                    description: "description",
                    url: "url",
                    created_at: "2024-01-15T09:30:00Z",
                    updated_at: "2024-01-15T09:30:00Z",
                    excludes: ["excludes"],
                    auth_type: "auth_type",
                    oauth: { authorize_url: "authorize_url", token_url: "token_url" },
                    auth_status: "valid",
                    active: true,
                    continue_on_failure: true,
                },
            ],
            total_count: 1.1,
        };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.connectors.list({
            limit: 1.1,
            offset: 1.1,
        });
        expect(response).toEqual({
            connectors: [
                {
                    id: "id",
                    organizationId: "organization_id",
                    name: "name",
                    description: "description",
                    url: "url",
                    createdAt: new Date("2024-01-15T09:30:00.000Z"),
                    updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                    excludes: ["excludes"],
                    authType: "auth_type",
                    oauth: {
                        authorizeUrl: "authorize_url",
                        tokenUrl: "token_url",
                    },
                    authStatus: "valid",
                    active: true,
                    continueOnFailure: true,
                },
            ],
            totalCount: 1.1,
        });
    });

    test("list (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("list (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

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

    test("list (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(403).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("list (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("list (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(422).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("list (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(429).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("list (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(498).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("list (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(499).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("list (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(500).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("list (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(501).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("list (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(503).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("list (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors").respondWith().statusCode(504).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.list();
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = {
            connector: {
                id: "id",
                organization_id: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                excludes: ["excludes"],
                auth_type: "auth_type",
                oauth: {
                    client_id: "client_id",
                    client_secret: "client_secret",
                    authorize_url: "authorize_url",
                    token_url: "token_url",
                    scope: "scope",
                },
                auth_status: "valid",
                active: true,
                continue_on_failure: true,
            },
        };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.connectors.create({
            name: "name",
            url: "url",
        });
        expect(response).toEqual({
            connector: {
                id: "id",
                organizationId: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                excludes: ["excludes"],
                authType: "auth_type",
                oauth: {
                    clientId: "client_id",
                    clientSecret: "client_secret",
                    authorizeUrl: "authorize_url",
                    tokenUrl: "token_url",
                    scope: "scope",
                },
                authStatus: "valid",
                active: true,
                continueOnFailure: true,
            },
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("create (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("create (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(429)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("create (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(498)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("create (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(499)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("create (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("create (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(501)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("create (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("create (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", url: "url" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(504)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.create({
                name: "name",
                url: "url",
            });
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

    test("get (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            connector: {
                id: "id",
                organization_id: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                excludes: ["excludes"],
                auth_type: "auth_type",
                oauth: {
                    client_id: "client_id",
                    client_secret: "client_secret",
                    authorize_url: "authorize_url",
                    token_url: "token_url",
                    scope: "scope",
                },
                auth_status: "valid",
                active: true,
                continue_on_failure: true,
            },
        };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.connectors.get("id");
        expect(response).toEqual({
            connector: {
                id: "id",
                organizationId: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                excludes: ["excludes"],
                authType: "auth_type",
                oauth: {
                    clientId: "client_id",
                    clientSecret: "client_secret",
                    authorizeUrl: "authorize_url",
                    tokenUrl: "token_url",
                    scope: "scope",
                },
                authStatus: "valid",
                active: true,
                continueOnFailure: true,
            },
        });
    });

    test("get (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("get (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("get (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(403).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("get (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("get (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(422).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("get (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(429).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("get (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(498).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("get (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(499).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("get (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(500).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("get (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(501).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("get (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(503).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("get (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/connectors/id").respondWith().statusCode(504).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.connectors.get("id");
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

    test("delete (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.connectors.delete("id");
        expect(response).toEqual({
            key: "value",
        });
    });

    test("delete (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("delete (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("delete (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("delete (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

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

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("delete (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("delete (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(429)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("delete (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(498)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("delete (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(499)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("delete (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("delete (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(501)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("delete (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("delete (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/connectors/id")
            .respondWith()
            .statusCode(504)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.delete("id");
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = {
            connector: {
                id: "id",
                organization_id: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                excludes: ["excludes"],
                auth_type: "auth_type",
                oauth: {
                    client_id: "client_id",
                    client_secret: "client_secret",
                    authorize_url: "authorize_url",
                    token_url: "token_url",
                    scope: "scope",
                },
                auth_status: "valid",
                active: true,
                continue_on_failure: true,
            },
        };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.connectors.update("id");
        expect(response).toEqual({
            connector: {
                id: "id",
                organizationId: "organization_id",
                name: "name",
                description: "description",
                url: "url",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                excludes: ["excludes"],
                authType: "auth_type",
                oauth: {
                    clientId: "client_id",
                    clientSecret: "client_secret",
                    authorizeUrl: "authorize_url",
                    tokenUrl: "token_url",
                    scope: "scope",
                },
                authStatus: "valid",
                active: true,
                continueOnFailure: true,
            },
        });
    });

    test("update (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("update (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("update (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("update (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("update (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("update (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(429)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("update (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(498)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("update (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(499)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("update (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("update (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(501)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("update (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("update (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/connectors/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(504)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.update("id");
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

    test("oAuthAuthorize (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { redirect_url: "redirect_url" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.connectors.oAuthAuthorize("id", {
            afterTokenRedirect: "after_token_redirect",
        });
        expect(response).toEqual({
            redirectUrl: "redirect_url",
        });
    });

    test("oAuthAuthorize (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("oAuthAuthorize (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("oAuthAuthorize (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("oAuthAuthorize (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("oAuthAuthorize (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

    test("oAuthAuthorize (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(429)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

    test("oAuthAuthorize (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(498)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

    test("oAuthAuthorize (9)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(499)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

    test("oAuthAuthorize (10)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("oAuthAuthorize (11)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(501)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

    test("oAuthAuthorize (12)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("oAuthAuthorize (13)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/connectors/id/oauth/authorize")
            .respondWith()
            .statusCode(504)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.connectors.oAuthAuthorize("id");
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });
});
