|
| 1 | +import type { IExecuteFunctions } from 'n8n-workflow'; |
| 2 | +import { userOperation } from './UserOperation'; |
| 3 | +import * as GenericFunctions from './GenericFunctions'; |
| 4 | + |
| 5 | +describe('UserOperation', () => { |
| 6 | + const mockExecuteFunctions = { |
| 7 | + getNodeParameter: jest.fn(), |
| 8 | + helpers: { |
| 9 | + constructExecutionMetaData: jest.fn().mockImplementation((data) => data), |
| 10 | + returnJsonArray: jest.fn().mockImplementation((data) => data), |
| 11 | + }, |
| 12 | + } as unknown as IExecuteFunctions & { |
| 13 | + getNodeParameter: jest.Mock; |
| 14 | + helpers: { |
| 15 | + constructExecutionMetaData: jest.Mock; |
| 16 | + returnJsonArray: jest.Mock; |
| 17 | + }; |
| 18 | + }; |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + jest.clearAllMocks(); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('getQueues', () => { |
| 25 | + it('should retrieve queues for a user', async () => { |
| 26 | + const index = 0; |
| 27 | + const userId = 'test-user-id'; |
| 28 | + const returnAll = true; |
| 29 | + const response = [{ id: 'queue-1', name: 'Queue 1' }]; |
| 30 | + |
| 31 | + mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => { |
| 32 | + if (paramName === 'operation') return 'getQueues'; |
| 33 | + if (paramName === 'userId') return userId; |
| 34 | + if (paramName === 'returnAll') return returnAll; |
| 35 | + return undefined; |
| 36 | + }); |
| 37 | + |
| 38 | + jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response); |
| 39 | + |
| 40 | + await userOperation.call(mockExecuteFunctions, index); |
| 41 | + |
| 42 | + expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith( |
| 43 | + 'entities', |
| 44 | + 'GET', |
| 45 | + `/api/v2/users/${userId}/queues`, |
| 46 | + {}, |
| 47 | + {}, |
| 48 | + 0, |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should retrieve queues for a user with limit', async () => { |
| 53 | + const index = 0; |
| 54 | + const userId = 'test-user-id'; |
| 55 | + const returnAll = false; |
| 56 | + const limit = 5; |
| 57 | + const response = [{ id: 'queue-1', name: 'Queue 1' }]; |
| 58 | + |
| 59 | + mockExecuteFunctions.getNodeParameter.mockImplementation((paramName: string) => { |
| 60 | + if (paramName === 'operation') return 'getQueues'; |
| 61 | + if (paramName === 'userId') return userId; |
| 62 | + if (paramName === 'returnAll') return returnAll; |
| 63 | + if (paramName === 'limit') return limit; |
| 64 | + return undefined; |
| 65 | + }); |
| 66 | + |
| 67 | + jest.spyOn(GenericFunctions, 'genesysCloudApiRequestAllItems').mockResolvedValue(response); |
| 68 | + |
| 69 | + await userOperation.call(mockExecuteFunctions, index); |
| 70 | + |
| 71 | + expect(GenericFunctions.genesysCloudApiRequestAllItems).toHaveBeenCalledWith( |
| 72 | + 'entities', |
| 73 | + 'GET', |
| 74 | + `/api/v2/users/${userId}/queues`, |
| 75 | + {}, |
| 76 | + {}, |
| 77 | + limit, |
| 78 | + ); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments