Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/profileCommands.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ const assertKeys = (input: JsonObject, allowed: readonly string[], label: string

const text = (input: JsonObject, key: string, max: number, requiredField: boolean): void => {
const value = input[key]
if (value === undefined && !requiredField) return
if (value === undefined) {
if (requiredField) throw new Error(`${key} is required`)
return
}
if (typeof value !== 'string' || value.length > max) throw new Error(`${key} must be text of at most ${max} characters`)
}

Expand Down
9 changes: 9 additions & 0 deletions test/profileCommands.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ describe('profile commands', () => {
expect(test.errors[1]).toContain('supported profile icon')
})

it('reports a missing required text field as required, not as too long', async () => {
const json: JsonMock = vi.fn(async () => ({ revision: 9 }))
const test = harness(json)
await expect(runCli(['profiles', 'actions', 'create', 'custom', 'profile1', '--name', 'n'], test.dependencies)).resolves.toBe(CliExitCode.USAGE)
await expect(runCli(['profiles', 'create', '--name', 'n', '--description', 'd'], test.dependencies)).resolves.toBe(CliExitCode.USAGE)
expect(test.errors).toEqual([expect.stringContaining('prompt is required'), expect.stringContaining('prompt is required')])
expect(json).not.toHaveBeenCalled()
})

it('rejects unknown, inapplicable, impossible, and trailing input before opening a profile request', async () => {
const json: JsonMock = vi.fn(async () => ({ revision: 9 }))
const test = harness(json)
Expand Down
Loading