This commit is contained in:
Adria Navarro 2023-08-01 13:36:38 +02:00
parent 672666d96b
commit 559f52d904
1 changed files with 14 additions and 5 deletions

View File

@ -22,6 +22,10 @@ jest.mock(
})) }))
) )
const mockedOpenAIApi = openai.OpenAIApi as jest.MockedClass<
typeof openai.OpenAIApi
>
const OPENAI_PROMPT = "What is the meaning of life?" const OPENAI_PROMPT = "What is the meaning of life?"
describe("test the openai action", () => { describe("test the openai action", () => {
@ -68,11 +72,16 @@ describe("test the openai action", () => {
}) })
it("should present the correct error message when an error is thrown from the createChatCompletion call", async () => { it("should present the correct error message when an error is thrown from the createChatCompletion call", async () => {
;(openai.OpenAIApi as any).mockImplementation(() => ({ mockedOpenAIApi.mockImplementation(
createChatCompletion: jest.fn(() => { () =>
throw new Error("An error occurred while calling createChatCompletion") ({
}), createChatCompletion: jest.fn(() => {
})) throw new Error(
"An error occurred while calling createChatCompletion"
)
}),
} as any)
)
const res = await setup.runStep("OPENAI", { const res = await setup.runStep("OPENAI", {
prompt: OPENAI_PROMPT, prompt: OPENAI_PROMPT,