// 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("BrandsClient", () => {
    test("listBrands (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: "brand",
                    id: "tlkp1d91",
                    name: "Default Brand",
                    is_default: true,
                    created_at: 1673778600,
                    updated_at: 1711031100,
                    help_center_id: "11",
                    default_address_settings_id: "13",
                },
                {
                    type: "brand",
                    id: "3",
                    name: "Premium Brand",
                    is_default: false,
                    created_at: 1686387300,
                    updated_at: 1709229600,
                    help_center_id: "10",
                    default_address_settings_id: "15",
                },
            ],
        };
        server.mockEndpoint().get("/brands").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.brands.listBrands();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "brand",
                    id: "tlkp1d91",
                    name: "Default Brand",
                    is_default: true,
                    created_at: 1673778600,
                    updated_at: 1711031100,
                    help_center_id: "11",
                    default_address_settings_id: "13",
                },
                {
                    type: "brand",
                    id: "3",
                    name: "Premium Brand",
                    is_default: false,
                    created_at: 1686387300,
                    updated_at: 1709229600,
                    help_center_id: "10",
                    default_address_settings_id: "15",
                },
            ],
        });
    });

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

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

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

        const rawResponseBody = {
            type: "brand",
            id: "15",
            name: "Premium Brand",
            is_default: false,
            created_at: 1686387300,
            updated_at: 1709229600,
            help_center_id: "20",
            default_address_settings_id: "15",
        };
        server.mockEndpoint().get("/brands/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.brands.retrieveBrand({
            id: "id",
        });
        expect(response).toEqual({
            type: "brand",
            id: "15",
            name: "Premium Brand",
            is_default: false,
            created_at: 1686387300,
            updated_at: 1709229600,
            help_center_id: "20",
            default_address_settings_id: "15",
        });
    });

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

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

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

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