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,55 @@
|
||||
import * as deleteFile from '../../../actions/file/delete.operation';
|
||||
import { ERROR_MESSAGES } from '../../../constants';
|
||||
import * as transport from '../../../transport';
|
||||
import { createMockExecuteFunction } from '../helpers';
|
||||
|
||||
const baseNodeParameters = {
|
||||
resource: 'file',
|
||||
operation: 'deleteFile',
|
||||
sessionId: 'test-session-123',
|
||||
fileId: 'file-123',
|
||||
};
|
||||
|
||||
jest.mock('../../../transport', () => {
|
||||
const originalModule = jest.requireActual<typeof transport>('../../../transport');
|
||||
return {
|
||||
...originalModule,
|
||||
apiRequest: jest.fn().mockResolvedValue({}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Airtop, delete file operation', () => {
|
||||
afterAll(() => {
|
||||
jest.unmock('../../../transport');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should delete file successfully', async () => {
|
||||
const result = await deleteFile.execute.call(createMockExecuteFunction(baseNodeParameters), 0);
|
||||
|
||||
expect(transport.apiRequest).toHaveBeenCalledWith('DELETE', '/files/file-123');
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
data: {
|
||||
message: 'File deleted successfully',
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should throw error when fileId is empty', async () => {
|
||||
const nodeParameters = {
|
||||
...baseNodeParameters,
|
||||
fileId: '',
|
||||
};
|
||||
|
||||
await expect(
|
||||
deleteFile.execute.call(createMockExecuteFunction(nodeParameters), 0),
|
||||
).rejects.toThrow(ERROR_MESSAGES.REQUIRED_PARAMETER.replace('{{field}}', 'File ID'));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
import * as get from '../../../actions/file/get.operation';
|
||||
import { ERROR_MESSAGES } from '../../../constants';
|
||||
import * as transport from '../../../transport';
|
||||
import { createMockExecuteFunction } from '../helpers';
|
||||
|
||||
const baseNodeParameters = {
|
||||
resource: 'file',
|
||||
operation: 'get',
|
||||
sessionId: 'test-session-123',
|
||||
fileId: 'file-123',
|
||||
};
|
||||
|
||||
const mockFileResponse = {
|
||||
data: {
|
||||
id: 'file-123',
|
||||
fileName: 'test-file.pdf',
|
||||
status: 'available',
|
||||
downloadUrl: 'https://api.airtop.com/files/file-123/download',
|
||||
},
|
||||
};
|
||||
|
||||
const mockBinaryBuffer = Buffer.from('mock-binary-data');
|
||||
|
||||
const mockPreparedBinaryData = {
|
||||
mimeType: 'application/pdf',
|
||||
fileType: 'pdf',
|
||||
fileName: 'test-file.pdf',
|
||||
data: 'mock-base64-data',
|
||||
};
|
||||
|
||||
jest.mock('../../../transport', () => {
|
||||
const originalModule = jest.requireActual<typeof transport>('../../../transport');
|
||||
return {
|
||||
...originalModule,
|
||||
apiRequest: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Airtop, get file operation', () => {
|
||||
afterAll(() => {
|
||||
jest.unmock('../../../transport');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should get file details successfully', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockFileResponse);
|
||||
|
||||
const result = await get.execute.call(createMockExecuteFunction(baseNodeParameters), 0);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith('GET', '/files/file-123');
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
...mockFileResponse,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should output file with binary data when specified', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockFileResponse);
|
||||
|
||||
const nodeParameters = {
|
||||
...baseNodeParameters,
|
||||
outputBinaryFile: true,
|
||||
};
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction(nodeParameters);
|
||||
|
||||
mockExecuteFunction.helpers.httpRequest = jest.fn().mockResolvedValue(mockBinaryBuffer);
|
||||
mockExecuteFunction.helpers.prepareBinaryData = jest
|
||||
.fn()
|
||||
.mockResolvedValue(mockPreparedBinaryData);
|
||||
|
||||
const result = await get.execute.call(mockExecuteFunction, 0);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith('GET', '/files/file-123');
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
...mockFileResponse,
|
||||
},
|
||||
binary: { data: mockPreparedBinaryData },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should throw error when fileId is empty', async () => {
|
||||
const nodeParameters = {
|
||||
...baseNodeParameters,
|
||||
fileId: '',
|
||||
};
|
||||
|
||||
await expect(get.execute.call(createMockExecuteFunction(nodeParameters), 0)).rejects.toThrow(
|
||||
ERROR_MESSAGES.REQUIRED_PARAMETER.replace('{{field}}', 'File ID'),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
import * as getMany from '../../../actions/file/getMany.operation';
|
||||
import * as transport from '../../../transport';
|
||||
import { createMockExecuteFunction } from '../helpers';
|
||||
|
||||
const baseNodeParameters = {
|
||||
resource: 'file',
|
||||
operation: 'getMany',
|
||||
sessionId: 'test-session-123',
|
||||
returnAll: true,
|
||||
outputSingleItem: true,
|
||||
};
|
||||
|
||||
const mockFilesResponse = {
|
||||
data: {
|
||||
files: [
|
||||
{
|
||||
id: 'file-123',
|
||||
name: 'document1.pdf',
|
||||
size: 12345,
|
||||
contentType: 'application/pdf',
|
||||
createdAt: '2023-06-15T10:30:00Z',
|
||||
},
|
||||
{
|
||||
id: 'file-456',
|
||||
name: 'image1.jpg',
|
||||
size: 54321,
|
||||
contentType: 'image/jpeg',
|
||||
createdAt: '2023-06-16T11:45:00Z',
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
hasMore: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockPaginatedResponse = {
|
||||
data: {
|
||||
files: [mockFilesResponse.data.files[0]],
|
||||
pagination: {
|
||||
hasMore: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('../../../transport', () => {
|
||||
const originalModule = jest.requireActual<typeof transport>('../../../transport');
|
||||
return {
|
||||
...originalModule,
|
||||
apiRequest: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Airtop, get many files operation', () => {
|
||||
afterAll(() => {
|
||||
jest.unmock('../../../transport');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should get all files successfully', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockFilesResponse);
|
||||
|
||||
const result = await getMany.execute.call(createMockExecuteFunction(baseNodeParameters), 0);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/files',
|
||||
{},
|
||||
{
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
sessionIds: '',
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
...mockFilesResponse,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle limited results', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockPaginatedResponse);
|
||||
|
||||
const nodeParameters = {
|
||||
...baseNodeParameters,
|
||||
returnAll: false,
|
||||
limit: 1,
|
||||
};
|
||||
|
||||
const result = await getMany.execute.call(createMockExecuteFunction(nodeParameters), 0);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/files',
|
||||
{},
|
||||
{
|
||||
limit: 1,
|
||||
sessionIds: '',
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
...mockPaginatedResponse,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,389 @@
|
||||
import * as helpers from '../../../actions/file/helpers';
|
||||
import * as GenericFunctions from '../../../GenericFunctions';
|
||||
import * as transport from '../../../transport';
|
||||
import { createMockExecuteFunction } from '../helpers';
|
||||
|
||||
const mockFileCreateResponse = {
|
||||
data: {
|
||||
id: 'file-123',
|
||||
uploadUrl: 'https://upload.example.com/url',
|
||||
},
|
||||
};
|
||||
|
||||
// Mock the transport and other dependencies
|
||||
jest.mock('../../../transport', () => {
|
||||
const originalModule = jest.requireActual<typeof transport>('../../../transport');
|
||||
return {
|
||||
...originalModule,
|
||||
apiRequest: jest.fn(async () => {}),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('../../../GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual<typeof GenericFunctions>('../../../GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
waitForSessionEvent: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Airtop file helpers', () => {
|
||||
afterAll(() => {
|
||||
jest.unmock('../../../transport');
|
||||
jest.unmock('../../../GenericFunctions');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(transport.apiRequest as jest.Mock).mockReset();
|
||||
(GenericFunctions.waitForSessionEvent as jest.Mock).mockReset();
|
||||
});
|
||||
|
||||
describe('requestAllFiles', () => {
|
||||
it('should request all files with pagination', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
const mockFilesResponse1 = {
|
||||
data: {
|
||||
files: [{ id: 'file-1' }, { id: 'file-2' }],
|
||||
pagination: { hasMore: true },
|
||||
},
|
||||
};
|
||||
|
||||
const mockFilesResponse2 = {
|
||||
data: {
|
||||
files: [{ id: 'file-3' }],
|
||||
pagination: { hasMore: false },
|
||||
},
|
||||
};
|
||||
|
||||
apiRequestMock
|
||||
.mockResolvedValueOnce(mockFilesResponse1)
|
||||
.mockResolvedValueOnce(mockFilesResponse2);
|
||||
|
||||
const result = await helpers.requestAllFiles.call(
|
||||
createMockExecuteFunction({}),
|
||||
'session-123',
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledTimes(2);
|
||||
expect(apiRequestMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'GET',
|
||||
'/files',
|
||||
{},
|
||||
{ offset: 0, limit: 100, sessionIds: 'session-123' },
|
||||
);
|
||||
expect(apiRequestMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'GET',
|
||||
'/files',
|
||||
{},
|
||||
{ offset: 100, limit: 100, sessionIds: 'session-123' },
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
data: {
|
||||
files: [{ id: 'file-1' }, { id: 'file-2' }, { id: 'file-3' }],
|
||||
pagination: { hasMore: false },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty response', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
const mockEmptyResponse = {
|
||||
data: {
|
||||
files: [],
|
||||
pagination: { hasMore: false },
|
||||
},
|
||||
};
|
||||
|
||||
apiRequestMock.mockResolvedValueOnce(mockEmptyResponse);
|
||||
|
||||
const result = await helpers.requestAllFiles.call(
|
||||
createMockExecuteFunction({}),
|
||||
'session-123',
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual({
|
||||
data: {
|
||||
files: [],
|
||||
pagination: { hasMore: false },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pollFileUntilAvailable', () => {
|
||||
it('should poll until file is available', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock
|
||||
.mockResolvedValueOnce({ data: { status: 'uploading' } })
|
||||
.mockResolvedValueOnce({ data: { status: 'available' } });
|
||||
|
||||
const pollPromise = helpers.pollFileUntilAvailable.call(
|
||||
createMockExecuteFunction({}),
|
||||
'file-123',
|
||||
1000,
|
||||
0,
|
||||
);
|
||||
|
||||
const result = await pollPromise;
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledTimes(2);
|
||||
expect(apiRequestMock).toHaveBeenCalledWith('GET', '/files/file-123');
|
||||
expect(result).toBe('file-123');
|
||||
});
|
||||
|
||||
it('should throw timeout error if file never becomes available', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValue({ data: { status: 'processing' } });
|
||||
|
||||
const promise = helpers.pollFileUntilAvailable.call(
|
||||
createMockExecuteFunction({}),
|
||||
'file-123',
|
||||
0,
|
||||
);
|
||||
|
||||
await expect(promise).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createAndUploadFile', () => {
|
||||
it('should create file entry, upload file, and poll until available', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock
|
||||
.mockResolvedValueOnce(mockFileCreateResponse)
|
||||
.mockResolvedValueOnce({ data: { status: 'available' } });
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
const mockHttpRequest = jest.fn().mockResolvedValueOnce({});
|
||||
mockExecuteFunction.helpers.httpRequest = mockHttpRequest;
|
||||
const pollingFunctionMock = jest.fn().mockResolvedValueOnce(mockFileCreateResponse.data.id);
|
||||
|
||||
const result = await helpers.createAndUploadFile.call(
|
||||
mockExecuteFunction,
|
||||
'test.png',
|
||||
Buffer.from('test'),
|
||||
'customer_upload',
|
||||
pollingFunctionMock,
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith('POST', '/files', {
|
||||
fileName: 'test.png',
|
||||
fileType: 'customer_upload',
|
||||
});
|
||||
|
||||
expect(mockHttpRequest).toHaveBeenCalledWith({
|
||||
method: 'PUT',
|
||||
url: mockFileCreateResponse.data.uploadUrl,
|
||||
body: Buffer.from('test'),
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
},
|
||||
});
|
||||
|
||||
expect(pollingFunctionMock).toHaveBeenCalledWith(mockFileCreateResponse.data.id);
|
||||
|
||||
expect(result).toBe(mockFileCreateResponse.data.id);
|
||||
});
|
||||
|
||||
it('should throw error if file creation response is missing id or upload URL', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce({});
|
||||
|
||||
await expect(
|
||||
helpers.createAndUploadFile.call(
|
||||
createMockExecuteFunction({}),
|
||||
'test.pdf',
|
||||
Buffer.from('test'),
|
||||
'customer_upload',
|
||||
),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('waitForFileInSession', () => {
|
||||
it('should resolve when file_upload_status event with available status is received', async () => {
|
||||
const waitForSessionEventMock = GenericFunctions.waitForSessionEvent as jest.Mock;
|
||||
const mockEvent = {
|
||||
event: 'file_upload_status',
|
||||
status: 'available',
|
||||
fileId: 'file-123',
|
||||
};
|
||||
waitForSessionEventMock.mockResolvedValueOnce(mockEvent);
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
|
||||
await helpers.waitForFileInSession.call(mockExecuteFunction, 'session-123', 'file-123', 1000);
|
||||
|
||||
expect(waitForSessionEventMock).toHaveBeenCalledTimes(1);
|
||||
expect(waitForSessionEventMock).toHaveBeenCalledWith(
|
||||
'session-123',
|
||||
expect.any(Function),
|
||||
1000,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error when uploading a file with invalid file format', async () => {
|
||||
const waitForSessionEventMock = GenericFunctions.waitForSessionEvent as jest.Mock;
|
||||
const mockEvent = {
|
||||
event: 'file_upload_status',
|
||||
status: 'upload_failed',
|
||||
fileId: 'file-123',
|
||||
eventData: {
|
||||
error: 'Upload failed due to invalid file format',
|
||||
},
|
||||
};
|
||||
waitForSessionEventMock.mockResolvedValueOnce(mockEvent);
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
|
||||
await expect(
|
||||
helpers.waitForFileInSession.call(mockExecuteFunction, 'session-123', 'file-123', 1000),
|
||||
).rejects.toMatchObject({ description: 'Upload failed due to invalid file format' });
|
||||
});
|
||||
|
||||
it('should throw error when upload_failed status is received', async () => {
|
||||
const waitForSessionEventMock = GenericFunctions.waitForSessionEvent as jest.Mock;
|
||||
const mockEvent = {
|
||||
fileId: 'file-123',
|
||||
event: 'file_upload_status',
|
||||
status: 'upload_failed',
|
||||
eventData: {
|
||||
error: 'Upload failed for File ID: file-123',
|
||||
},
|
||||
};
|
||||
waitForSessionEventMock.mockResolvedValueOnce(mockEvent);
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
|
||||
// the service should throw an error description 'Upload failed for File ID: file-123'
|
||||
await expect(
|
||||
helpers.waitForFileInSession.call(mockExecuteFunction, 'session-123', 'file-123', 1000),
|
||||
).rejects.toMatchObject({ description: 'Upload failed for File ID: file-123' });
|
||||
});
|
||||
|
||||
it('should timeout if no matching event is received', async () => {
|
||||
const waitForSessionEventMock = GenericFunctions.waitForSessionEvent as jest.Mock;
|
||||
waitForSessionEventMock.mockRejectedValueOnce(new Error('Timeout reached'));
|
||||
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
|
||||
await expect(
|
||||
helpers.waitForFileInSession.call(mockExecuteFunction, 'session-123', 'file-123', 100),
|
||||
).rejects.toThrow('Timeout reached');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pushFileToSession', () => {
|
||||
it('should push file to session and wait', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
const mockFileId = 'file-123';
|
||||
const mockSessionId = 'session-123';
|
||||
apiRequestMock.mockResolvedValueOnce({});
|
||||
|
||||
// Mock waitForFileInSession
|
||||
const waitForFileInSessionMock = jest.fn().mockResolvedValueOnce({});
|
||||
|
||||
// Call the function
|
||||
await helpers.pushFileToSession.call(
|
||||
createMockExecuteFunction({}),
|
||||
mockFileId,
|
||||
mockSessionId,
|
||||
waitForFileInSessionMock,
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith('POST', `/files/${mockFileId}/push`, {
|
||||
sessionIds: [mockSessionId],
|
||||
});
|
||||
|
||||
expect(waitForFileInSessionMock).toHaveBeenCalledWith(mockSessionId, mockFileId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('triggerFileInput', () => {
|
||||
it('should trigger file input in window', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce({});
|
||||
const mockFileId = 'file-123';
|
||||
const mockWindowId = 'window-123';
|
||||
const mockSessionId = 'session-123';
|
||||
|
||||
await helpers.triggerFileInput.call(createMockExecuteFunction({}), {
|
||||
fileId: mockFileId,
|
||||
windowId: mockWindowId,
|
||||
sessionId: mockSessionId,
|
||||
elementDescription: 'test',
|
||||
includeHiddenElements: false,
|
||||
});
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
`/sessions/${mockSessionId}/windows/${mockWindowId}/file-input`,
|
||||
{
|
||||
fileId: mockFileId,
|
||||
elementDescription: 'test',
|
||||
includeHiddenElements: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createFileBuffer', () => {
|
||||
it('should create buffer from URL', async () => {
|
||||
const mockUrl = 'https://example.com/file.pdf';
|
||||
const mockBuffer = [1, 2, 3];
|
||||
|
||||
// Mock http request
|
||||
const mockHttpRequest = jest.fn().mockResolvedValueOnce(mockBuffer);
|
||||
|
||||
// Create mock execute function with http request helper
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
mockExecuteFunction.helpers.httpRequest = mockHttpRequest;
|
||||
|
||||
const result = await helpers.createFileBuffer.call(mockExecuteFunction, 'url', mockUrl, 0);
|
||||
|
||||
expect(mockHttpRequest).toHaveBeenCalledWith({
|
||||
url: mockUrl,
|
||||
json: false,
|
||||
encoding: 'arraybuffer',
|
||||
});
|
||||
expect(result).toBe(mockBuffer);
|
||||
});
|
||||
|
||||
it('should create buffer from binary data', async () => {
|
||||
const mockBinaryPropertyName = 'data';
|
||||
const mockBuffer = [1, 2, 3];
|
||||
|
||||
// Mock getBinaryDataBuffer
|
||||
const mockGetBinaryDataBuffer = jest.fn().mockResolvedValue(mockBuffer);
|
||||
|
||||
// Create mock execute function with getBinaryDataBuffer helper
|
||||
const mockExecuteFunction = createMockExecuteFunction({});
|
||||
mockExecuteFunction.helpers.getBinaryDataBuffer = mockGetBinaryDataBuffer;
|
||||
|
||||
const result = await helpers.createFileBuffer.call(
|
||||
mockExecuteFunction,
|
||||
'binary',
|
||||
mockBinaryPropertyName,
|
||||
0,
|
||||
);
|
||||
|
||||
expect(mockGetBinaryDataBuffer).toHaveBeenCalledWith(0, mockBinaryPropertyName);
|
||||
expect(result).toBe(mockBuffer);
|
||||
});
|
||||
|
||||
it('should throw error for unsupported source type', async () => {
|
||||
await expect(
|
||||
helpers.createFileBuffer.call(
|
||||
createMockExecuteFunction({}),
|
||||
'invalid-source',
|
||||
'test-value',
|
||||
0,
|
||||
),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user