feat(Google Drive Node): Overhaul (#5941)
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as copy from '../../../../v2/actions/file/copy.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file copy', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'copy',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test01.png',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
name: 'copyImage.png',
|
||||
sameFolder: false,
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 3',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
options: {
|
||||
copyRequiresWriterPermission: true,
|
||||
description: 'image copy',
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await copy.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toBeCalledWith(
|
||||
'POST',
|
||||
'/drive/v3/files/fileIDxxxxxx/copy',
|
||||
{
|
||||
copyRequiresWriterPermission: true,
|
||||
description: 'image copy',
|
||||
name: 'copyImage.png',
|
||||
parents: ['folderIDxxxxxx'],
|
||||
},
|
||||
{
|
||||
supportsAllDrives: true,
|
||||
corpora: 'allDrives',
|
||||
includeItemsFromAllDrives: true,
|
||||
spaces: 'appDataFolder, drive',
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as createFromText from '../../../../v2/actions/file/createFromText.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file createFromText', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'createFromText',
|
||||
content: 'hello drive!',
|
||||
name: 'helloDrive.txt',
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 3',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
options: {
|
||||
appPropertiesUi: {
|
||||
appPropertyValues: [
|
||||
{
|
||||
key: 'appKey1',
|
||||
value: 'appValue1',
|
||||
},
|
||||
],
|
||||
},
|
||||
propertiesUi: {
|
||||
propertyValues: [
|
||||
{
|
||||
key: 'prop1',
|
||||
value: 'value1',
|
||||
},
|
||||
{
|
||||
key: 'prop2',
|
||||
value: 'value2',
|
||||
},
|
||||
],
|
||||
},
|
||||
keepRevisionForever: true,
|
||||
ocrLanguage: 'en',
|
||||
useContentAsIndexableText: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await createFromText.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/upload/drive/v3/files',
|
||||
'\n\t\t\n--XXXXXX\t\t\nContent-Type: application/json; charset=UTF-8\t\t\n\n{"name":"helloDrive.txt","parents":["folderIDxxxxxx"],"mimeType":"text/plain","properties":{"prop1":"value1","prop2":"value2"},"appProperties":{"appKey1":"appValue1"}}\t\t\n--XXXXXX\t\t\nContent-Type: text/plain\t\t\nContent-Transfer-Encoding: base64\t\t\n\nhello drive!\t\t\n--XXXXXX--',
|
||||
{
|
||||
corpora: 'allDrives',
|
||||
includeItemsFromAllDrives: true,
|
||||
keepRevisionForever: true,
|
||||
ocrLanguage: 'en',
|
||||
spaces: 'appDataFolder, drive',
|
||||
supportsAllDrives: true,
|
||||
uploadType: 'multipart',
|
||||
useContentAsIndexableText: true,
|
||||
},
|
||||
undefined,
|
||||
{ headers: { 'Content-Length': 12, 'Content-Type': 'multipart/related; boundary=XXXXXX' } },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as deleteFile from '../../../../v2/actions/file/deleteFile.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file deleteFile', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'deleteFile',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test.txt',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
options: {
|
||||
deletePermanently: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await deleteFile.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
undefined,
|
||||
{ supportsAllDrives: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as download from '../../../../v2/actions/file/download.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file download', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'deleteFile',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test.txt',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
options: {
|
||||
deletePermanently: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await download.execute.call(fakeExecuteFunction, 0, { json: {} });
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(2);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
{},
|
||||
{ fields: 'mimeType,name', supportsTeamDrives: true },
|
||||
);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
{},
|
||||
{ alt: 'media' },
|
||||
undefined,
|
||||
{ encoding: null, json: false, resolveWithFullResponse: true, useStream: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as move from '../../../../v2/actions/file/move.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function (method: string) {
|
||||
if (method === 'GET') {
|
||||
return {
|
||||
parents: ['parentFolderIDxxxxxx'],
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file move', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'move',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test.txt',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder1',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await move.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(2);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
undefined,
|
||||
{
|
||||
corpora: 'allDrives',
|
||||
fields: 'parents',
|
||||
includeItemsFromAllDrives: true,
|
||||
spaces: 'appDataFolder, drive',
|
||||
supportsAllDrives: true,
|
||||
},
|
||||
);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
undefined,
|
||||
{
|
||||
addParents: 'folderIDxxxxxx',
|
||||
removeParents: 'parentFolderIDxxxxxx',
|
||||
corpora: 'allDrives',
|
||||
includeItemsFromAllDrives: true,
|
||||
spaces: 'appDataFolder, drive',
|
||||
supportsAllDrives: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as share from '../../../../v2/actions/file/share.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file share', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'share',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test.txt',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
permissionsUi: {
|
||||
permissionsValues: {
|
||||
role: 'owner',
|
||||
type: 'user',
|
||||
emailAddress: 'user@gmail.com',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
emailMessage: 'some message',
|
||||
moveToNewOwnersRoot: true,
|
||||
sendNotificationEmail: true,
|
||||
transferOwnership: true,
|
||||
useDomainAdminAccess: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await share.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/drive/v3/files/fileIDxxxxxx/permissions',
|
||||
{ emailAddress: 'user@gmail.com', role: 'owner', type: 'user' },
|
||||
{
|
||||
emailMessage: 'some message',
|
||||
moveToNewOwnersRoot: true,
|
||||
sendNotificationEmail: true,
|
||||
supportsAllDrives: true,
|
||||
transferOwnership: true,
|
||||
useDomainAdminAccess: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as update from '../../../../v2/actions/file/update.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function () {
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file update', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
operation: 'update',
|
||||
fileId: {
|
||||
__rl: true,
|
||||
value: 'fileIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'test.txt',
|
||||
cachedResultUrl: 'https://drive.google.com/file/d/fileIDxxxxxx/view?usp=drivesdk',
|
||||
},
|
||||
newUpdatedFileName: 'test2.txt',
|
||||
options: {
|
||||
keepRevisionForever: true,
|
||||
ocrLanguage: 'en',
|
||||
useContentAsIndexableText: true,
|
||||
fields: ['hasThumbnail', 'starred'],
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await update.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/drive/v3/files/fileIDxxxxxx',
|
||||
{ name: 'test2.txt' },
|
||||
{
|
||||
fields: 'hasThumbnail, starred',
|
||||
keepRevisionForever: true,
|
||||
ocrLanguage: 'en',
|
||||
supportsAllDrives: true,
|
||||
useContentAsIndexableText: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as upload from '../../../../v2/actions/file/upload.operation';
|
||||
|
||||
import * as transport from '../../../../v2/transport';
|
||||
import * as utils from '../../../../v2/helpers/utils';
|
||||
|
||||
import { createMockExecuteFunction, driveNode } from '../helpers';
|
||||
|
||||
jest.mock('../../../../v2/transport', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/transport');
|
||||
return {
|
||||
...originalModule,
|
||||
googleApiRequest: jest.fn(async function (method: string) {
|
||||
if (method === 'POST') {
|
||||
return {
|
||||
headers: { location: 'someLocation' },
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('../../../../v2/helpers/utils', () => {
|
||||
const originalModule = jest.requireActual('../../../../v2/helpers/utils');
|
||||
return {
|
||||
...originalModule,
|
||||
getItemBinaryData: jest.fn(async function () {
|
||||
return {
|
||||
contentLength: '123',
|
||||
fileContent: 'Hello Drive!',
|
||||
originalFilename: 'original.txt',
|
||||
mimeType: 'text/plain',
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: file upload', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
jest.unmock('../../../../v2/helpers/utils');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
name: 'newFile.txt',
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 3',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
options: {
|
||||
simplifyOutput: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await upload.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(2);
|
||||
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/upload/drive/v3/files',
|
||||
undefined,
|
||||
{ uploadType: 'resumable' },
|
||||
undefined,
|
||||
{ resolveWithFullResponse: true },
|
||||
);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/drive/v3/files/undefined',
|
||||
{ mimeType: 'text/plain', name: 'newFile.txt', originalFilename: 'original.txt' },
|
||||
{
|
||||
addParents: 'folderIDxxxxxx',
|
||||
supportsAllDrives: true,
|
||||
corpora: 'allDrives',
|
||||
includeItemsFromAllDrives: true,
|
||||
spaces: 'appDataFolder, drive',
|
||||
},
|
||||
);
|
||||
|
||||
expect(utils.getItemBinaryData).toBeCalledTimes(1);
|
||||
expect(utils.getItemBinaryData).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user