mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-24 04:59:13 +00:00
feat(Google Drive Node): Overhaul (#5941)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as create from '../../../../v2/actions/folder/create.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: folder create', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'folder',
|
||||
name: 'testFolder 2',
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: 'root',
|
||||
mode: 'list',
|
||||
cachedResultName: 'root',
|
||||
cachedResultUrl: 'https://drive.google.com/drive',
|
||||
},
|
||||
options: {
|
||||
folderColorRgb: '#167D08',
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await create.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/drive/v3/files',
|
||||
{
|
||||
folderColorRgb: '#167D08',
|
||||
mimeType: 'application/vnd.google-apps.folder',
|
||||
name: 'testFolder 2',
|
||||
parents: ['root'],
|
||||
},
|
||||
{
|
||||
fields: undefined,
|
||||
includeItemsFromAllDrives: true,
|
||||
supportsAllDrives: true,
|
||||
spaces: 'appDataFolder, drive',
|
||||
corpora: 'allDrives',
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as deleteFolder from '../../../../v2/actions/folder/deleteFolder.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: folder deleteFolder', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with PATCH', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'folder',
|
||||
operation: 'deleteFolder',
|
||||
folderNoRootId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 2',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
options: {},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await deleteFolder.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/drive/v3/files/folderIDxxxxxx',
|
||||
{ trashed: true },
|
||||
{ supportsAllDrives: true },
|
||||
);
|
||||
});
|
||||
|
||||
it('shuold be called with DELETE', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'folder',
|
||||
operation: 'deleteFolder',
|
||||
folderNoRootId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 2',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
options: { deletePermanently: true },
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await deleteFolder.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/drive/v3/files/folderIDxxxxxx',
|
||||
undefined,
|
||||
{ supportsAllDrives: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as share from '../../../../v2/actions/folder/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: folder share', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'folder',
|
||||
operation: 'share',
|
||||
folderNoRootId: {
|
||||
__rl: true,
|
||||
value: 'folderIDxxxxxx',
|
||||
mode: 'list',
|
||||
cachedResultName: 'testFolder 2',
|
||||
cachedResultUrl: 'https://drive.google.com/drive/folders/folderIDxxxxxx',
|
||||
},
|
||||
permissionsUi: {
|
||||
permissionsValues: {
|
||||
role: 'reader',
|
||||
type: 'anyone',
|
||||
allowFileDiscovery: true,
|
||||
},
|
||||
},
|
||||
options: {
|
||||
moveToNewOwnersRoot: 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/folderIDxxxxxx/permissions',
|
||||
{ allowFileDiscovery: true, role: 'reader', type: 'anyone' },
|
||||
{ moveToNewOwnersRoot: true, supportsAllDrives: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user