Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class ApiClient {
}

async invokeWebhooks(uuid: string): Promise<unknown> {
const env = await this.request<unknown>('POST', `/api/v2/builds/${encodeURIComponent(uuid)}/webhooks`);
const env = await this.request<unknown>('PUT', `/api/v2/builds/${encodeURIComponent(uuid)}/webhooks`);
return env.data;
}

Expand Down
31 changes: 30 additions & 1 deletion tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' });
});
});
Loading