Skip to content

Automate browser based workflows with AI

27.8 KB
Raw Blame
// This file was auto-generated by Fern from our API Definition.

import * as Skyvern from "../../src/api/index";
import { SkyvernClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("Schedules", () => {
    test("listAll (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedules: [
                {
                    workflow_schedule_id: "workflow_schedule_id",
                    organization_id: "organization_id",
                    workflow_permanent_id: "workflow_permanent_id",
                    workflow_title: "workflow_title",
                    cron_expression: "cron_expression",
                    interval_seconds: 1,
                    first_fire_at: "2024-01-15T09:30:00Z",
                    run_at: "2024-01-15T09:30:00Z",
                    dispatch_status: "pending",
                    workflow_run_id: "workflow_run_id",
                    timezone: "timezone",
                    enabled: true,
                    parameters: { key: "value" },
                    name: "name",
                    description: "description",
                    next_run: "2024-01-15T09:30:00Z",
                    created_at: "2024-01-15T09:30:00Z",
                    modified_at: "2024-01-15T09:30:00Z",
                },
            ],
            total_count: 1,
            page: 1,
            page_size: 1,
        };
        server.mockEndpoint().get("/v1/schedules").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.schedules.listAll({
            page: 1,
            page_size: 1,
            status: "active",
            search: "search",
        });
        expect(response).toEqual({
            schedules: [
                {
                    workflow_schedule_id: "workflow_schedule_id",
                    organization_id: "organization_id",
                    workflow_permanent_id: "workflow_permanent_id",
                    workflow_title: "workflow_title",
                    cron_expression: "cron_expression",
                    interval_seconds: 1,
                    first_fire_at: "2024-01-15T09:30:00Z",
                    run_at: "2024-01-15T09:30:00Z",
                    dispatch_status: "pending",
                    workflow_run_id: "workflow_run_id",
                    timezone: "timezone",
                    enabled: true,
                    parameters: {
                        key: "value",
                    },
                    name: "name",
                    description: "description",
                    next_run: "2024-01-15T09:30:00Z",
                    created_at: "2024-01-15T09:30:00Z",
                    modified_at: "2024-01-15T09:30:00Z",
                },
            ],
            total_count: 1,
            page: 1,
            page_size: 1,
        });
    });

    test("listAll (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/schedules").respondWith().statusCode(422).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.schedules.listAll();
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("list (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedules: [
                {
                    workflow_schedule_id: "workflow_schedule_id",
                    organization_id: "organization_id",
                    workflow_permanent_id: "workflow_permanent_id",
                    cron_expression: "cron_expression",
                    interval_seconds: 1,
                    first_fire_at: "2024-01-15T09:30:00Z",
                    run_at: "2024-01-15T09:30:00Z",
                    dispatch_status: "pending",
                    workflow_run_id: "workflow_run_id",
                    timezone: "timezone",
                    enabled: true,
                    parameters: { key: "value" },
                    temporal_schedule_id: "temporal_schedule_id",
                    name: "name",
                    description: "description",
                    created_at: "2024-01-15T09:30:00Z",
                    modified_at: "2024-01-15T09:30:00Z",
                    deleted_at: "2024-01-15T09:30:00Z",
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/v1/agents/workflow_permanent_id/schedules")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.list("workflow_permanent_id");
        expect(response).toEqual({
            schedules: [
                {
                    workflow_schedule_id: "workflow_schedule_id",
                    organization_id: "organization_id",
                    workflow_permanent_id: "workflow_permanent_id",
                    cron_expression: "cron_expression",
                    interval_seconds: 1,
                    first_fire_at: "2024-01-15T09:30:00Z",
                    run_at: "2024-01-15T09:30:00Z",
                    dispatch_status: "pending",
                    workflow_run_id: "workflow_run_id",
                    timezone: "timezone",
                    enabled: true,
                    parameters: {
                        key: "value",
                    },
                    temporal_schedule_id: "temporal_schedule_id",
                    name: "name",
                    description: "description",
                    created_at: "2024-01-15T09:30:00Z",
                    modified_at: "2024-01-15T09:30:00Z",
                    deleted_at: "2024-01-15T09:30:00Z",
                },
            ],
        });
    });

    test("list (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/agents/workflow_permanent_id/schedules")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.list("workflow_permanent_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });
        const rawRequestBody = { timezone: "timezone" };
        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.create("workflow_permanent_id", {
            timezone: "timezone",
        });
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });
        const rawRequestBody = { timezone: "timezone" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.create("workflow_permanent_id", {
                timezone: "timezone",
            });
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("get (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .get("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.get("workflow_permanent_id", "workflow_schedule_id");
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("get (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.get("workflow_permanent_id", "workflow_schedule_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("update (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });
        const rawRequestBody = { timezone: "timezone" };
        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .put("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.update("workflow_permanent_id", "workflow_schedule_id", {
            timezone: "timezone",
        });
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("update (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });
        const rawRequestBody = { timezone: "timezone" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .put("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.update("workflow_permanent_id", "workflow_schedule_id", {
                timezone: "timezone",
            });
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("delete (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { ok: true };
        server
            .mockEndpoint()
            .delete("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.delete("workflow_permanent_id", "workflow_schedule_id");
        expect(response).toEqual({
            ok: true,
        });
    });

    test("delete (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.delete("workflow_permanent_id", "workflow_schedule_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("enable (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/enable")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.enable("workflow_permanent_id", "workflow_schedule_id");
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("enable (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/enable")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.enable("workflow_permanent_id", "workflow_schedule_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("disable (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/disable")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.disable("workflow_permanent_id", "workflow_schedule_id");
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("disable (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/disable")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.disable("workflow_permanent_id", "workflow_schedule_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });

    test("cancel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = {
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: { key: "value" },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/cancel")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.schedules.cancel("workflow_permanent_id", "workflow_schedule_id");
        expect(response).toEqual({
            schedule: {
                workflow_schedule_id: "workflow_schedule_id",
                organization_id: "organization_id",
                workflow_permanent_id: "workflow_permanent_id",
                cron_expression: "cron_expression",
                interval_seconds: 1,
                first_fire_at: "2024-01-15T09:30:00Z",
                run_at: "2024-01-15T09:30:00Z",
                dispatch_status: "pending",
                workflow_run_id: "workflow_run_id",
                timezone: "timezone",
                enabled: true,
                parameters: {
                    key: "value",
                },
                temporal_schedule_id: "temporal_schedule_id",
                name: "name",
                description: "description",
                created_at: "2024-01-15T09:30:00Z",
                modified_at: "2024-01-15T09:30:00Z",
                deleted_at: "2024-01-15T09:30:00Z",
            },
            next_runs: ["2024-01-15T09:30:00Z"],
        });
    });

    test("cancel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new SkyvernClient({ apiKey: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/agents/workflow_permanent_id/schedules/workflow_schedule_id/cancel")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.schedules.cancel("workflow_permanent_id", "workflow_schedule_id");
        }).rejects.toThrow(Skyvern.UnprocessableEntityError);
    });
});