// 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("TagsClient", () => {
    test("tagContact (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907" };
        const rawResponseBody = {
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagContact({
            contact_id: "63a07ddf05a32042dffac965",
            id: "7522907",
        });
        expect(response).toEqual({
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("tagContact (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907" };
        const rawResponseBody = {
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagContact({
            contact_id: "63a07ddf05a32042dffac965",
            id: "7522907",
        });
        expect(response).toEqual({
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("tagContact (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/contacts/63a07ddf05a32042dffac965/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagContact({
            contact_id: "63a07ddf05a32042dffac965",
            id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "81",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

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

        await expect(async () => {
            return await client.tags.tagContact({
                contact_id: "contact_id",
                id: "id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("tagContact (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/contacts/contact_id/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.tagContact({
                contact_id: "contact_id",
                id: "id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = {
            type: "tag",
            id: "84",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/contacts/63a07ddf05a32042dffac965/tags/7522907")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagContact({
            contact_id: "63a07ddf05a32042dffac965",
            tag_id: "7522907",
        });
        expect(response).toEqual({
            type: "tag",
            id: "84",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagContact (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("/contacts/contact_id/tags/tag_id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagContact({
                contact_id: "contact_id",
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("untagContact (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("/contacts/contact_id/tags/tag_id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagContact({
                contact_id: "contact_id",
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("tagConversation (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907", admin_id: "780" };
        const rawResponseBody = {
            type: "tag",
            id: "86",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/conversations/64619700005694/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagConversation({
            conversation_id: "64619700005694",
            id: "7522907",
            admin_id: "780",
        });
        expect(response).toEqual({
            type: "tag",
            id: "86",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("tagConversation (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907", admin_id: "780" };
        const rawResponseBody = {
            type: "tag",
            id: "86",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/conversations/64619700005694/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagConversation({
            conversation_id: "64619700005694",
            id: "7522907",
            admin_id: "780",
        });
        expect(response).toEqual({
            type: "tag",
            id: "86",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

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

        await expect(async () => {
            return await client.tags.tagConversation({
                conversation_id: "conversation_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("tagConversation (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "id", admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/conversations/conversation_id/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.tagConversation({
                conversation_id: "conversation_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("untagConversation (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/conversations/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagConversation({
            conversation_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagConversation (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/conversations/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagConversation({
            conversation_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagConversation (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/conversations/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagConversation({
            conversation_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "89",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagConversation (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/tags/tag_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagConversation({
                conversation_id: "conversation_id",
                tag_id: "tag_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("untagConversation (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/tags/tag_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagConversation({
                conversation_id: "conversation_id",
                tag_id: "tag_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "tag",
                    id: "102",
                    name: "Manual tag 1",
                    applied_at: 1663597223,
                    applied_by: { type: "contact", id: "1a2b3c" },
                },
            ],
        };
        server.mockEndpoint().get("/tags").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.tags.list();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "tag",
                    id: "102",
                    name: "Manual tag 1",
                    applied_at: 1663597223,
                    applied_by: {
                        type: "contact",
                        id: "1a2b3c",
                    },
                },
            ],
        });
    });

    test("list (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("/tags").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

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

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "test" };
        const rawResponseBody = {
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.create({
            name: "test",
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "Independent" };
        const rawResponseBody = {
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.create({
            name: "Independent",
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "test", companies: [{ company_id: "123" }] };
        const rawResponseBody = {
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.create({
            name: "test",
            companies: [
                {
                    company_id: "123",
                },
            ],
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "test", users: [{ id: "123" }] };
        const rawResponseBody = {
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.create({
            name: "test",
            users: [
                {
                    id: "123",
                },
            ],
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { name: "name" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

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

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

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

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

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

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

        const rawResponseBody = {
            type: "tag",
            id: "113",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server.mockEndpoint().get("/tags/123").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.tags.find({
            tag_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "113",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("find (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("/tags/tag_id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.tags.find({
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("find (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("/tags/tag_id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.tags.find({
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

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

        server.mockEndpoint().delete("/tags/123").respondWith().statusCode(200).build();

        const response = await client.tags.delete({
            tag_id: "123",
        });
        expect(response).toEqual(undefined);
    });

    test("delete (2)", 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("/tags/tag_id").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.tags.delete({
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.BadRequestError);
    });

    test("delete (3)", 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("/tags/tag_id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.tags.delete({
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("delete (4)", 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("/tags/tag_id").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.tags.delete({
                tag_id: "tag_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("tagTicket (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907", admin_id: "780" };
        const rawResponseBody = {
            type: "tag",
            id: "121",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tickets/64619700005694/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagTicket({
            ticket_id: "64619700005694",
            id: "7522907",
            admin_id: "780",
        });
        expect(response).toEqual({
            type: "tag",
            id: "121",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("tagTicket (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "7522907", admin_id: "780" };
        const rawResponseBody = {
            type: "tag",
            id: "121",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .post("/tickets/64619700005694/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.tagTicket({
            ticket_id: "64619700005694",
            id: "7522907",
            admin_id: "780",
        });
        expect(response).toEqual({
            type: "tag",
            id: "121",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

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

        await expect(async () => {
            return await client.tags.tagTicket({
                ticket_id: "ticket_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("tagTicket (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { id: "id", admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/tickets/ticket_id/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.tagTicket({
                ticket_id: "ticket_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("untagTicket (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/tickets/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagTicket({
            ticket_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagTicket (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/tickets/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagTicket({
            ticket_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagTicket (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "123" };
        const rawResponseBody = {
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: { type: "contact", id: "1a2b3c" },
        };
        server
            .mockEndpoint()
            .delete("/tickets/64619700005694/tags/7522907")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tags.untagTicket({
            ticket_id: "64619700005694",
            tag_id: "7522907",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "124",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("untagTicket (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/tickets/ticket_id/tags/tag_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagTicket({
                ticket_id: "ticket_id",
                tag_id: "tag_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("untagTicket (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { admin_id: "admin_id" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/tickets/ticket_id/tags/tag_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.tags.untagTicket({
                ticket_id: "ticket_id",
                tag_id: "tag_id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });
});
