Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/commands/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { ApiError } from '../lib/errors.js';
import { type CliSchedule, createScheduleCommand, runGet, runList } from './schedule.js';
import { type CliSchedule, createScheduleCommand, runGet, runList, runUpdate } from './schedule.js';

const SCHEDULE_FIXTURE: CliSchedule = {
scheduleId: 'sch_b3c91efa',
Expand Down Expand Up @@ -427,3 +427,27 @@ describe('runGet', () => {
).rejects.toBeInstanceOf(ApiError);
});
});

describe('runUpdate --name validation', () => {
it('rejects an empty --name instead of sending it to the server', async () => {
const fetchImpl = vi.fn();
await expect(
runUpdate(
{ ...BASE, output: 'json', scheduleId: 'sch_1', name: '' },
{ fetchImpl: fetchImpl as unknown as typeof globalThis.fetch, stdout: () => {}, stderr: () => {} },
),
).rejects.toMatchObject({ code: 'VALIDATION_ERROR', exitCode: 5 });
expect(fetchImpl).not.toHaveBeenCalled();
});

it('rejects a whitespace-only --name', async () => {
const fetchImpl = vi.fn();
const err = await runUpdate(
{ ...BASE, output: 'json', scheduleId: 'sch_1', name: ' ' },
{ fetchImpl: fetchImpl as unknown as typeof globalThis.fetch, stdout: () => {}, stderr: () => {} },
).catch((caught: unknown) => caught);
expect(err).toMatchObject({ code: 'VALIDATION_ERROR', exitCode: 5 });
expect((err as { nextAction: string }).nextAction).toContain('--name must not be empty');
expect(fetchImpl).not.toHaveBeenCalled();
});
});
4 changes: 4 additions & 0 deletions src/commands/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ export async function runUpdate(
}
const environment = normalizeScheduleEnvironmentName(opts.env);

if (opts.name !== undefined && opts.name.trim().length === 0) {
throw localValidationError('--name must not be empty');
}

const body: UpdateScheduleRequest = {
...(opts.name !== undefined ? { name: opts.name } : {}),
...(environment !== undefined ? { environment } : {}),
Expand Down
Loading