@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
22import { MermaidChart } from './index.js' ;
33import { AICreditsLimitExceededError } from './errors.js' ;
44import type { AuthorizationData } from './types.js' ;
5+ import { URLS } from './urls.js' ;
56
67import { 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 } ) ,
0 commit comments