// 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("SubscriptionTypesClient", () => {
    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: "subscription",
                    id: "135",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [{ name: "Newsletters", description: "Lorem ipsum dolor sit amet", locale: "en" }],
                    consent_type: "opt_out",
                    content_types: ["email"],
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/subscription_types")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.subscriptionTypes.list();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "subscription",
                    id: "135",
                    state: "live",
                    default_translation: {
                        name: "Newsletters",
                        description: "Lorem ipsum dolor sit amet",
                        locale: "en",
                    },
                    translations: [
                        {
                            name: "Newsletters",
                            description: "Lorem ipsum dolor sit amet",
                            locale: "en",
                        },
                    ],
                    consent_type: "opt_out",
                    content_types: ["email"],
                },
            ],
        });
    });

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

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