diff --git a/src/tools/sync/push.ts b/src/tools/sync/push.ts index ea034cf..879ff82 100644 --- a/src/tools/sync/push.ts +++ b/src/tools/sync/push.ts @@ -4,7 +4,7 @@ import { components, paths } from "../../api"; import { ListOptions } from "../client"; import { checkForConsistency } from "./consistency"; import { getGitContext } from "./git"; -import { TestTargetSyncData } from "./types"; +import { SyncDataByStableId, TestTargetSyncData } from "./types"; import { readTestCasesFromDir } from "./yaml"; type ErrorResponse = @@ -72,7 +72,7 @@ export const draftPush = async ( | { success: boolean; versionIds: string[]; - versionIdByStableId: Record; + syncDataByStableId: SyncDataByStableId; } | undefined > => { diff --git a/src/tools/sync/types.ts b/src/tools/sync/types.ts index 89d5ee8..0629d8e 100644 --- a/src/tools/sync/types.ts +++ b/src/tools/sync/types.ts @@ -1,6 +1,8 @@ -import { components } from "../../api"; +import { components, operations } from "../../api"; export type TestTargetSyncData = components["schemas"]["TestTargetSyncSchema"]; export type SyncTestCases = TestTargetSyncData["testCases"]; export type SyncTestCase = SyncTestCases[number]; export type ExecutionContext = components["schemas"]["ExecutionContext"]; +export type SyncDataByStableId = + operations["pushTestTargetDraft"]["responses"]["200"]["content"]["application/json"]["syncDataByStableId"]; diff --git a/src/tools/yamlMutations/edit.ts b/src/tools/yamlMutations/edit.ts index 9d2cf4f..05f4e52 100644 --- a/src/tools/yamlMutations/edit.ts +++ b/src/tools/yamlMutations/edit.ts @@ -100,13 +100,21 @@ export const edit = async (options: EditOptions): Promise => { throw new Error(`Could not edit test case with id '${testCaseToEdit.id}'`); } - const versionId = response.versionIdByStableId[testCaseToEdit.id]; - if (!versionId) { + const syncData = response.syncDataByStableId[testCaseToEdit.id]; + if (!syncData) { throw new Error(`Could not edit test case with id '${testCaseToEdit.id}'`); } + const { versionId, testResultId } = syncData; + const parsedBaseUrl = URL.parse(BASE_URL); - const localEditingUrl = `${parsedBaseUrl?.protocol}//${parsedBaseUrl?.host}/testtargets/${options.testTargetId}/testcases/${versionId}/localEdit?detailsPanelRail=steps&testTargetId=${options.testTargetId}&testCaseId=${versionId}`; - await open(localEditingUrl); + const localEditingUrl = new URL( + `${parsedBaseUrl?.protocol}//${parsedBaseUrl?.host}/testtargets/${options.testTargetId}/testcases/${versionId}/localEdit`, + ); + if (testResultId) { + localEditingUrl.searchParams.set("testResultId", testResultId); + } + + await open(localEditingUrl.href); console.log( `Navigating to local editing url, open it manually if a browser didn't open already: ${localEditingUrl}`, diff --git a/tests/tools/yamlMutations/edit.spec.ts b/tests/tools/yamlMutations/edit.spec.ts index b003621..5ba2301 100644 --- a/tests/tools/yamlMutations/edit.spec.ts +++ b/tests/tools/yamlMutations/edit.spec.ts @@ -1,5 +1,6 @@ import fs from "fs"; +import open from "open"; import ora from "ora"; import { beforeEach, describe, expect, it, MockedObject, vi } from "vitest"; import { mock } from "vitest-mock-extended"; @@ -97,7 +98,7 @@ describe("edit", () => { vi.mocked(draftPush).mockResolvedValue({ success: true, versionIds: [], - versionIdByStableId: {}, + syncDataByStableId: {}, }); await expect( @@ -117,7 +118,7 @@ describe("edit", () => { vi.mocked(draftPush).mockResolvedValue({ success: true, versionIds: [], - versionIdByStableId: { "test-id": "version-123" }, + syncDataByStableId: { "test-id": { versionId: "version-123" } }, }); vi.mocked(mockedClient.GET) .mockResolvedValueOnce({ @@ -158,7 +159,7 @@ describe("edit", () => { vi.mocked(draftPush).mockResolvedValue({ success: true, versionIds: [], - versionIdByStableId: { "child-id": "version-123" }, + syncDataByStableId: { "child-id": { versionId: "version-123" } }, }); vi.mocked(mockedClient.GET).mockResolvedValue({ data: { localEditingStatus: "CANCELLED" }, @@ -209,7 +210,7 @@ describe("edit", () => { vi.mocked(draftPush).mockResolvedValue({ success: true, versionIds: [], - versionIdByStableId: { "test-id": "version-123" }, + syncDataByStableId: { "test-id": { versionId: "version-123" } }, }); vi.mocked(mockedClient.GET) .mockResolvedValueOnce({ @@ -227,4 +228,39 @@ describe("edit", () => { expect(console.log).toHaveBeenCalledWith("Edited test case successfully"); }); + + it.each([ + { + testResultId: "result-456", + expectedUrl: expect.stringContaining("testResultId=result-456"), + }, + { + testResultId: undefined, + expectedUrl: expect.not.stringContaining("testResultId"), + }, + ])("handles testResultId=$testResultId in URL correctly", async ({ + testResultId, + expectedUrl, + }) => { + const testCase = createMockSyncTestCase({ id: "test-id" }); + + vi.mocked(findOctomindFolder).mockResolvedValue("/mock/.octomind"); + vi.mocked(getAbsoluteFilePathInOctomindRoot).mockResolvedValue( + "/mock/.octomind/test.yaml", + ); + vi.mocked(fs.readFileSync).mockReturnValue(yaml.stringify(testCase)); + vi.mocked(readTestCasesFromDir).mockReturnValue([testCase]); + vi.mocked(draftPush).mockResolvedValue({ + success: true, + versionIds: [], + syncDataByStableId: { + "test-id": { versionId: "version-123", testResultId }, + }, + }); + vi.mocked(waitForLocalChangesToBeFinished).mockResolvedValue("cancelled"); + + await edit({ testTargetId: "someId", filePath: "test.yaml" }); + + expect(open).toHaveBeenCalledWith(expectedUrl); + }); }); diff --git a/vitest.config.ts b/vitest.config.ts index 8c1ac4c..d3ba980 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,6 +6,7 @@ export default defineConfig({ test: { mockReset: true, globals: true, - environment: 'node' - } + environment: 'node', + include: ["tests/**/*.spec.ts"], + }, })