first commit
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
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
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import * as alert from '../../../v2/actions/alert';
|
||||
import * as transport from '../../../v2/transport';
|
||||
|
||||
jest.mock('../../../v2/transport', () => ({
|
||||
splunkApiJsonRequest: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('Splunk, alert resource', () => {
|
||||
const response = [{ id: '123' }, { id: '345' }];
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
test('getMetrics operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue(response);
|
||||
const responseData = await alert.getMetrics.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/alerts/metric_alerts',
|
||||
);
|
||||
expect(responseData).toEqual(response);
|
||||
});
|
||||
|
||||
test('getReport operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue(response);
|
||||
const responseData = await alert.getReport.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/alerts/fired_alerts',
|
||||
);
|
||||
expect(responseData).toEqual(response);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { SPLUNK } from '../../../v1/types';
|
||||
import * as report from '../../../v2/actions/report';
|
||||
import * as transport from '../../../v2/transport';
|
||||
|
||||
jest.mock('../../../v2/transport', () => ({
|
||||
splunkApiJsonRequest: jest.fn(),
|
||||
splunkApiRequest: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('Splunk, report resource', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
test('create operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('name', 0).mockReturnValue('someName');
|
||||
executeFunctions.getNodeParameter.calledWith('searchJobId', 0).mockReturnValue('12345');
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([
|
||||
{
|
||||
id: '12345',
|
||||
cronSchedule: '*/5 * * * *',
|
||||
earliestTime: '2020-01-01T00:00:00.000Z',
|
||||
latestTime: '2020-01-01T00:05:00.000Z',
|
||||
isScheduled: true,
|
||||
search: 'search index=_internal | stats count by source',
|
||||
name: 'someName',
|
||||
},
|
||||
]);
|
||||
|
||||
const response = {
|
||||
feed: {
|
||||
entry: [
|
||||
{
|
||||
id: '1',
|
||||
content: { [SPLUNK.DICT]: { [SPLUNK.KEY]: [{ $: { name: 'key1' }, _: 'value1' }] } },
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue(Promise.resolve(response));
|
||||
|
||||
const responseData = await report.create.execute.call(executeFunctions, 0);
|
||||
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/search/jobs/12345',
|
||||
);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith('POST', '/services/saved/searches', {
|
||||
alert_type: 'always',
|
||||
cron_schedule: '*/5 * * * *',
|
||||
'dispatch.earliest_time': '2020-01-01T00:00:00.000Z',
|
||||
'dispatch.latest_time': '2020-01-01T00:05:00.000Z',
|
||||
is_scheduled: true,
|
||||
name: 'someName',
|
||||
search: 'search index=_internal | stats count by source',
|
||||
});
|
||||
expect(responseData).toEqual([{ entryUrl: '1', id: '1', key1: 'value1' }]);
|
||||
});
|
||||
|
||||
test('deleteReport operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.mockReturnValue('12345');
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue({});
|
||||
const responseData = await report.deleteReport.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/services/saved/searches/12345',
|
||||
);
|
||||
expect(responseData).toEqual({ success: true });
|
||||
});
|
||||
|
||||
test('get operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('reportId', 0).mockReturnValue('12345');
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await report.get.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/saved/searches/12345',
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('getAll operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('options', 0).mockReturnValue({});
|
||||
executeFunctions.getNodeParameter.calledWith('returnAll', 0).mockReturnValue(true);
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await report.getAll.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/saved/searches',
|
||||
{},
|
||||
{ count: 0 },
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import * as search from '../../../v2/actions/search';
|
||||
import * as transport from '../../../v2/transport';
|
||||
|
||||
jest.mock('../../../v2/transport', () => ({
|
||||
splunkApiJsonRequest: jest.fn(),
|
||||
splunkApiRequest: jest.fn(),
|
||||
}));
|
||||
describe('Splunk, search resource', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('create operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter
|
||||
.calledWith('search', 0)
|
||||
.mockReturnValue('search index=_internal | stats count by source');
|
||||
executeFunctions.getNodeParameter.calledWith('additionalFields', 0).mockReturnValue({
|
||||
earliest_time: '2020-01-01T00:00:00.000Z',
|
||||
latest_time: '2020-01-01T00:05:00.000Z',
|
||||
index_earliest: '2020-01-01T00:00:00.000Z',
|
||||
index_latest: '2020-01-01T00:05:00.000Z',
|
||||
});
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue({ response: { sid: '12345' } });
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await search.create.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith('POST', '/services/search/jobs', {
|
||||
earliest_time: 1577836800,
|
||||
index_earliest: 1577836800,
|
||||
index_latest: 1577837100,
|
||||
latest_time: 1577837100,
|
||||
search: 'search index=_internal | stats count by source',
|
||||
});
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/search/jobs/12345',
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('deleteJob operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.mockReturnValue('12345');
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue({});
|
||||
const responseData = await search.deleteJob.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/services/search/jobs/12345',
|
||||
);
|
||||
expect(responseData).toEqual({ success: true });
|
||||
});
|
||||
|
||||
test('get operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('searchJobId', 0).mockReturnValue('12345');
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await search.get.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/search/jobs/12345',
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('getAll operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('sort.values', 0).mockReturnValue({});
|
||||
executeFunctions.getNodeParameter.calledWith('returnAll', 0).mockReturnValue(true);
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await search.getAll.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/search/jobs',
|
||||
{},
|
||||
{ count: 0 },
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('getResult operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('searchJobId', 0).mockReturnValue('12345');
|
||||
executeFunctions.getNodeParameter.calledWith('filters', 0).mockReturnValue({
|
||||
keyValueMatch: { keyValuePair: { key: 'key1', value: 'test1' } },
|
||||
});
|
||||
executeFunctions.getNodeParameter.calledWith('returnAll', 0).mockReturnValue(false);
|
||||
executeFunctions.getNodeParameter.calledWith('limit', 0).mockReturnValue(10);
|
||||
executeFunctions.getNodeParameter.calledWith('options', 0).mockReturnValue({});
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await search.getResult.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/search/jobs/12345/results',
|
||||
{},
|
||||
{ count: 10, search: 'search key1=test1' },
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { SPLUNK } from '../../../v1/types';
|
||||
import * as user from '../../../v2/actions/user';
|
||||
import * as transport from '../../../v2/transport';
|
||||
|
||||
jest.mock('../../../v2/transport', () => ({
|
||||
splunkApiJsonRequest: jest.fn(),
|
||||
splunkApiRequest: jest.fn(),
|
||||
}));
|
||||
describe('Splunk, user resource', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('create operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('roles', 0).mockReturnValue(['role1', 'role2']);
|
||||
executeFunctions.getNodeParameter.calledWith('name', 0).mockReturnValue('John Doe');
|
||||
executeFunctions.getNodeParameter.calledWith('password', 0).mockReturnValue('password');
|
||||
executeFunctions.getNodeParameter.calledWith('additionalFields', 0).mockReturnValue({});
|
||||
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue({
|
||||
feed: {
|
||||
entry: [
|
||||
{
|
||||
id: '1',
|
||||
content: { [SPLUNK.DICT]: { [SPLUNK.KEY]: [{ $: { name: 'test' }, _: 'test1' }] } },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const responseData = await user.create.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/services/authentication/users',
|
||||
{ name: 'John Doe', password: 'password', roles: ['role1', 'role2'] },
|
||||
);
|
||||
|
||||
expect(responseData).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
test: 'test1',
|
||||
entryUrl: '1',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('deleteUser operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.mockReturnValue('12345');
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue({});
|
||||
const responseData = await user.deleteUser.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/services/authentication/users/12345',
|
||||
);
|
||||
expect(responseData).toEqual({ success: true });
|
||||
});
|
||||
|
||||
test('get operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('userId', 0).mockReturnValue('12345');
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await user.get.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/authentication/users/12345',
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('getAll operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter.calledWith('returnAll', 0).mockReturnValue(true);
|
||||
|
||||
(transport.splunkApiJsonRequest as jest.Mock).mockReturnValue([{ test: 'test' }]);
|
||||
const responseData = await user.getAll.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiJsonRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/services/authentication/users',
|
||||
{},
|
||||
{ count: 0 },
|
||||
);
|
||||
expect(responseData).toEqual([{ test: 'test' }]);
|
||||
});
|
||||
|
||||
test('update operation', async () => {
|
||||
const executeFunctions = mock<IExecuteFunctions>();
|
||||
executeFunctions.getNodeParameter
|
||||
.calledWith('updateFields', 0)
|
||||
.mockReturnValue({ roles: ['role1', 'role2'], email: 'testW@example.com' });
|
||||
executeFunctions.getNodeParameter.calledWith('userId', 0).mockReturnValue('12345');
|
||||
|
||||
(transport.splunkApiRequest as jest.Mock).mockReturnValue(
|
||||
Promise.resolve({
|
||||
feed: {
|
||||
entry: [
|
||||
{
|
||||
id: '1',
|
||||
content: { [SPLUNK.DICT]: { [SPLUNK.KEY]: [{ $: { name: 'test' }, _: 'test1' }] } },
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const responseData = await user.update.execute.call(executeFunctions, 0);
|
||||
expect(transport.splunkApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/services/authentication/users/12345',
|
||||
{ email: 'testW@example.com', roles: ['role1', 'role2'] },
|
||||
);
|
||||
|
||||
expect(responseData).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
test: 'test1',
|
||||
entryUrl: '1',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user