mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
Co-authored-by: Eugene <eugene@n8n.io> Co-authored-by: Daria <daria.staferova@n8n.io> Co-authored-by: Alex Grozav <alex@grozav.com> Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: Charlie Kolb <charlie@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: shortstacked <declan@n8n.io> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Csaba Tuncsik <csaba@n8n.io> Co-authored-by: Jaakko Husso <jaakko@n8n.io> Co-authored-by: Raúl Gómez Morales <raul00gm@gmail.com> Co-authored-by: Suguru Inoue <suguru@n8n.io> Co-authored-by: Milorad FIlipović <milorad@n8n.io> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: RomanDavydchuk <roman.davydchuk@n8n.io> Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Ricardo Espinoza <ricardo@n8n.io> Co-authored-by: Dana <152518854+dana-gill@users.noreply.github.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Mutasem Aldmour <mutasem@n8n.io>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import * as waitForDownload from '../../../actions/session/waitForDownload.operation';
|
|
import { ERROR_MESSAGES } from '../../../constants';
|
|
import * as GenericFunctions from '../../../GenericFunctions';
|
|
import { createMockExecuteFunction } from '../helpers';
|
|
|
|
jest.mock('../../../GenericFunctions', () => {
|
|
const originalModule = jest.requireActual<typeof GenericFunctions>('../../../GenericFunctions');
|
|
return {
|
|
...originalModule,
|
|
waitForSessionEvent: jest.fn(),
|
|
};
|
|
});
|
|
|
|
describe('Test Airtop, session waitForDownload operation', () => {
|
|
afterAll(() => {
|
|
jest.unmock('../../../GenericFunctions');
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should wait for download successfully', async () => {
|
|
const mockEvent = {
|
|
event: 'file_status',
|
|
status: 'available',
|
|
fileId: 'test-file-123',
|
|
downloadUrl: 'https://example.com/download/test-file-123',
|
|
};
|
|
|
|
(GenericFunctions.waitForSessionEvent as jest.Mock).mockResolvedValue(mockEvent);
|
|
|
|
const nodeParameters = {
|
|
resource: 'session',
|
|
operation: 'waitForDownload',
|
|
sessionId: 'test-session-123',
|
|
timeout: 1,
|
|
};
|
|
|
|
const result = await waitForDownload.execute.call(createMockExecuteFunction(nodeParameters), 0);
|
|
|
|
expect(GenericFunctions.waitForSessionEvent).toHaveBeenCalledTimes(1);
|
|
expect(GenericFunctions.waitForSessionEvent).toHaveBeenCalledWith(
|
|
'test-session-123',
|
|
expect.any(Function),
|
|
1,
|
|
);
|
|
|
|
expect(result).toEqual([
|
|
{
|
|
json: {
|
|
sessionId: 'test-session-123',
|
|
data: {
|
|
fileId: 'test-file-123',
|
|
downloadUrl: 'https://example.com/download/test-file-123',
|
|
},
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should throw error when sessionId is empty', async () => {
|
|
const nodeParameters = {
|
|
resource: 'session',
|
|
operation: 'waitForDownload',
|
|
sessionId: '',
|
|
};
|
|
|
|
await expect(
|
|
waitForDownload.execute.call(createMockExecuteFunction(nodeParameters), 0),
|
|
).rejects.toThrow(ERROR_MESSAGES.SESSION_ID_REQUIRED);
|
|
});
|
|
|
|
it('should throw error when sessionId is whitespace', async () => {
|
|
const nodeParameters = {
|
|
resource: 'session',
|
|
operation: 'waitForDownload',
|
|
sessionId: ' ',
|
|
};
|
|
|
|
await expect(
|
|
waitForDownload.execute.call(createMockExecuteFunction(nodeParameters), 0),
|
|
).rejects.toThrow(ERROR_MESSAGES.SESSION_ID_REQUIRED);
|
|
});
|
|
});
|