Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nodes/GenesysCloud/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function genesysCloudApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
method: IHttpRequestMethods,
resource: string,
body: IDataObject = {},
body: IDataObject | IDataObject[] = {},
query: IDataObject = {},
) {
const credentials = await this.getCredentials('genesysCloudPlatformApiOAuth2Api');
Expand Down
25 changes: 24 additions & 1 deletion nodes/GenesysCloud/QueueDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export const queueOperations: INodeProperties[] = [
},
},
options: [
{
name: 'Add Members',
value: 'addMembers',
description: 'Add members to a queue',
action: 'Add members to a queue',
},
{
name: 'Create',
value: 'create',
Expand Down Expand Up @@ -290,7 +296,7 @@ export const queueFields: INodeProperties[] = [
displayOptions: {
show: {
resource: ['queue'],
operation: ['get', 'getMembers'],
operation: ['get', 'getMembers', 'addMembers'],
},
},
description: 'ID of queue that needs to be fetched',
Expand Down Expand Up @@ -546,4 +552,21 @@ export const queueFields: INodeProperties[] = [
},
],
},
/* -------------------------------------------------------------------------- */
/* queue:addMembers */
/* -------------------------------------------------------------------------- */
{
displayName: 'User IDs',
name: 'userIds',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['queue'],
operation: ['addMembers'],
},
},
description: 'Comma-separated list or Array of user IDs to add to the queue',
},
];
29 changes: 29 additions & 0 deletions nodes/GenesysCloud/QueueOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export async function queueOperation(
return getAll.call(this, index);
} else if (operation === 'getMembers') {
return getMembers.call(this, index);
} else if (operation === 'addMembers') {
return addMembers.call(this, index);
}

return [];
Expand Down Expand Up @@ -121,3 +123,30 @@ export async function getMembers(
{ itemData: { item: index } },
);
}

export async function addMembers(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const queueId = this.getNodeParameter('queueId', index) as string;
const userIds = this.getNodeParameter('userIds', index) as string | string[];

let members: IDataObject[] = [];
if (Array.isArray(userIds)) {
members = userIds.map((id) => ({ id: id.trim() }));
} else {
members = userIds.split(',').map((id) => ({ id: id.trim() }));
}

const responseData = await genesysCloudApiRequest.call(
this,
'POST',
`/api/v2/routing/queues/${queueId}/members`,
members,
);

return this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: index } },
);
}
12 changes: 9 additions & 3 deletions nodes/GenesysCloud/UserDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const userOperations: INodeProperties[] = [
description: 'Get many users',
action: 'Get many users',
},
{
name: 'Get Queues',
value: 'getQueues',
description: 'Get queues for a user',
action: 'Get queues for a user',
},
],
default: 'get',
},
Expand All @@ -42,7 +48,7 @@ export const userFields: INodeProperties[] = [
displayOptions: {
show: {
resource: ['user'],
operation: ['get'],
operation: ['get', 'getQueues'],
},
},
description: 'The ID of the user',
Expand All @@ -58,7 +64,7 @@ export const userFields: INodeProperties[] = [
displayOptions: {
show: {
resource: ['user'],
operation: ['getAll'],
operation: ['getAll', 'getQueues'],
},
},
default: false,
Expand All @@ -71,7 +77,7 @@ export const userFields: INodeProperties[] = [
displayOptions: {
show: {
resource: ['user'],
operation: ['getAll'],
operation: ['getAll', 'getQueues'],
returnAll: [false],
},
},
Expand Down
81 changes: 81 additions & 0 deletions nodes/GenesysCloud/UserOperation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { IExecuteFunctions } from 'n8n-workflow';
import { userOperation } from './UserOperation';
import * as GenericFunctions from './GenericFunctions';

describe('UserOperation', () => {
const mockExecuteFunctions = {
getNodeParameter: jest.fn(),
helpers: {
constructExecutionMetaData: jest.fn().mockImplementation((data) => data),
returnJsonArray: jest.fn().mockImplementation((data) => data),
},
} as unknown as IExecuteFunctions & {
getNodeParameter: jest.Mock;
helpers: {
constructExecutionMetaData: jest.Mock;
returnJsonArray: jest.Mock;
};
};

beforeEach(() => {
jest.clearAllMocks();
});

describe('getQueues', () => {
it('should retrieve queues for a user', async () => {
const index = 0;
const userId = 'test-user-id';
const returnAll = true;
const response = [{ id: 'queue-1', name: 'Queue 1' }];

mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => {
if (paramName === 'operation') return 'getQueues';
if (paramName === 'userId') return userId;
if (paramName === 'returnAll') return returnAll;
return undefined;
});

jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response);

await userOperation.call(mockExecuteFunctions, index);

expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith(
'entities',
'GET',
`/api/v2/users/${userId}/queues`,
{},
{},
0,
);
});

it('should retrieve queues for a user with limit', async () => {
const index = 0;
const userId = 'test-user-id';
const returnAll = false;
const limit = 5;
const response = [{ id: 'queue-1', name: 'Queue 1' }];

mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => {
if (paramName === 'operation') return 'getQueues';
if (paramName === 'userId') return userId;
if (paramName === 'returnAll') return returnAll;
if (paramName === 'limit') return limit;
return undefined;
});

jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response);

await userOperation.call(mockExecuteFunctions, index);

expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith(
'entities',
'GET',
`/api/v2/users/${userId}/queues`,
{},
{},
limit,
);
});
});
});
14 changes: 14 additions & 0 deletions nodes/GenesysCloud/UserOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ export async function userOperation(
qs,
limit,
);
} else if (operation === 'getQueues') {
const userId = this.getNodeParameter('userId', index) as string;
const returnAll = this.getNodeParameter('returnAll', index) as boolean;
const limit = returnAll ? 0 : (this.getNodeParameter('limit', index) as number);

responseData = await genesysCloudApiRequestAllItems.call(
this,
'entities',
'GET',
`/api/v2/users/${userId}/queues`,
{},
qs,
limit,
);
}

return this.helpers.constructExecutionMetaData(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@makingchatbots/n8n-nodes-genesys-cloud",
"version": "1.0.1",
"version": "1.0.2",
"description": "n8n node for interacting with Genesys Cloud's Platform API",
"license": "MIT",
"homepage": "https://makingchatbots.com",
Expand Down