feat(Google Drive Node): Overhaul (#5941)
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as create from '../../../../v2/actions/drive/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 {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
jest.mock('uuid', () => {
|
||||
const originalModule = jest.requireActual('uuid');
|
||||
return {
|
||||
...originalModule,
|
||||
v4: jest.fn(function () {
|
||||
return '430c0ca1-2498-472c-9d43-da0163839823';
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: drive create', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
name: 'newDrive',
|
||||
options: {
|
||||
capabilities: {
|
||||
canComment: true,
|
||||
canRename: true,
|
||||
canTrashChildren: true,
|
||||
},
|
||||
colorRgb: '#451AD3',
|
||||
hidden: false,
|
||||
restrictions: {
|
||||
driveMembersOnly: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await create.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/drive/v3/drives',
|
||||
{
|
||||
capabilities: { canComment: true, canRename: true, canTrashChildren: true },
|
||||
colorRgb: '#451AD3',
|
||||
hidden: false,
|
||||
name: 'newDrive',
|
||||
restrictions: { driveMembersOnly: true },
|
||||
},
|
||||
{ requestId: '430c0ca1-2498-472c-9d43-da0163839823' },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as deleteDrive from '../../../../v2/actions/drive/deleteDrive.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: drive deleteDrive', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
operation: 'deleteDrive',
|
||||
driveId: {
|
||||
__rl: true,
|
||||
value: 'driveIDxxxxxx',
|
||||
mode: 'id',
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await deleteDrive.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'DELETE',
|
||||
'/drive/v3/drives/driveIDxxxxxx',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as get from '../../../../v2/actions/drive/get.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: drive get', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
operation: 'get',
|
||||
driveId: {
|
||||
__rl: true,
|
||||
value: 'driveIDxxxxxx',
|
||||
mode: 'id',
|
||||
},
|
||||
options: {
|
||||
useDomainAdminAccess: true,
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await get.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/drive/v3/drives/driveIDxxxxxx',
|
||||
{},
|
||||
{ useDomainAdminAccess: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as list from '../../../../v2/actions/drive/list.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 {};
|
||||
}
|
||||
}),
|
||||
googleApiRequestAllItems: jest.fn(async function (method: string) {
|
||||
if (method === 'GET') {
|
||||
return {};
|
||||
}
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('test GoogleDriveV2: drive list', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with limit', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
operation: 'list',
|
||||
limit: 20,
|
||||
options: {},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await list.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/drive/v3/drives',
|
||||
{},
|
||||
{ pageSize: 20 },
|
||||
);
|
||||
});
|
||||
|
||||
it('shuold be called with returnAll true', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
operation: 'list',
|
||||
returnAll: true,
|
||||
options: {},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await list.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequestAllItems).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequestAllItems).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'drives',
|
||||
'/drive/v3/drives',
|
||||
{},
|
||||
{},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import nock from 'nock';
|
||||
|
||||
import * as update from '../../../../v2/actions/drive/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: drive update', () => {
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../../../v2/transport');
|
||||
});
|
||||
|
||||
it('shuold be called with', async () => {
|
||||
const nodeParameters = {
|
||||
resource: 'drive',
|
||||
operation: 'update',
|
||||
driveId: {
|
||||
__rl: true,
|
||||
value: 'sharedDriveIDxxxxx',
|
||||
mode: 'id',
|
||||
},
|
||||
options: {
|
||||
colorRgb: '#F4BEBE',
|
||||
name: 'newName',
|
||||
restrictions: {
|
||||
driveMembersOnly: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const fakeExecuteFunction = createMockExecuteFunction(nodeParameters, driveNode);
|
||||
|
||||
await update.execute.call(fakeExecuteFunction, 0);
|
||||
|
||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/drive/v3/drives/sharedDriveIDxxxxx',
|
||||
{ colorRgb: '#F4BEBE', name: 'newName', restrictions: { driveMembersOnly: true } },
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user