n8n/packages/nodes-base/nodes/Microsoft/Dynamics/test/GenericFunctions.test.ts
Thanasis G 6fa5b3d292
fix: Sign Microsoft Dynamics OAuth2 requests with the access token (#37855)
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 16:24:47 +00:00

20 lines
796 B
TypeScript

import { mock } from 'vitest-mock-extended';
import type { IExecuteFunctions } from 'n8n-workflow';
import { microsoftApiRequest } from '../GenericFunctions';
describe('microsoftApiRequest', () => {
it('should call requestOAuth2 without oAuth2Options so the stored access token is used', async () => {
const requestOAuth2 = vi.fn().mockResolvedValue({});
const context = mock<IExecuteFunctions>({
helpers: mock<IExecuteFunctions['helpers']>({ requestOAuth2 }),
});
context.getCredentials.mockResolvedValue({ subdomain: 'org', region: 'crm.dynamics.com' });
await microsoftApiRequest.call(context, 'GET', '/accounts');
expect(requestOAuth2).toHaveBeenCalledWith('microsoftDynamicsOAuth2Api', expect.any(Object));
expect(requestOAuth2.mock.calls[0]).toHaveLength(2);
});
});