google-drive-mock 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/v3.js +29 -1
- package/package.json +1 -1
- package/src/routes/v3.ts +30 -1
- package/test/advanced_changes.test.ts +3 -3
- package/test/iterate_changes.test.ts +22 -6
- package/test/v3_parity.test.ts +7 -1
package/dist/routes/v3.js
CHANGED
|
@@ -210,6 +210,22 @@ const createV3Router = () => {
|
|
|
210
210
|
nextPageToken
|
|
211
211
|
};
|
|
212
212
|
const fields = req.query.fields;
|
|
213
|
+
if (fields && (fields.includes('etag') || fields.includes('kind,etag'))) {
|
|
214
|
+
res.status(400).json({
|
|
215
|
+
error: {
|
|
216
|
+
code: 400,
|
|
217
|
+
message: "Invalid field selection etag",
|
|
218
|
+
errors: [{
|
|
219
|
+
message: "Invalid field selection etag",
|
|
220
|
+
domain: "global",
|
|
221
|
+
reason: "invalidParameter",
|
|
222
|
+
location: "fields",
|
|
223
|
+
locationType: "parameter"
|
|
224
|
+
}]
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
213
229
|
if (fields) {
|
|
214
230
|
res.json((0, mappers_1.applyFields)(response, fields));
|
|
215
231
|
}
|
|
@@ -434,7 +450,19 @@ const createV3Router = () => {
|
|
|
434
450
|
}
|
|
435
451
|
const fields = req.query.fields;
|
|
436
452
|
if (fields && (fields.includes('etag') || fields.includes('kind,etag'))) {
|
|
437
|
-
res.status(400).json({
|
|
453
|
+
res.status(400).json({
|
|
454
|
+
error: {
|
|
455
|
+
code: 400,
|
|
456
|
+
message: "Invalid field selection etag",
|
|
457
|
+
errors: [{
|
|
458
|
+
message: "Invalid field selection etag",
|
|
459
|
+
domain: "global",
|
|
460
|
+
reason: "invalidParameter",
|
|
461
|
+
location: "fields",
|
|
462
|
+
locationType: "parameter"
|
|
463
|
+
}]
|
|
464
|
+
}
|
|
465
|
+
});
|
|
438
466
|
return;
|
|
439
467
|
}
|
|
440
468
|
if (req.query.alt === 'media') {
|
package/package.json
CHANGED
package/src/routes/v3.ts
CHANGED
|
@@ -218,6 +218,23 @@ export const createV3Router = () => {
|
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
const fields = req.query.fields as string;
|
|
221
|
+
if (fields && (fields.includes('etag') || fields.includes('kind,etag'))) {
|
|
222
|
+
res.status(400).json({
|
|
223
|
+
error: {
|
|
224
|
+
code: 400,
|
|
225
|
+
message: "Invalid field selection etag",
|
|
226
|
+
errors: [{
|
|
227
|
+
message: "Invalid field selection etag",
|
|
228
|
+
domain: "global",
|
|
229
|
+
reason: "invalidParameter",
|
|
230
|
+
location: "fields",
|
|
231
|
+
locationType: "parameter"
|
|
232
|
+
}]
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
221
238
|
if (fields) {
|
|
222
239
|
res.json(applyFields(response, fields));
|
|
223
240
|
} else {
|
|
@@ -491,7 +508,19 @@ export const createV3Router = () => {
|
|
|
491
508
|
|
|
492
509
|
const fields = req.query.fields as string;
|
|
493
510
|
if (fields && (fields.includes('etag') || fields.includes('kind,etag'))) {
|
|
494
|
-
res.status(400).json({
|
|
511
|
+
res.status(400).json({
|
|
512
|
+
error: {
|
|
513
|
+
code: 400,
|
|
514
|
+
message: "Invalid field selection etag",
|
|
515
|
+
errors: [{
|
|
516
|
+
message: "Invalid field selection etag",
|
|
517
|
+
domain: "global",
|
|
518
|
+
reason: "invalidParameter",
|
|
519
|
+
location: "fields",
|
|
520
|
+
locationType: "parameter"
|
|
521
|
+
}]
|
|
522
|
+
}
|
|
523
|
+
});
|
|
495
524
|
return;
|
|
496
525
|
}
|
|
497
526
|
|
|
@@ -57,7 +57,7 @@ describe('Advanced Drive Features (Part 1)', () => {
|
|
|
57
57
|
const fileId = (createRes.body as DriveFile).id;
|
|
58
58
|
|
|
59
59
|
// 3. List Changes
|
|
60
|
-
const changesRes = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true&fields=changes(fileId,removed,file(name))`);
|
|
60
|
+
const changesRes = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true&includeItemsFromAllDrives=true&fields=changes(fileId,removed,file(name))`);
|
|
61
61
|
expect(changesRes.status).toBe(200);
|
|
62
62
|
|
|
63
63
|
let found: DriveChange | undefined;
|
|
@@ -65,7 +65,7 @@ describe('Advanced Drive Features (Part 1)', () => {
|
|
|
65
65
|
const retryDelay = 400;
|
|
66
66
|
|
|
67
67
|
for (let i = 0; i < maxRetries; i++) {
|
|
68
|
-
const changesRes = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true&fields=changes(fileId,removed,file(name))`);
|
|
68
|
+
const changesRes = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true&includeItemsFromAllDrives=true&fields=changes(fileId,removed,file(name))`);
|
|
69
69
|
expect(changesRes.status).toBe(200);
|
|
70
70
|
const changes = (changesRes.body as { changes: DriveChange[] }).changes;
|
|
71
71
|
found = changes.find((c: DriveChange) => c.fileId === fileId);
|
|
@@ -86,7 +86,7 @@ describe('Advanced Drive Features (Part 1)', () => {
|
|
|
86
86
|
|
|
87
87
|
// 4. Delete file (Change)
|
|
88
88
|
await req('DELETE', `/drive/v3/files/${fileId}`);
|
|
89
|
-
const changesRes2 = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true`);
|
|
89
|
+
const changesRes2 = await req('GET', `/drive/v3/changes?pageToken=${startToken}&supportsAllDrives=true&includeItemsFromAllDrives=true`);
|
|
90
90
|
const changes2 = (changesRes2.body as { changes: DriveChange[] }).changes;
|
|
91
91
|
const deletion = changes2.find((c: DriveChange) => c.fileId === fileId && c.removed === true);
|
|
92
92
|
|
|
@@ -7,7 +7,7 @@ import { DriveFile } from '../src/store';
|
|
|
7
7
|
|
|
8
8
|
const randomString = () => Math.random().toString(36).substring(7);
|
|
9
9
|
|
|
10
|
-
const createFileWithContent = async (name: string, content: string, config: TestConfig) => {
|
|
10
|
+
const createFileWithContent = async (name: string, content: string, config: TestConfig, parentId?: string) => {
|
|
11
11
|
const res = await fetch(`${config.baseUrl}/upload/drive/v3/files?uploadType=media`, {
|
|
12
12
|
method: 'POST',
|
|
13
13
|
headers: {
|
|
@@ -24,7 +24,11 @@ const createFileWithContent = async (name: string, content: string, config: Test
|
|
|
24
24
|
// actually, let's just use the patch to set name/metadata to ensure it's correct for the test.
|
|
25
25
|
|
|
26
26
|
// Better: use multipart or just update after create.
|
|
27
|
-
|
|
27
|
+
const patchUrl = parentId
|
|
28
|
+
? `${config.baseUrl}/drive/v3/files/${file.id}?addParents=${parentId}`
|
|
29
|
+
: `${config.baseUrl}/drive/v3/files/${file.id}`;
|
|
30
|
+
|
|
31
|
+
await fetch(patchUrl, {
|
|
28
32
|
method: 'PATCH',
|
|
29
33
|
headers: {
|
|
30
34
|
'Authorization': `Bearer ${config.token}`,
|
|
@@ -52,19 +56,31 @@ describe('Iterate Changes Queries', () => {
|
|
|
52
56
|
});
|
|
53
57
|
|
|
54
58
|
it('should find files where last write time was greater than X, sorted by modifiedTime and id, with limit', async () => {
|
|
59
|
+
// Create a parent folder
|
|
60
|
+
const parentRes = await fetch(`${config.baseUrl}/drive/v3/files`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { ...headers, 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
name: 'ParentFolder_GreaterThan_' + randomString(),
|
|
65
|
+
mimeType: 'application/vnd.google-apps.folder'
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
expect(parentRes.status).toBe(200);
|
|
69
|
+
const parentId = (await parentRes.json()).id;
|
|
70
|
+
|
|
55
71
|
// Create 3 files with slight delays to ensure different modifiedTimes
|
|
56
|
-
const file1 = await createFileWithContent('file1', randomString(), config);
|
|
72
|
+
const file1 = await createFileWithContent('file1', randomString(), config, parentId);
|
|
57
73
|
await new Promise(r => setTimeout(r, 1100)); // Ensure > 1s diff for reliable sorting if seconds resolution
|
|
58
|
-
const file2 = await createFileWithContent('file2', randomString(), config);
|
|
74
|
+
const file2 = await createFileWithContent('file2', randomString(), config, parentId);
|
|
59
75
|
await new Promise(r => setTimeout(r, 1100));
|
|
60
|
-
const file3 = await createFileWithContent('file3', randomString(), config);
|
|
76
|
+
const file3 = await createFileWithContent('file3', randomString(), config, parentId);
|
|
61
77
|
|
|
62
78
|
// Use file1's modifiedTime as the baseline (X)
|
|
63
79
|
const timeX = file1.modifiedTime;
|
|
64
80
|
|
|
65
81
|
// Query: modifiedTime > X, orderBy modifiedTime asc, name asc (using name as proxy for ID stability in test if needed, but user asked for ID)
|
|
66
82
|
// User asked for: Sorted by write data and id. with limit
|
|
67
|
-
const q = `modifiedTime > '${timeX}' and trashed = false`;
|
|
83
|
+
const q = `modifiedTime > '${timeX}' and '${parentId}' in parents and trashed = false`;
|
|
68
84
|
const orderBy = 'modifiedTime asc, name asc';
|
|
69
85
|
const pageSize = 1;
|
|
70
86
|
|
package/test/v3_parity.test.ts
CHANGED
|
@@ -62,7 +62,7 @@ describe('Google Drive API V3 Parity', () => {
|
|
|
62
62
|
return makeRequest(config.target, method, path, headers, body);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
it('should return 400 if fields=etag is requested', async () => {
|
|
65
|
+
it('should return 400 if fields=etag is requested on get', async () => {
|
|
66
66
|
// Create file
|
|
67
67
|
const createRes = await req('POST', '/drive/v3/files', { name: 'V3 Fields Test' });
|
|
68
68
|
const fileId = createRes.body.id;
|
|
@@ -73,6 +73,12 @@ describe('Google Drive API V3 Parity', () => {
|
|
|
73
73
|
expect(getRes.status).toBe(400);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
it('should return 400 if fields=etag is requested on list', async () => {
|
|
77
|
+
const getRes = await req('GET', `/drive/v3/files?fields=files(id,name,mimeType,parents,modifiedTime,size,etag)`);
|
|
78
|
+
|
|
79
|
+
expect(getRes.status).toBe(400);
|
|
80
|
+
});
|
|
81
|
+
|
|
76
82
|
it('should ignore If-Match header on PATCH (Last Write Wins)', async () => {
|
|
77
83
|
// Create file
|
|
78
84
|
const createRes = await req('POST', '/drive/v3/files', { name: 'V3 If-Match Test' });
|