@@ -17,52 +17,56 @@ import type { PactV4 } from "@pact-foundation/pact";
1717
1818import { createHttpClient } from "../../httpClient" ;
1919import { createChatEndpoints } from "../../endpoints/chat" ;
20- import { createPact } from "./_pact" ;
20+ import { CONTRACT_SUITE_OPTIONS , createPact } from "./_pact" ;
2121
22- describe ( "contract @ POST /api/v1/chat (non-streaming)" , ( ) => {
23- let pact : PactV4 ;
24- beforeAll ( ( ) => {
25- pact = createPact ( ) ;
26- } ) ;
27- afterAll ( ( ) => { } ) ;
22+ describe (
23+ "contract @ POST /api/v1/chat (non-streaming)" ,
24+ CONTRACT_SUITE_OPTIONS ,
25+ ( ) => {
26+ let pact : PactV4 ;
27+ beforeAll ( ( ) => {
28+ pact = createPact ( ) ;
29+ } ) ;
30+ afterAll ( ( ) => { } ) ;
2831
29- it ( "returns assistant text for a simple user prompt (hub persona)" , async ( ) => {
30- await pact
31- . addInteraction ( )
32- . given (
33- "authenticated user-pact-001 with a clean conversation; Anthropic stub returns fixed assistant text" ,
34- )
35- . uponReceiving (
36- "a POST /api/v1/chat request without tool-calls (non-streaming)" ,
37- )
38- . withRequest ( "POST" , "/api/v1/chat" , ( req ) => {
39- req . headers ( {
40- accept : "application/json" ,
41- "content-type" : "application/json" ,
32+ it ( "returns assistant text for a simple user prompt (hub persona)" , async ( ) => {
33+ await pact
34+ . addInteraction ( )
35+ . given (
36+ "authenticated user-pact-001 with a clean conversation; Anthropic stub returns fixed assistant text" ,
37+ )
38+ . uponReceiving (
39+ "a POST /api/v1/chat request without tool-calls (non-streaming)" ,
40+ )
41+ . withRequest ( "POST" , "/api/v1/chat" , ( req ) => {
42+ req . headers ( {
43+ accept : "application/json" ,
44+ "content-type" : "application/json" ,
45+ } ) ;
46+ req . jsonBody ( {
47+ context : "hub" ,
48+ messages : [ { role : "user" , content : "Привіт, як справи?" } ] ,
49+ stream : false ,
50+ } ) ;
51+ } )
52+ . willRespondWith ( 200 , ( res ) => {
53+ res . headers ( { "content-type" : "application/json" } ) ;
54+ res . jsonBody ( {
55+ text : "Все ок, що треба зробити?" ,
56+ } ) ;
57+ } )
58+ . executeTest ( async ( mockServer ) => {
59+ const http = createHttpClient ( { baseUrl : mockServer . url } ) ;
60+ const chat = createChatEndpoints ( http ) ;
61+ const out = await chat . send ( {
62+ context : "hub" ,
63+ messages : [ { role : "user" , content : "Привіт, як справи?" } ] ,
64+ stream : false ,
65+ } ) ;
66+ expect ( out . text ) . toBe ( "Все ок, що треба зробити?" ) ;
67+ expect ( out . tool_calls ) . toBeUndefined ( ) ;
68+ expect ( out . error ) . toBeUndefined ( ) ;
4269 } ) ;
43- req . jsonBody ( {
44- context : "hub" ,
45- messages : [ { role : "user" , content : "Привіт, як справи?" } ] ,
46- stream : false ,
47- } ) ;
48- } )
49- . willRespondWith ( 200 , ( res ) => {
50- res . headers ( { "content-type" : "application/json" } ) ;
51- res . jsonBody ( {
52- text : "Все ок, що треба зробити?" ,
53- } ) ;
54- } )
55- . executeTest ( async ( mockServer ) => {
56- const http = createHttpClient ( { baseUrl : mockServer . url } ) ;
57- const chat = createChatEndpoints ( http ) ;
58- const out = await chat . send ( {
59- context : "hub" ,
60- messages : [ { role : "user" , content : "Привіт, як справи?" } ] ,
61- stream : false ,
62- } ) ;
63- expect ( out . text ) . toBe ( "Все ок, що треба зробити?" ) ;
64- expect ( out . tool_calls ) . toBeUndefined ( ) ;
65- expect ( out . error ) . toBeUndefined ( ) ;
66- } ) ;
67- } ) ;
68- } ) ;
70+ } ) ;
71+ } ,
72+ ) ;
0 commit comments