diff --git a/package.json b/package.json index db8ff84..3a7f24e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lfc-cli", - "version": "0.7.1", + "version": "0.7.2", "description": "Command-line interface for Lifecycle — preview environments, services, and static sites", "license": "Apache-2.0", "type": "module", diff --git a/src/lib/api.ts b/src/lib/api.ts index 80b8657..2e81d67 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -243,7 +243,7 @@ export class ApiClient { } async invokeWebhooks(uuid: string): Promise { - const env = await this.request('POST', `/api/v2/builds/${encodeURIComponent(uuid)}/webhooks`); + const env = await this.request('PUT', `/api/v2/builds/${encodeURIComponent(uuid)}/webhooks`); return env.data; } diff --git a/tests/api.test.ts b/tests/api.test.ts index a2a8edb..49f5261 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { afterEach, describe, expect, it, vi } from 'vitest'; import { ApiClient, type ListResult } from '../src/lib/api.js'; import type { Profile } from '../src/lib/config.js'; @@ -96,3 +96,32 @@ describe('ApiClient.resolveBuild', () => { expect(truncated).toBe(false); }); }); + +describe('ApiClient webhooks', () => { + afterEach(() => { + vi.unstubAllGlobals(); + }); + + function stubFetch(data: unknown) { + const fetchMock = vi.fn(async () => new Response(JSON.stringify({ request_id: 'r', data, error: null }))); + vi.stubGlobal('fetch', fetchMock); + return () => fetchMock.mock.calls[0] as unknown as [URL, RequestInit]; + } + + it('lists invocations with GET', async () => { + const firstCall = stubFetch([]); + await new ApiClient('test', PROFILE).listWebhookInvocations('a-b-1'); + const [url, init] = firstCall(); + expect(url.toString()).toBe('http://example.test/api/v2/builds/a-b-1/webhooks'); + expect(init.method).toBe('GET'); + }); + + it('invokes with PUT, since the route exports no POST handler', async () => { + const firstCall = stubFetch({ status: 'success' }); + const result = await new ApiClient('test', PROFILE).invokeWebhooks('a-b-1'); + const [url, init] = firstCall(); + expect(url.toString()).toBe('http://example.test/api/v2/builds/a-b-1/webhooks'); + expect(init.method).toBe('PUT'); + expect(result).toEqual({ status: 'success' }); + }); +});