feat(testmanagement): create test cases with a custom template (template_id) + listTestCaseTemplates#328
Merged
gaurav-singh-9227 merged 1 commit intoJun 26, 2026
Conversation
…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>
3577e1e to
3939fb7
Compare
ruturaj-browserstack
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Follow-up to #319 (which added a
templateparam that only selects system templates). This adds the ability to create a test case with a custom template, plus a way to discover template ids. Both verified end-to-end against prod.The key finding
A custom template can only be selected by numeric
template_id— thetemplateslug only ever picks a system template (step_typeis constrained totest_case_steps/test_case_bddand isn't unique).createTestCasetherefore routes to the v1 create endpoint when atemplate_idis supplied (it honours the id), and keeps using the v2 endpoint otherwise.Why not the documented v2 endpoint?
The natural choice would be the documented v2 create (
POST /api/v2/projects/{id}/folders/{folder_id}/test-cases). It cannot apply a custom template, confirmed two ways:1. No template-selection field exists in the v2 contract. The documented request body is
name, description, owner, preconditions, test_case_steps, issues, issue_tracker, tags, case_type, priority, custom_fields. There is notemplate_id/template_name. The only documentedtemplatevalue is"test_case_bdd"— a system step-type, not a custom template.2. v2 silently ignores
template_idat runtime. A direct call with a valid, project-linked custom template id returnsHTTP 200 success:true, but the field is dropped — the case is created with the default template:Tested across placements —
template_idinsidetest_case,template_idas a top-level sibling, andtemplateset to the numeric id string — all produced the default template. So this is not a payload-shape issue; the v2 endpoint does not carry template selection at all.v1 is the only public endpoint that honours
template_id(it is also the endpoint the TM web dashboard itself uses for template-based creates), so the PR uses v1 for that path only.How v1 is wired in
template_idis set →POST /api/v1/projects/{numericId}/test-cases(API-TOKEN auth, folder carried in the body). Same user credentials as the rest of the server (getBrowserStackAuth(config)), sameAPI-TOKENheader style already used byform-fields-v2/ project lookup / TCG calls.custom_fieldsby id with option ids, whereas v2 keys by name with values — so on the v1 path we translate the by-name shape → v1's by-id shape via the project's form fields, keeping multi-select custom fields working alongside a template.template_id, the proven v2 path is unchanged — zero regression for the common case.template_idsupport (see below) and we migrate back, any regression surfaces loudly instead of silently.Changes
list-templates.ts—listTestCaseTemplatestool →GET /api/v1/admin-v2/settings/templates?entity_type=TestCase(API-TOKEN), client-sidenamefilter.create-testcase.ts—template_idparam; v1 routing when set;toV1CustomFieldstranslation; post-create read-back warning.Testing
npm run buildgreen — lint, format, tsc, and 198 tests pass.Existing tests (sanity)
The pre-existing
testmanagementsuite is unchanged and still green — notably the v2 default create path, priority normalization, thetemplatesystem-slug pass-through + silent-fallback warning, and the multi-selectcustom_fields-by-name behaviour from #319 all continue to pass (this PR leaves the no-template_idpath entirely on v2).New tests (9)
createTestCase—template_idrouting & verification (6)template_idthrough to the request body and does not warn when applied —template_idreachesbody.test_case.template_id; no mismatch warning when the applied template equals the requested one.template_idthan requested — if the created case comes back with a differenttemplate_id, the tool surfaces a clear mismatch warning instead of reporting plain success.template_idis supplied (id takes precedence) — thetemplatesystem-slug fallback warning is suppressed whentemplate_idis present, so the two paths don't double-warn.template_idis omitted from the create response but not applied — the real create response has notemplate_id, so the tool re-reads the case via the v1 search endpoint and warns when the applied template differs (covers the silent-miss failure mode).template_idis set — asserts the request targets/api/v1/projects/{id}/test-caseswith theAPI-TOKENheader (not v2 + Basic), the folder is carried in the body (folder_idtop-level andtest_case.test_case_folder_id), and MCP-only params (project_identifier,folder_id) do not leak into thetest_casepayload.custom_fieldsname→id and option value→id on the v1 path — with form fields mocked,{ aaas: ["m40","m48"] }(v2/by-name shape) is rewritten to{ 194184: [111, 222] }(v1/by-id shape) in the request body.listTestCaseTemplates(3)GET /api/v1/admin-v2/settings/templates?entity_type=TestCasewith theAPI-TOKENheader and returns each template's numeric id and name.nameargument narrows the returned list (matching template kept, non-matching default dropped) and the count reflects the filtered set.No templates matching "…"message rather than an empty/confusing result.End-to-end verification (prod, throwaway folder, deleted after)
listTestCaseTemplatesvia compiled toolcreateTestCasewith a customtemplate_idcreateTestCasewithtemplate_id+ multi-selectcustom_fields+ priority + tags + stepsisError:false✅createTestCasewith an invalidtemplate_idcreateTestCasewith notemplate_id(v2 path)Server boots clean and registers all tools.
Notes / limitations / follow-up
template_idsupport on the documented v2 create so this path can move back to v2.feature/scenariofields on the schema (today's schema is steps-oriented) — out of scope.