Skip to content

Commit 4ae649c

Browse files
committed
resolve comments
1 parent 189fac2 commit 4ae649c

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/sdk/src/index.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import { MermaidChart } from './index.js';
33
import { AICreditsLimitExceededError } from './errors.js';
44
import type { AuthorizationData } from './types.js';
5+
import { URLS } from './urls.js';
56

67
import { OAuth2Client } from '@badgateway/oauth2-client';
78

@@ -172,27 +173,35 @@ describe('MermaidChart', () => {
172173
});
173174
});
174175

175-
describe('#mermaidPrSuggestion', () => {
176+
describe('#suggestPrSummary', () => {
176177
beforeEach(async () => {
177178
await client.setAccessToken('test-access-token');
178179
});
179180

180-
it('should return title and description from diagram diff', async () => {
181-
vi.spyOn(client, 'mermaidPrSuggestion').mockResolvedValue({
181+
it('should POST to the pr-summary endpoint with the request body and return response.data', async () => {
182+
const jsonResponse = {
182183
title: 'Add validation step to flowchart',
183184
description: '## What changed\n- Added node C',
185+
};
186+
187+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
188+
const postSpy = vi.spyOn((client as any).axios, 'post').mockResolvedValue({
189+
data: jsonResponse,
184190
});
185191

186-
const result = await client.mermaidPrSuggestion({
192+
const requestBody = {
187193
originalDiagram: 'flowchart TD\n A --> B',
188194
editedDiagram: 'flowchart TD\n A --> B\n B --> C[Validate]',
189-
});
195+
};
196+
197+
const result = await client.suggestPrSummary(requestBody);
190198

191-
expect(result.title).toContain('validation');
192-
expect(result.description).toContain('What changed');
199+
expect(postSpy).toHaveBeenCalledWith(URLS.rest.openai.prSummary, requestBody);
200+
expect(result).toEqual(jsonResponse);
193201
});
194202

195203
it('should throw AICreditsLimitExceededError on 402', async () => {
204+
// Mock the underlying axios call so the error mapping in suggestPrSummary is exercised.
196205
// eslint-disable-next-line @typescript-eslint/no-explicit-any
197206
vi.spyOn((client as any).axios, 'post').mockRejectedValue({
198207
response: {
@@ -202,7 +211,7 @@ describe('MermaidChart', () => {
202211
});
203212

204213
await expect(
205-
client.mermaidPrSuggestion({
214+
client.suggestPrSummary({
206215
originalDiagram: 'flowchart TD\n A --> B',
207216
editedDiagram: 'flowchart TD\n A --> B\n B --> C',
208217
}),

packages/sdk/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import type {
1919
MCUser,
2020
RepairDiagramRequest,
2121
RepairDiagramResponse,
22-
MermaidPrSuggestionRequest,
23-
MermaidPrSuggestionResponse,
22+
PrSummaryRequest,
23+
PrSummaryResponse,
2424
AICreditsUsage,
2525
} from './types.js';
2626
import { URLS } from './urls.js';
@@ -338,11 +338,9 @@ export class MermaidChart {
338338
* @param request - `originalDiagram` and `editedDiagram` only
339339
* @throws {@link AICreditsLimitExceededError} if credits limit exceeded (HTTP 402)
340340
*/
341-
public async mermaidPrSuggestion(
342-
request: MermaidPrSuggestionRequest,
343-
): Promise<MermaidPrSuggestionResponse> {
341+
public async suggestPrSummary(request: PrSummaryRequest): Promise<PrSummaryResponse> {
344342
try {
345-
const response = await this.axios.post<MermaidPrSuggestionResponse>(
343+
const response = await this.axios.post<PrSummaryResponse>(
346344
URLS.rest.openai.prSummary,
347345
request,
348346
);

packages/sdk/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ export interface RepairDiagramRequest {
9797
}
9898

9999
/**
100-
* Only the two diagram versions are sent; the server derives user plan and usage from the session.
100+
* Only the two diagram versions are sent; the server derives user plan and usage from the auth context provided by the access token.
101101
*/
102-
export interface MermaidPrSuggestionRequest {
102+
export interface PrSummaryRequest {
103103
originalDiagram: string;
104104
editedDiagram: string;
105105
}
106106

107107
/**
108108
* Public response: suggested PR title and markdown description
109109
*/
110-
export interface MermaidPrSuggestionResponse {
110+
export interface PrSummaryResponse {
111111
title: string;
112112
description: string;
113113
}

0 commit comments

Comments
 (0)