@@ -4,6 +4,9 @@ import sinon from 'sinon';
4
4
5
5
import { DocsChatbotAIService } from '../../../participant/docsChatbotAIService' ;
6
6
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ const { version } = require ( '../../../../package.json' ) ;
9
+
7
10
suite ( 'DocsChatbotAIService Test Suite' , function ( ) {
8
11
const initialFetch = global . fetch ;
9
12
let docsChatbotAIService : DocsChatbotAIService ;
@@ -138,4 +141,34 @@ suite('DocsChatbotAIService Test Suite', function () {
138
141
} ) ;
139
142
expect ( rating ) . to . be . eql ( true ) ;
140
143
} ) ;
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
+ } ) ;
141
174
} ) ;
0 commit comments