diff --git a/packages/visual-editor/src/cli/commands/internal/deploy/deploy.test.ts b/packages/visual-editor/src/cli/commands/internal/deploy/deploy.test.ts index 793780f37..dd59dcaf1 100644 --- a/packages/visual-editor/src/cli/commands/internal/deploy/deploy.test.ts +++ b/packages/visual-editor/src/cli/commands/internal/deploy/deploy.test.ts @@ -6,6 +6,7 @@ import { execFileSync } from "node:child_process"; import prompts from "prompts"; import { deploy } from "./deploy.ts"; import type { DeployConfig } from "./config.ts"; +import type { SectionLibraryRevision } from "./sectionLibraryApi.ts"; vi.mock("prompts"); @@ -17,10 +18,20 @@ const config: DeployConfig = { partition: "US", apiHost: "https://sbx-api.yextapis.com", }; -const successfulResponse = JSON.stringify({ - meta: { errors: [] }, - response: {}, -}); +const sectionLibrary = { + name: "accounts/123/sectionLibraries/library-123", + uid: "019c9cb4-a7ad-7312-a603-9a828ac7c103", + displayName: "Library", + description: "Test", +}; +const sectionLibraryRevision = { + name: `${sectionLibrary.name}/revisions/019c9cb5-0bc5-76cd-848c-25657b850a8f`, + status: "STATUS_BUILD_PROCESSING", +} satisfies SectionLibraryRevision; + +function successfulResponse(response: object): string { + return JSON.stringify({ meta: { errors: [] }, response }); +} let rootDir: string; let sourceCommitHash: string; @@ -73,11 +84,19 @@ describe("deploy", () => { it("creates a section library revision with Git source metadata", async () => { const fetchMock = vi .fn() - .mockResolvedValueOnce(new Response(successfulResponse, { status: 200 })) - .mockResolvedValueOnce(new Response(successfulResponse, { status: 201 })); + .mockResolvedValueOnce( + new Response(successfulResponse(sectionLibrary), { status: 200 }) + ) + .mockResolvedValueOnce( + new Response(successfulResponse(sectionLibraryRevision), { + status: 201, + }) + ); vi.stubGlobal("fetch", fetchMock); - await deploy(config); + const revision = await deploy(config); + + expect(revision).toEqual(sectionLibraryRevision); expect(fetchMock).toHaveBeenNthCalledWith( 1, @@ -120,7 +139,7 @@ describe("deploy", () => { vi .fn() .mockResolvedValueOnce( - new Response(successfulResponse, { status: 200 }) + new Response(successfulResponse(sectionLibrary), { status: 200 }) ) .mockResolvedValueOnce( new Response( @@ -151,7 +170,7 @@ describe("deploy", () => { vi .fn() .mockResolvedValueOnce( - new Response(successfulResponse, { status: 200 }) + new Response(successfulResponse(sectionLibrary), { status: 200 }) ) .mockResolvedValueOnce( new Response( @@ -250,7 +269,7 @@ describe("deploy", () => { vi .fn() .mockResolvedValueOnce( - new Response(successfulResponse, { status: 200 }) + new Response(successfulResponse(sectionLibrary), { status: 200 }) ) .mockResolvedValueOnce(new Response(responseBody, { status: 400 })) ); @@ -265,9 +284,17 @@ describe("deploy", () => { vi.mocked(prompts).mockResolvedValueOnce({ value: true }); const fetchMock = vi .fn() - .mockResolvedValueOnce(new Response(successfulResponse, { status: 404 })) - .mockResolvedValueOnce(new Response(successfulResponse, { status: 201 })) - .mockResolvedValueOnce(new Response(successfulResponse, { status: 201 })); + .mockResolvedValueOnce( + new Response(successfulResponse({}), { status: 404 }) + ) + .mockResolvedValueOnce( + new Response(successfulResponse(sectionLibrary), { status: 201 }) + ) + .mockResolvedValueOnce( + new Response(successfulResponse(sectionLibraryRevision), { + status: 201, + }) + ); vi.stubGlobal("fetch", fetchMock); await deploy(config); diff --git a/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.test.ts b/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.test.ts index 595b0bb93..02138f5b6 100644 --- a/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.test.ts +++ b/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.test.ts @@ -26,6 +26,8 @@ const config: DeployConfig = { partition: "US", apiHost: "https://sbx-api.yextapis.com", }; +const revisionId = "019c9cb5-0bc5-76cd-848c-25657b850a8f"; +const revisionName = `accounts/123/sectionLibraries/test-library/revisions/${revisionId}`; afterEach(() => { vi.clearAllMocks(); @@ -37,17 +39,15 @@ describe("pollRevision", () => { vi.useFakeTimers(); vi.mocked(getSectionLibraryRevision) .mockResolvedValueOnce({ - name: "revision-name", + name: revisionName, status: "STATUS_BUILD_PROCESSING", - uid: "revision-uid", }) .mockResolvedValueOnce({ - name: "revision-name", + name: revisionName, status: "STATUS_BUILD_SUCCEEDED", - uid: "revision-uid", }); - const polling = pollRevision(config, "revision-name", false); + const polling = pollRevision(config, revisionName, false); await vi.advanceTimersByTimeAsync(2000); await polling; @@ -56,28 +56,27 @@ describe("pollRevision", () => { "Waiting for Section Library Revision build..." ); expect(vi.mocked(ora).mock.results[0].value.succeed).toHaveBeenCalledWith( - "Section Library Revision revision-uid build succeeded after 2s." + `Section Library Revision ${revisionId} build succeeded after 2s.` ); }); it("rejects when the build reaches an unsuccessful terminal status", async () => { vi.useFakeTimers(); vi.mocked(getSectionLibraryRevision).mockResolvedValueOnce({ - name: "revision-name", - status: "STATUS_BUILD_FAILED", - uid: "test-uid", + name: revisionName, + status: "STATUS_BUILD_FAILURE", }); - const polling = pollRevision(config, "revision-name", false); + const polling = pollRevision(config, revisionName, false); const rejection = expect(polling).rejects.toThrow( - "Section Library Revision failed with status STATUS_BUILD_FAILED." + "Section Library Revision failed with status STATUS_BUILD_FAILURE." ); await vi.advanceTimersByTimeAsync(1000); await rejection; const spinner = vi.mocked(ora).mock.results[0]?.value; expect(spinner.fail).toHaveBeenCalledWith( - "Section Library Revision failed with status STATUS_BUILD_FAILED." + "Section Library Revision failed with status STATUS_BUILD_FAILURE." ); }); }); diff --git a/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.ts b/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.ts index 4a7fec912..783b22a6b 100644 --- a/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.ts +++ b/packages/visual-editor/src/cli/commands/internal/deploy/pollRevision.ts @@ -40,8 +40,9 @@ export async function pollRevision( if (revision?.status === BUILD_SUCCESS_STATUS) { const elapsedSeconds = Math.floor((Date.now() - startedAt) / 1000); + const revisionId = revision.name.split("/").pop(); spinner.succeed( - `Section Library Revision ${revision.uid} build succeeded after ${formatElapsed(elapsedSeconds)}.` + `Section Library Revision ${revisionId} build succeeded after ${formatElapsed(elapsedSeconds)}.` ); } else { const message = `Section Library Revision failed with status ${lastStatus}.`; diff --git a/packages/visual-editor/src/cli/commands/internal/deploy/sectionLibraryApi.ts b/packages/visual-editor/src/cli/commands/internal/deploy/sectionLibraryApi.ts index 5bee1eaea..9ccd1bcb0 100644 --- a/packages/visual-editor/src/cli/commands/internal/deploy/sectionLibraryApi.ts +++ b/packages/visual-editor/src/cli/commands/internal/deploy/sectionLibraryApi.ts @@ -13,10 +13,17 @@ export interface SectionLibrary { export interface SectionLibraryRevision { name: string; - status: string; - uid: string; + status: SectionLibraryRevisionStatus; } +type SectionLibraryRevisionStatus = + | "STATUS_UNSPECIFIED" + | "STATUS_BUILD_PROCESSING" + | "STATUS_BUILD_SUCCEEDED" + | "STATUS_BUILD_SYSTEM_ERROR" + | "STATUS_BUILD_FAILURE" + | "STATUS_BUILD_TIMED_OUT"; + interface RevisionSource { sourceGitOrigin: string; sourceCommitHash: string;