-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(OpenAI Node): Update node to account for URL in credentials (#12356)
- Loading branch information
1 parent
11e8520
commit f78cceb
Showing
2 changed files
with
72 additions
and
2 deletions.
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
62 changes: 62 additions & 0 deletions
62
packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/transport/test/transport.test.ts
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,62 @@ | ||
import type { IExecuteFunctions } from 'n8n-workflow'; | ||
|
||
import { apiRequest } from '../index'; | ||
|
||
const mockedExecutionContext = { | ||
getCredentials: jest.fn(), | ||
helpers: { | ||
requestWithAuthentication: jest.fn(), | ||
}, | ||
}; | ||
|
||
describe('apiRequest', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should call requestWithAuthentication with credentials URL if one is provided', async () => { | ||
mockedExecutionContext.getCredentials.mockResolvedValue({ | ||
url: 'http://www.test/url/v1', | ||
}); | ||
|
||
// Act | ||
await apiRequest.call(mockedExecutionContext as unknown as IExecuteFunctions, 'GET', '/test', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
// Assert | ||
|
||
expect(mockedExecutionContext.getCredentials).toHaveBeenCalledWith('openAiApi'); | ||
expect(mockedExecutionContext.helpers.requestWithAuthentication).toHaveBeenCalledWith( | ||
'openAiApi', | ||
{ | ||
headers: { 'Content-Type': 'application/json' }, | ||
method: 'GET', | ||
uri: 'http://www.test/url/v1/test', | ||
json: true, | ||
}, | ||
); | ||
}); | ||
|
||
it('should call requestWithAuthentication with default URL if credentials URL is not provided', async () => { | ||
mockedExecutionContext.getCredentials.mockResolvedValue({}); | ||
|
||
// Act | ||
await apiRequest.call(mockedExecutionContext as unknown as IExecuteFunctions, 'GET', '/test', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
// Assert | ||
|
||
expect(mockedExecutionContext.getCredentials).toHaveBeenCalledWith('openAiApi'); | ||
expect(mockedExecutionContext.helpers.requestWithAuthentication).toHaveBeenCalledWith( | ||
'openAiApi', | ||
{ | ||
headers: { 'Content-Type': 'application/json' }, | ||
method: 'GET', | ||
uri: 'https://api.openai.com/v1/test', | ||
json: true, | ||
}, | ||
); | ||
}); | ||
}); |