// 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("WorkflowsClient", () => {
    test("exportWorkflow (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            export_version: "1.0",
            exported_at: "2026-01-26T12:00:00Z",
            app_id: 12345,
            workflow: {
                id: "67890",
                title: "My Workflow",
                description: "A workflow that handles customer inquiries",
                trigger_type: "inbound_conversation",
                state: "live",
                target_channels: ["chat"],
                preferred_devices: ["desktop", "mobile"],
                created_at: "2025-06-15T10:30:00Z",
                updated_at: "2026-01-20T14:45:00Z",
                targeting: { key: "value" },
                snapshot: { key: "value" },
                attributes: [{ key: "value" }],
                embedded_rules: [{ key: "value" }],
            },
        };
        server
            .mockEndpoint()
            .get("/export/workflows/12345")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.workflows.exportWorkflow({
            id: "12345",
        });
        expect(response).toEqual({
            export_version: "1.0",
            exported_at: "2026-01-26T12:00:00Z",
            app_id: 12345,
            workflow: {
                id: "67890",
                title: "My Workflow",
                description: "A workflow that handles customer inquiries",
                trigger_type: "inbound_conversation",
                state: "live",
                target_channels: ["chat"],
                preferred_devices: ["desktop", "mobile"],
                created_at: "2025-06-15T10:30:00Z",
                updated_at: "2026-01-20T14:45:00Z",
                targeting: {
                    key: "value",
                },
                snapshot: {
                    key: "value",
                },
                attributes: [
                    {
                        key: "value",
                    },
                ],
                embedded_rules: [
                    {
                        key: "value",
                    },
                ],
            },
        });
    });

    test("exportWorkflow (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("/export/workflows/id")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.workflows.exportWorkflow({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.ForbiddenError);
    });

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

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