feat(testmanagement): create test cases with a custom template (template_id) + listTestCaseTemplates#328
Open
gaurav-singh-9227 wants to merge 1 commit into
Open
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
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).The catch: the public v2 create endpoint silently strips
template_id(proven — a project-linked custom template id still applied the default). But the v1 create endpoint honours it. So:template_idis set,createTestCaseroutes toPOST /api/v1/projects/{numericId}/test-cases(API-TOKEN auth, folder in the body) instead of v2.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.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 that warns if the applied template differs.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
feature/scenariofields on the schema (today's schema is steps-oriented) — out of scope.form-fields/ project-lookup calls.