-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microsoft OneDrive service root endpoint
This change makes the service root configurable for the Microsoft OneDrive nodes. The service root endpoint is configurable in the OneDrive credential. The motivation behind this change is to allow the Microsoft OneDrive N8N node to connect to the other tenant types such as the Microsoft GovCloud instances.
- Loading branch information
1 parent
1bb8e1b
commit a2bcd75
Showing
4 changed files
with
121 additions
and
6 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
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
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
70 changes: 70 additions & 0 deletions
70
packages/nodes-base/nodes/Microsoft/OneDrive/test/GenericFunctions.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,70 @@ | ||
import type { ICredentialDataDecryptedObject, IExecuteFunctions } from 'n8n-workflow'; | ||
|
||
import * as GenericFunctions from '../GenericFunctions'; | ||
|
||
const fakeExecute = (credentials: ICredentialDataDecryptedObject, result: unknown) => { | ||
const fakeExecuteFunction = { | ||
async getCredentials(): Promise<ICredentialDataDecryptedObject> { | ||
return credentials; | ||
}, | ||
getNode: jest.fn(), | ||
|
||
helpers: { | ||
requestOAuth2: jest.fn().mockResolvedValue(result), | ||
}, | ||
} as unknown as IExecuteFunctions; | ||
return fakeExecuteFunction; | ||
}; | ||
|
||
describe('Test MicrosoftOneDrive, GenericFunctions => microsoftApiRequest', () => { | ||
it('should call microsoftApiRequest using the defined service root', async () => { | ||
const execute = fakeExecute( | ||
{ | ||
graphEndpoint: 'https://foo.bar', | ||
useShared: false, | ||
userPrincipalName: 'test-principal', | ||
}, | ||
'foo', | ||
); | ||
|
||
const result: string = (await GenericFunctions.microsoftApiRequest.call( | ||
execute, | ||
'GET', | ||
'/foo', | ||
)) as string; | ||
|
||
expect(result).toEqual('foo'); | ||
expect(execute.helpers.requestOAuth2).toHaveBeenCalledTimes(1); | ||
expect(execute.helpers.requestOAuth2).toHaveBeenCalledWith('microsoftOneDriveOAuth2Api', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
method: 'GET', | ||
uri: 'https://foo.bar/v1.0/me/foo', | ||
json: true, | ||
}); | ||
}); | ||
|
||
it('should call microsoftApiRequest using the service root if no root is provided', async () => { | ||
const execute = fakeExecute( | ||
{ | ||
useShared: false, | ||
userPrincipalName: 'test-principal', | ||
}, | ||
'foo', | ||
); | ||
|
||
const result: string = (await GenericFunctions.microsoftApiRequest.call( | ||
execute, | ||
'GET', | ||
'/foo', | ||
)) as string; | ||
|
||
expect(result).toEqual('foo'); | ||
expect(execute.helpers.requestOAuth2).toHaveBeenCalledTimes(1); | ||
expect(execute.helpers.requestOAuth2).toHaveBeenCalledWith('microsoftOneDriveOAuth2Api', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
method: 'GET', | ||
uri: 'https://graph.microsoft.com/v1.0/me/foo', | ||
json: true, | ||
}); | ||
}); | ||
}); |