// 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("DataAttributesClient", () => {
    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: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "name",
                    full_name: "name",
                    label: "Company name",
                    description: "The name of a company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "company_id",
                    full_name: "company_id",
                    label: "Company ID",
                    description: "A number identifying a company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "last_request_at",
                    full_name: "last_request_at",
                    label: "Company last seen",
                    description: "The last day anyone from a company visited your site or app",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "remote_created_at",
                    full_name: "remote_created_at",
                    label: "Company created at",
                    description: "The day a company was added to Intercom",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "user_count",
                    full_name: "user_count",
                    label: "People",
                    description: "The number of people in a company",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "session_count",
                    full_name: "session_count",
                    label: "Company web sessions",
                    description: "All visits from anyone in a company to your product's site or app",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "name",
                    full_name: "plan.name",
                    label: "Plan",
                    description: "A specific plan or level within your product that companies have signed up to",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "monthly_spend",
                    full_name: "monthly_spend",
                    label: "Monthly Spend",
                    description: "The monthly revenue you receive from a company",
                    data_type: "float",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "size",
                    full_name: "size",
                    label: "Company size",
                    description: "The number of people employed in this company, expressed as a single number",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "industry",
                    full_name: "industry",
                    label: "Company industry",
                    description: "The category or domain this company belongs to e.g. 'ecommerce' or 'SaaS'",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "website",
                    full_name: "website",
                    label: "Company website",
                    description: "The web address for the company's primary marketing site",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 34,
                    model: "company",
                    name: "The One Ring",
                    full_name: "custom_attributes.The One Ring",
                    label: "The One Ring",
                    description:
                        "One ring to rule them all, one ring to find them, One ring to bring them all and in the darkness bind them.",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: true,
                    archived: false,
                    created_at: 1734537753,
                    updated_at: 1734537753,
                    admin_id: "991267784",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "id",
                    full_name: "id",
                    label: "ID",
                    description: "The Intercom defined id representing the company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "created_at",
                    full_name: "created_at",
                    label: "Created at",
                    description: "The time the company was added to Intercom",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "updated_at",
                    full_name: "updated_at",
                    label: "Updated at",
                    description: "The last time the company was updated",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "id",
                    full_name: "plan.id",
                    label: "Plan ID",
                    description: "The Intercom defined id representing the plan",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "app_id",
                    full_name: "app_id",
                    label: "App ID",
                    description: "The Intercom defined id representing the app",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
            ],
        };
        server.mockEndpoint().get("/data_attributes").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.dataAttributes.list({
            model: "contact",
            include_archived: true,
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "name",
                    full_name: "name",
                    label: "Company name",
                    description: "The name of a company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "company_id",
                    full_name: "company_id",
                    label: "Company ID",
                    description: "A number identifying a company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "last_request_at",
                    full_name: "last_request_at",
                    label: "Company last seen",
                    description: "The last day anyone from a company visited your site or app",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "remote_created_at",
                    full_name: "remote_created_at",
                    label: "Company created at",
                    description: "The day a company was added to Intercom",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "user_count",
                    full_name: "user_count",
                    label: "People",
                    description: "The number of people in a company",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "session_count",
                    full_name: "session_count",
                    label: "Company web sessions",
                    description: "All visits from anyone in a company to your product's site or app",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "name",
                    full_name: "plan.name",
                    label: "Plan",
                    description: "A specific plan or level within your product that companies have signed up to",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "monthly_spend",
                    full_name: "monthly_spend",
                    label: "Monthly Spend",
                    description: "The monthly revenue you receive from a company",
                    data_type: "float",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "size",
                    full_name: "size",
                    label: "Company size",
                    description: "The number of people employed in this company, expressed as a single number",
                    data_type: "integer",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "industry",
                    full_name: "industry",
                    label: "Company industry",
                    description: "The category or domain this company belongs to e.g. 'ecommerce' or 'SaaS'",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "website",
                    full_name: "website",
                    label: "Company website",
                    description: "The web address for the company's primary marketing site",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 34,
                    model: "company",
                    name: "The One Ring",
                    full_name: "custom_attributes.The One Ring",
                    label: "The One Ring",
                    description:
                        "One ring to rule them all, one ring to find them, One ring to bring them all and in the darkness bind them.",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: true,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: true,
                    archived: false,
                    created_at: 1734537753,
                    updated_at: 1734537753,
                    admin_id: "991267784",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "id",
                    full_name: "id",
                    label: "ID",
                    description: "The Intercom defined id representing the company",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "created_at",
                    full_name: "created_at",
                    label: "Created at",
                    description: "The time the company was added to Intercom",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "updated_at",
                    full_name: "updated_at",
                    label: "Updated at",
                    description: "The last time the company was updated",
                    data_type: "date",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "id",
                    full_name: "plan.id",
                    label: "Plan ID",
                    description: "The Intercom defined id representing the plan",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
                {
                    type: "data_attribute",
                    id: 12878,
                    model: "company",
                    name: "app_id",
                    full_name: "app_id",
                    label: "App ID",
                    description: "The Intercom defined id representing the app",
                    data_type: "string",
                    options: ["true", "false"],
                    api_writable: false,
                    messenger_writable: true,
                    ui_writable: false,
                    custom: false,
                    archived: false,
                    created_at: 1671028894,
                    updated_at: 1671028894,
                    admin_id: "5712945",
                },
            ],
        });
    });

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

        await expect(async () => {
            return await client.dataAttributes.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 = { data_type: "string" };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            data_type: "string",
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { data_type: "integer" };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            data_type: "integer",
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { data_type: "string" };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            data_type: "string",
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { data_type: "string" };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            data_type: "string",
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { data_type: "string" };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            data_type: "string",
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

    test("create (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{ value: "1-10" }] };
        const rawResponseBody = {
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        };
        server
            .mockEndpoint()
            .post("/data_attributes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.create({
            options: [
                {
                    value: "1-10",
                },
            ],
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 37,
            model: "company",
            name: "Mithril Shirt",
            full_name: "custom_attributes.Mithril Shirt",
            label: "Mithril Shirt",
            description: "Whether the user is a paid subscriber.",
            data_type: "string",
            options: ["true", "false"],
            api_writable: true,
            messenger_writable: false,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537756,
            updated_at: 1734537756,
            admin_id: "991267786",
        });
    });

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

        await expect(async () => {
            return await client.dataAttributes.create({
                options: [{}, {}],
            });
        }).rejects.toThrow(Intercom.BadRequestError);
    });

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

        await expect(async () => {
            return await client.dataAttributes.create({
                options: [{}, {}],
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{ value: "1-10" }, { value: "11-20" }] };
        const rawResponseBody = {
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.update({
            data_attribute_id: 1,
            body: {
                options: [
                    {
                        value: "1-10",
                    },
                    {
                        value: "11-20",
                    },
                ],
            },
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        });
    });

    test("update (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{ value: "1-10" }, { value: "11-50" }] };
        const rawResponseBody = {
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.update({
            data_attribute_id: 1,
            body: {
                options: [
                    {
                        value: "1-10",
                    },
                    {
                        value: "11-50",
                    },
                ],
            },
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        });
    });

    test("update (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{ value: "1-10" }, { value: "11-20" }] };
        const rawResponseBody = {
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.update({
            data_attribute_id: 1,
            body: {
                options: [
                    {
                        value: "1-10",
                    },
                    {
                        value: "11-20",
                    },
                ],
            },
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        });
    });

    test("update (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { description: "Trying to archieve", archived: true };
        const rawResponseBody = {
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.dataAttributes.update({
            data_attribute_id: 1,
            body: {
                description: "Trying to archieve",
                archived: true,
            },
        });
        expect(response).toEqual({
            type: "data_attribute",
            id: 44,
            model: "company",
            name: "The One Ring",
            full_name: "custom_attributes.The One Ring",
            label: "The One Ring",
            description: "Just a plain old ring",
            data_type: "string",
            options: ["1-10", "11-20"],
            api_writable: true,
            messenger_writable: true,
            ui_writable: false,
            custom: true,
            archived: false,
            created_at: 1734537762,
            updated_at: 1734537763,
            admin_id: "991267793",
        });
    });

    test("update (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{}, {}] };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.dataAttributes.update({
                data_attribute_id: 1,
                body: {
                    options: [{}, {}],
                },
            });
        }).rejects.toThrow(Intercom.BadRequestError);
    });

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

        await expect(async () => {
            return await client.dataAttributes.update({
                data_attribute_id: 1,
                body: {
                    options: [{}, {}],
                },
            });
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("update (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{}, {}] };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.dataAttributes.update({
                data_attribute_id: 1,
                body: {
                    options: [{}, {}],
                },
            });
        }).rejects.toThrow(Intercom.NotFoundError);
    });

    test("update (8)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { options: [{}, {}] };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/data_attributes/1")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.dataAttributes.update({
                data_attribute_id: 1,
                body: {
                    options: [{}, {}],
                },
            });
        }).rejects.toThrow(Intercom.UnprocessableEntityError);
    });
});
