Skip to content

feat(testmanagement): template selection + multi-select custom fields#319

Merged
gaurav-singh-9227 merged 1 commit into
mainfrom
feat/testcase-template-multiselect
Jun 15, 2026
Merged

feat(testmanagement): template selection + multi-select custom fields#319
gaurav-singh-9227 merged 1 commit into
mainfrom
feat/testcase-template-multiselect

Conversation

@gaurav-singh-9227

Copy link
Copy Markdown
Collaborator

What & why

Closes a customer blocker in the Test Management createTestCase/updateTestCase tools. Two gaps:

  1. No template selection — every test case was created with the default "Test Case Steps" template; no way to pick a custom template.
  2. custom_fields couldn't hold multiple values — the Zod schema restricted values to string | number | boolean, blocking arrays, so multi-select custom fields couldn't be set programmatically.

How the contract was determined

I probed the live TM v2 API (a project with real custom fields incl. a field_multi_dropdown) before writing code:

  • Template → API keys on the internal slug. Sending test_case_bdd was recognized (HTTP 422 "Scenario is required for BDD test cases"). A display name ("Test Case BDD") was silently ignored and fell back to test_case_steps. form-fields-v2 does not enumerate templates and there's no template-list endpoint, so resolving display→slug server-side isn't possible. Pass-through of the slug is the only viable approach.
  • Unrecognized template values fail silently (HTTP 200, falls back to default) — so we now warn when the returned template differs from the requested one.
  • template is create-only. The PATCH/update endpoint ignores it (even a valid slug didn't switch the template), so template is intentionally not added to updateTestCase.
  • Multi-select works on create and update when keyed by field name with an array: { "Field Name": ["opt1","opt2"] }. Keying by field id or a CSV string is silently dropped.

Changes

  • create-testcase.ts: optional template param (slug, pass-through) + a mismatch warning when the API silently falls back; custom_fields widened to accept arrays (multi-select). New exported CustomFieldValue type + customFieldValueSchema.
  • update-testcase.ts: custom_fields widened to accept arrays. No template (API ignores it on update).
  • testmanagement.test.ts: +4 tests — slug pass-through, the silent-fallback warning, and array custom_fields on both create and update. (apiClient mock gained patch.)

Testing

npm run build passes locally — lint, format, 186 tests (4 new), and tsc all green.

Known limitation

Switching an existing test case's template via updateTestCase is not supported by the TM API — it ignores the template field on PATCH. Template can only be set at creation; supporting post-creation switching would need a TM backend change.

🤖 Generated with Claude Code

…tom fields

createTestCase gains an optional `template` (internal slug, e.g. test_case_steps
or test_case_bdd) passed through to the TM v2 create endpoint, with a warning when
the API silently falls back to the default for an unrecognized value. Display names
are not accepted and the form-fields endpoint does not enumerate templates, so slug
pass-through is the only viable approach. template is create-only -- the PATCH/update
endpoint ignores it -- so it is not added to updateTestCase.

custom_fields on both create and update now accept array values, enabling
multi-select custom fields (keyed by field name).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gaurav-singh-9227 gaurav-singh-9227 merged commit 8b45669 into main Jun 15, 2026
5 checks passed
gaurav-singh-9227 added a commit that referenced this pull request Jun 25, 2026
…TestCaseTemplates

Follow-up to #319, which added a `template` param that only ever selects a
SYSTEM template (the TM create logic maps the slug to {is_system, step_type},
and step_type is constrained to test_case_steps/test_case_bdd and isn't unique).
A custom template is selectable only by its numeric template_id.

Two capabilities, both verified end-to-end against prod:

- listTestCaseTemplates: lists templates with their numeric ids via
  GET /api/v1/admin-v2/settings/templates?entity_type=TestCase (API-TOKEN auth),
  with a client-side name filter.

- createTestCase template_id: the public v2 create endpoint silently drops
  template_id, but the v1 create endpoint honours it. When template_id is set we
  route to POST /api/v1/projects/{numericId}/test-cases (API-TOKEN, folder in the
  body) and translate custom_fields from the by-name shape (v2) to v1's by-id
  shape (field name -> id, option value -> option id) so multi-select custom
  fields keep working alongside a template. With no template_id, the proven v2
  path is unchanged (zero regression). A post-create read-back warns if the
  applied template differs (e.g. id not linked to the project).

Verified live: create with template_id + multi-select custom_fields + priority
+ tags + steps applied all of them. Tests +6. npm run build green
(lint, format, tsc, tests).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants