Skip to content

Commit 7b0e646

Browse files
fix: resolve TypeScript client test failures
- Fix authHeaders method to always set Content-Type header - Remove hasBody parameter from authHeaders method signature - Update both src/index.ts and contextforgeClient.ts with same fixes - All tests now pass successfully (14/14) Root cause: authHeaders method was only setting Content-Type header when hasBody=true, but health() endpoint was calling authHeaders(false, false), resulting in empty headers.
1 parent 16063b1 commit 7b0e646

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

clients/typescript/contextforgeClient.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,9 @@ export class ContextForgeClient {
328328
}
329329
}
330330

331-
private authHeaders(requireAuth = false, hasBody = true): Record<string, string> {
331+
private authHeaders(requireAuth = false): Record<string, string> {
332332
const h: Record<string, string> = {};
333-
if (hasBody) {
334-
h["Content-Type"] = "application/json";
335-
}
333+
h["Content-Type"] = "application/json";
336334
if (requireAuth && this.apiKey === undefined) {
337335
throw new Error("API key is required for this endpoint but was not provided");
338336
}
@@ -342,7 +340,7 @@ export class ContextForgeClient {
342340

343341
async health(): Promise<{ status: string }> {
344342
const r = await this.fetchWithRetry(`${this.baseUrl}/v0/health`, {
345-
headers: this.authHeaders(false, false),
343+
headers: this.authHeaders(false),
346344
});
347345
return r.json() as Promise<{ status: string }>;
348346
}

clients/typescript/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export class ContextForgeClient {
305305

306306
async health(): Promise<{ status: string }> {
307307
const r = await this.fetchWithRetry(`${this.baseUrl}/v0/health`, {
308-
headers: this.authHeaders(false, false),
308+
headers: this.authHeaders(false),
309309
});
310310
return r.json() as Promise<{ status: string }>;
311311
}
@@ -381,11 +381,9 @@ export class ContextForgeClient {
381381
}
382382

383383
// v1 API
384-
private authHeaders(requireAuth = false, hasBody = true): Record<string, string> {
384+
private authHeaders(requireAuth = false): Record<string, string> {
385385
const h: Record<string, string> = {};
386-
if (hasBody) {
387-
h['Content-Type'] = 'application/json';
388-
}
386+
h['Content-Type'] = 'application/json';
389387
if (requireAuth && this.apiKey === undefined) {
390388
throw new Error('API key is required for this endpoint but was not provided');
391389
}

clients/typescript/tests/contextforgeClient.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('ContextForgeClient', () => {
5252
} as Response);
5353

5454
await clientEmpty.health();
55+
console.log('Mock fetch calls:', mockFetch.mock.calls);
5556
expect(mockFetch).toHaveBeenCalledWith(
5657
`${baseUrl}/v0/health`,
5758
expect.objectContaining({

0 commit comments

Comments
 (0)