-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: query parameters are not passed correctly to WolframAlpha API #3502
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {afterEach, beforeEach, describe, expect} from "@jest/globals"; | ||
import {WolframAlphaTool} from "../wolframalpha.js"; | ||
|
||
const MOCK_APP_ID = '[MOCK_APP_ID]'; | ||
const QUERY_1 = 'What is 2 + 2?'; | ||
const MOCK_ANSWER = '[MOCK_ANSWER]'; | ||
|
||
describe("wolfram alpha test suite", () => { | ||
|
||
let fetchMock: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
fetchMock = jest.spyOn(global, "fetch").mockImplementation(() => { | ||
return Promise.resolve({ | ||
text: () => Promise.resolve(MOCK_ANSWER), | ||
} as Response); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.mockRestore(); | ||
}); | ||
|
||
test("test query parameters passed correctly", async () => { | ||
const wolframAlpha = new WolframAlphaTool({ | ||
appid: MOCK_APP_ID, | ||
}); | ||
await wolframAlpha._call(QUERY_1); | ||
const [url] = fetchMock.mock.calls[0]; | ||
const parsedUrl = new URL(url); | ||
const params = new URLSearchParams(parsedUrl.search); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(params.get("appid")).toBe(MOCK_APP_ID); | ||
expect(params.get("input")).toBe(QUERY_1); | ||
}); | ||
|
||
test("test answer retrieved", async () => { | ||
const wolframAlpha = new WolframAlphaTool({ | ||
appid: MOCK_APP_ID, | ||
}); | ||
|
||
const answer = await wolframAlpha._call(QUERY_1); | ||
expect(answer).toBe(MOCK_ANSWER); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,9 @@ export class WolframAlphaTool extends Tool { | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey team, just a heads up that I've flagged a new external HTTP request using the |
||
|
||
async _call(query: string): Promise<string> { | ||
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${query}`; | ||
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${ | ||
encodeURIComponent(query) | ||
}`; | ||
const res = await fetch(url); | ||
|
||
return res.text(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey team, just wanted to flag that this PR adds a new external HTTP request using the
fetch
API for testing the Wolfram Alpha tool. This comment is to ensure the maintainers review and approve the addition. Great work on the testing implementation!