// 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("attachTagToContact (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.unstable.tags.attachTagToContact({
            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("attachTagToContact (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.unstable.tags.attachTagToContact({
            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("attachTagToContact (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.unstable.tags.attachTagToContact({
            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("attachTagToContact (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: "type", 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.unstable.tags.attachTagToContact({
                contact_id: "contact_id",
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("attachTagToContact (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.unstable.tags.attachTagToContact({
                contact_id: "contact_id",
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("detachTagFromContact (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.unstable.tags.detachTagFromContact({
            contact_id: "63a07ddf05a32042dffac965",
            id: "7522907",
        });
        expect(response).toEqual({
            type: "tag",
            id: "84",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

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

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/contacts/contact_id/tags/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

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

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

    test("attachTagToConversation (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.unstable.tags.attachTagToConversation({
            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("attachTagToConversation (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.unstable.tags.attachTagToConversation({
            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("attachTagToConversation (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: "type", 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.unstable.tags.attachTagToConversation({
                conversation_id: "conversation_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("attachTagToConversation (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.unstable.tags.attachTagToConversation({
                conversation_id: "conversation_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("detachTagFromConversation (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.unstable.tags.detachTagFromConversation({
            conversation_id: "64619700005694",
            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("detachTagFromConversation (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.unstable.tags.detachTagFromConversation({
            conversation_id: "64619700005694",
            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("detachTagFromConversation (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.unstable.tags.detachTagFromConversation({
            conversation_id: "64619700005694",
            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("detachTagFromConversation (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/conversations/conversation_id/tags/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("detachTagFromConversation (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/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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

    test("listTags (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.unstable.tags.listTags();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "tag",
                    id: "102",
                    name: "Manual tag 1",
                    applied_at: 1663597223,
                    applied_by: {
                        type: "contact",
                        id: "1a2b3c",
                    },
                },
            ],
        });
    });

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

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

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

    test("createTag (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.unstable.tags.createTag({
            name: "test",
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("createTag (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.unstable.tags.createTag({
            name: "Independent",
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("createTag (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.unstable.tags.createTag({
            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("createTag (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.unstable.tags.createTag({
            name: "test",
            users: [
                {
                    id: "123",
                },
            ],
        });
        expect(response).toEqual({
            type: "tag",
            id: "105",
            name: "test",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

    test("createTag (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.unstable.tags.createTag({
                name: "name",
            });
        }).rejects.toThrow(Intercom.unstable.BadRequestError);
    });

    test("createTag (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/tags")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("createTag (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.unstable.tags.createTag({
                name: "name",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("findTag (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.unstable.tags.findTag({
            id: "123",
        });
        expect(response).toEqual({
            type: "tag",
            id: "113",
            name: "Manual tag",
            applied_at: 1663597223,
            applied_by: {
                type: "contact",
                id: "1a2b3c",
            },
        });
    });

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

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

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

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

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

    test("deleteTag (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.unstable.tags.deleteTag({
            id: "123",
        });
        expect(response).toEqual(undefined);
    });

    test("deleteTag (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/id").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

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

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

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

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

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

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

    test("attachTagToTicket (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.unstable.tags.attachTagToTicket({
            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("attachTagToTicket (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.unstable.tags.attachTagToTicket({
            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("attachTagToTicket (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: "type", 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.unstable.tags.attachTagToTicket({
                ticket_id: "ticket_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("attachTagToTicket (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.unstable.tags.attachTagToTicket({
                ticket_id: "ticket_id",
                id: "id",
                admin_id: "admin_id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("detachTagFromTicket (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.unstable.tags.detachTagFromTicket({
            ticket_id: "64619700005694",
            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("detachTagFromTicket (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.unstable.tags.detachTagFromTicket({
            ticket_id: "64619700005694",
            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("detachTagFromTicket (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.unstable.tags.detachTagFromTicket({
            ticket_id: "64619700005694",
            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("detachTagFromTicket (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: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/tickets/ticket_id/tags/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

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

    test("detachTagFromTicket (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/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

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