Skip to content

Commit

Permalink
chore(chat): update docs chatbot request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy committed Oct 7, 2024
1 parent f99da1f commit c43ed72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/participant/docsChatbotAIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class DocsChatbotAIService {
}): Promise<Response> {
return fetch(uri, {
headers: {
origin: this._serverBaseUri,
'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`,
'User-Agent': `mongodb-vscode/${version}`,
...headers,
},
Expand Down
33 changes: 33 additions & 0 deletions src/test/suite/participant/docsChatbotAIService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import sinon from 'sinon';

import { DocsChatbotAIService } from '../../../participant/docsChatbotAIService';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../../../package.json');

suite('DocsChatbotAIService Test Suite', function () {
const initialFetch = global.fetch;
let docsChatbotAIService: DocsChatbotAIService;
Expand Down Expand Up @@ -138,4 +141,34 @@ suite('DocsChatbotAIService Test Suite', function () {
});
expect(rating).to.be.eql(true);
});

test('has the correct headers', async () => {
const fetchStub = sinon.stub().resolves({
status: 200,
ok: true,
json: () => Promise.resolve(true),
});
global.fetch = fetchStub;
expect(fetchStub.calledOnce).to.be.false;
const signal = new AbortController().signal;
await docsChatbotAIService.addMessage({
conversationId: '650b4b260f975ef031016c8a',
message: 'pineapple',
signal,
});
expect(fetchStub.calledOnce).to.be.true;
expect(fetchStub.firstCall.args[0]).to.equal(
'https://knowledge.mongodb.com/api/v1/conversations/650b4b260f975ef031016c8a/messages'
);
expect(fetchStub.firstCall.args[1]).to.deep.equal({
method: 'POST',
body: '{"message":"pineapple"}',
headers: {
'Content-Type': 'application/json',
'X-Request-Origin': `vscode-mongodb-copilot-v${version}/docs`,
'User-Agent': `mongodb-vscode/${version}`,
},
signal,
});
});
});

0 comments on commit c43ed72

Please sign in to comment.