Skip to content

test(cli): add 13 integration tests for CLI → API contract#21

Open
govindkavaturi-art wants to merge 1 commit intomainfrom
test/cli-integration-tests
Open

test(cli): add 13 integration tests for CLI → API contract#21
govindkavaturi-art wants to merge 1 commit intomainfrom
test/cli-integration-tests

Conversation

@govindkavaturi-art
Copy link
Copy Markdown
Member

Summary

Before this, `tests/test_cli.py` was exclusively help-text and argument-parsing assertions via Click's `CliRunner` — zero tests exercised the HTTP call the CLI makes. A breaking change in cueapi-core or the httpx client code path could land with fully green CI.

Approach

Patch `cueapi.cli.CueAPIClient` with a `MagicMock` that mimics the context-manager protocol, then assert on the resulting `.post` / `.get` / `.patch.call_args`. This preserves the full CLI code path (flag parsing, body construction, error handling) and only mocks the network boundary.

Coverage added (13 tests)

`create`

  • Recurring `--cron` posts correct body + `"type": "recurring"`
  • One-time `--at` produces `"type": "once"` schedule
  • `--worker` sets `transport: "worker"` and omits `callback`
  • `--payload` JSON parsed into body
  • `--on-failure` JSON parsed into body
  • Invalid `--payload` JSON rejected before any HTTP call
  • HTTP 403 surfaces the `cueapi upgrade` hint

`list`

  • Default params (`limit=20, offset=0`)
  • Filters (`--status active --limit 50 --offset 10`)

`pause` / `resume`

  • Both `PATCH /cues/{id}` with correct `{"status": "..."}` body

`update`

  • Patches correct path + body
  • "No fields specified" errors before calling the API

Verification

```
32 passed in 0.21s
```

Was 19/19 before this PR; now 32/32.

Why inline `--api-key` vs monkey-patching credentials

Using the existing `--api-key` flag is the supported "bypass config file" path — keeps tests close to how a user or CI script would actually run the command.

Test plan

  • CI green

Before this, tests/test_cli.py was exclusively help-text and
argument-parsing assertions via Click's CliRunner — zero tests
exercised the HTTP call the CLI makes. A breaking change in
cueapi-core or the httpx client code path could land with full
green CI.

Approach: patch cueapi.cli.CueAPIClient with a MagicMock that
mimics the context-manager protocol, assert on the resulting
.post/.get/.patch.call_args. Preserves full CLI code path
(flag parsing, body/schedule construction, error handling) and
only mocks the network boundary.

Coverage added:
- create: recurring cron → POST /cues body, one-time `--at` →
  "once" schedule, --worker omits callback, --payload JSON
  parsed into body, --on-failure JSON parsed, invalid --payload
  JSON rejected before any HTTP call, HTTP 403 surfaces the
  "cueapi upgrade" hint
- list: default params, filters (--status/--limit/--offset)
- pause/resume: PATCH /cues/{id} with correct {"status": "..."}
- update: patches correct path + body, "no fields" errors before
  calling the API

Tests: 32/32 pass (was 19/19).

Why inline --api-key instead of monkey-patching credentials:
using the existing --api-key flag is already the supported
"bypass config file" path; tests stay close to how a user or
CI script would run the command.
@govindkavaturi-art govindkavaturi-art enabled auto-merge (squash) April 20, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant