@@ -4,6 +4,9 @@ import sinon from 'sinon';
44
55import { DocsChatbotAIService } from '../../../participant/docsChatbotAIService' ;
66
7+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8+ const { version } = require ( '../../../../package.json' ) ;
9+
710suite ( 'DocsChatbotAIService Test Suite' , function ( ) {
811 const initialFetch = global . fetch ;
912 let docsChatbotAIService : DocsChatbotAIService ;
@@ -138,4 +141,34 @@ suite('DocsChatbotAIService Test Suite', function () {
138141 } ) ;
139142 expect ( rating ) . to . be . eql ( true ) ;
140143 } ) ;
144+
145+ test ( 'has the correct headers' , async ( ) => {
146+ const fetchStub = sinon . stub ( ) . resolves ( {
147+ status : 200 ,
148+ ok : true ,
149+ json : ( ) => Promise . resolve ( true ) ,
150+ } ) ;
151+ global . fetch = fetchStub ;
152+ expect ( fetchStub . calledOnce ) . to . be . false ;
153+ const signal = new AbortController ( ) . signal ;
154+ await docsChatbotAIService . addMessage ( {
155+ conversationId : '650b4b260f975ef031016c8a' ,
156+ message : 'pineapple' ,
157+ signal,
158+ } ) ;
159+ expect ( fetchStub . calledOnce ) . to . be . true ;
160+ expect ( fetchStub . firstCall . args [ 0 ] ) . to . equal (
161+ 'https://knowledge.mongodb.com/api/v1/conversations/650b4b260f975ef031016c8a/messages'
162+ ) ;
163+ expect ( fetchStub . firstCall . args [ 1 ] ) . to . deep . equal ( {
164+ method : 'POST' ,
165+ body : '{"message":"pineapple"}' ,
166+ headers : {
167+ 'Content-Type' : 'application/json' ,
168+ 'X-Request-Origin' : `vscode-mongodb-copilot-v${ version } /docs` ,
169+ 'User-Agent' : `mongodb-vscode/${ version } ` ,
170+ } ,
171+ signal,
172+ } ) ;
173+ } ) ;
141174} ) ;
0 commit comments