Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

227 lines
6.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type { ILoadOptionsFunctions, WorkflowTestData } from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks';
import { MicrosoftEntra } from '../MicrosoftEntra.node';
describe('Microsoft Entra Node', () => {
const testHarness = new NodeTestHarness();
const baseUrl = 'https://graph.microsoft.com/v1.0';
describe('Credentials', () => {
const credentials = {
microsoftEntraOAuth2Api: {
scope: '',
oauthTokenData: {
access_token: 'ACCESSTOKEN',
},
},
};
const tests: WorkflowTestData[] = [
{
description: 'should use correct credentials',
input: {
workflowData: {
nodes: [
{
parameters: {},
type: 'n8n-nodes-base.manualTrigger',
typeVersion: 1,
position: [0, 0],
id: '1307e408-a8a5-464e-b858-494953e2f43b',
name: 'When clicking Execute workflow',
},
{
parameters: {
resource: 'group',
operation: 'get',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
filter: '',
output: 'raw',
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.getGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: `/groups/${microsoftEntraApiResponse.getGroup.id}`,
statusCode: 200,
responseBody: {
...microsoftEntraApiResponse.getGroup,
},
},
],
},
},
];
for (const testData of tests) {
testHarness.setupTest(testData, { credentials });
}
});
describe('Load options', () => {
it('should load group properties', async () => {
const mockContext = {
helpers: {
requestWithAuthentication: jest
.fn()
.mockReturnValue(microsoftEntraApiResponse.metadata.groups),
},
getCurrentNodeParameter: jest.fn(),
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const properties = await node.methods.loadOptions.getGroupProperties.call(mockContext);
expect(properties).toEqual(microsoftEntraNodeResponse.loadOptions.getGroupProperties);
});
it('should load user properties', async () => {
const mockContext = {
helpers: {
requestWithAuthentication: jest
.fn()
.mockReturnValue(microsoftEntraApiResponse.metadata.users),
},
getCurrentNodeParameter: jest.fn(),
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const properties = await node.methods.loadOptions.getUserProperties.call(mockContext);
expect(properties).toEqual(microsoftEntraNodeResponse.loadOptions.getUserProperties);
});
});
describe('List search', () => {
it('should list search groups', async () => {
const mockResponse = {
value: Array.from({ length: 2 }, (_, i) => ({
id: (i + 1).toString(),
displayName: `Group ${i + 1}`,
})),
'@odata.nextLink': '',
};
const mockRequestWithAuthentication = jest.fn().mockReturnValue(mockResponse);
const mockContext = {
helpers: {
requestWithAuthentication: mockRequestWithAuthentication,
},
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const listSearchResult = await node.methods.listSearch.getGroups.call(mockContext);
expect(mockRequestWithAuthentication).toHaveBeenCalledWith('microsoftEntraOAuth2Api', {
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
headers: {},
body: {},
qs: {
$select: 'id,displayName',
},
});
expect(listSearchResult).toEqual({
results: mockResponse.value.map((x) => ({ name: x.displayName, value: x.id })),
paginationToken: mockResponse['@odata.nextLink'],
});
});
it('should list search users', async () => {
const mockResponse = {
value: Array.from({ length: 2 }, (_, i) => ({
id: (i + 1).toString(),
displayName: `User ${i + 1}`,
})),
'@odata.nextLink': '',
};
const mockRequestWithAuthentication = jest.fn().mockReturnValue(mockResponse);
const mockContext = {
helpers: {
requestWithAuthentication: mockRequestWithAuthentication,
},
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const listSearchResult = await node.methods.listSearch.getUsers.call(mockContext);
expect(mockRequestWithAuthentication).toHaveBeenCalledWith('microsoftEntraOAuth2Api', {
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/users',
json: true,
headers: {},
body: {},
qs: {
$select: 'id,displayName',
},
});
expect(listSearchResult).toEqual({
results: mockResponse.value.map((x) => ({ name: x.displayName, value: x.id })),
paginationToken: mockResponse['@odata.nextLink'],
});
});
});
});