-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: query parameters are not passed correctly to WolframAlpha API (#…
…3502) * fix: query parameters are not passed correctly to WolframAlpha API * Lint + format * Fix test --------- Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
f289f3d
commit 71a70b1
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { jest, 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", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let fetchMock: any; | ||
|
||
beforeEach(() => { | ||
fetchMock = jest.spyOn(global, "fetch").mockImplementation( | ||
async () => | ||
({ | ||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71a70b1
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.
Successfully deployed to the following URLs:
langchainjs-docs – ./docs/core_docs/
langchainjs-docs-langchain.vercel.app
langchainjs-docs-ruddy.vercel.app
langchainjs-docs-git-main-langchain.vercel.app
js.langchain.com