google-drive-mock 1.1.6 → 1.2.0

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.
Files changed (48) hide show
  1. package/AGENTS.md +4 -1
  2. package/CLAUDE.md +17 -0
  3. package/dist/index.js +2 -1
  4. package/dist/mappers.d.ts +5 -0
  5. package/dist/mappers.js +15 -0
  6. package/dist/routes/v2.js +16 -8
  7. package/dist/routes/v3.js +30 -9
  8. package/dist/store.js +2 -2
  9. package/package.json +4 -4
  10. package/scripts/check-token.ts +107 -38
  11. package/scripts/run-loop.sh +18 -0
  12. package/src/index.ts +2 -1
  13. package/src/mappers.ts +15 -0
  14. package/src/routes/v2.ts +16 -8
  15. package/src/routes/v3.ts +35 -10
  16. package/src/store.ts +2 -2
  17. package/test/advanced_changes.test.ts +76 -29
  18. package/test/advanced_ordering.test.ts +2 -1
  19. package/test/basics.test.ts +34 -58
  20. package/test/batch_and_query.test.ts +28 -62
  21. package/test/batch_insert_download.test.ts +2 -1
  22. package/test/check_empty.test.ts +60 -0
  23. package/test/complex_query.test.ts +2 -1
  24. package/test/concurrent_fetch.test.ts +2 -1
  25. package/test/config.ts +164 -7
  26. package/test/dates_and_sorting.test.ts +2 -1
  27. package/test/etag.test.ts +8 -4
  28. package/test/features.test.ts +2 -1
  29. package/test/folder_query.test.ts +2 -1
  30. package/test/folder_search.test.ts +2 -1
  31. package/test/iterate_changes.test.ts +153 -68
  32. package/test/latency.test.ts +2 -1
  33. package/test/mime_types.test.ts +2 -1
  34. package/test/missing_fields.test.ts +2 -1
  35. package/test/multipart_behavior.test.ts +2 -1
  36. package/test/parallel_update.test.ts +2 -1
  37. package/test/parity_media_download.test.ts +2 -1
  38. package/test/routines.test.ts +15 -12
  39. package/test/upload.test.ts +2 -1
  40. package/test/url_parameters.test.ts +2 -1
  41. package/test/v2_basics.test.ts +22 -13
  42. package/test/v2_content.test.ts +2 -1
  43. package/test/v2_missing_ops.test.ts +75 -75
  44. package/test/v2_routes.test.ts +31 -21
  45. package/test/v2_upload.test.ts +17 -9
  46. package/test/v3_parity.test.ts +56 -20
  47. package/test_etag_headers.ts +92 -0
  48. package/vitest.config.ts +7 -1
@@ -0,0 +1,92 @@
1
+ /* eslint-disable */
2
+ import { getTestConfig } from './test/config';
3
+
4
+ async function run() {
5
+ const config = await getTestConfig();
6
+ const token = config.token;
7
+ const baseUrl = config.baseUrl;
8
+
9
+ const req = async (method: string, path: string, body?: any, headers: any = {}) => {
10
+ const url = `${baseUrl}${path}`;
11
+ const fetchOptions: RequestInit = {
12
+ method,
13
+ headers: {
14
+ 'Authorization': `Bearer ${token}`,
15
+ ...headers
16
+ }
17
+ };
18
+ if (body) {
19
+ if (typeof body === 'string') {
20
+ fetchOptions.body = body;
21
+ } else {
22
+ fetchOptions.body = JSON.stringify(body);
23
+ fetchOptions.headers = {
24
+ ...fetchOptions.headers,
25
+ 'Content-Type': 'application/json'
26
+ };
27
+ }
28
+ }
29
+ const res = await fetch(url, fetchOptions);
30
+ const resBody = res.headers.get('content-type')?.includes('application/json')
31
+ ? await res.json()
32
+ : await res.text();
33
+ return { status: res.status, headers: res.headers, body: resBody };
34
+ };
35
+
36
+ console.log('--- TESTING V2 ---');
37
+
38
+ // 1. Create file (POST metadata)
39
+ const createRes = await req('POST', '/drive/v2/files', {
40
+ title: 'ETag Test V2 Real',
41
+ parents: [{ id: config.testFolderId }]
42
+ });
43
+ console.log('1. POST /drive/v2/files status:', createRes.status);
44
+ console.log('1. POST /drive/v2/files ETag Header:', createRes.headers.get('etag'));
45
+ console.log('1. POST /drive/v2/files Body etag:', createRes.body.etag);
46
+
47
+ const fileId = createRes.body.id;
48
+
49
+ // 2. GET file metadata
50
+ const getRes = await req('GET', `/drive/v2/files/${fileId}`);
51
+ console.log('2. GET /drive/v2/files/:id status:', getRes.status);
52
+ console.log('2. GET /drive/v2/files/:id ETag Header:', getRes.headers.get('etag'));
53
+ console.log('2. GET /drive/v2/files/:id Body etag:', getRes.body.etag);
54
+
55
+ // 3. PUT file metadata (V2 uses PUT for metadata update)
56
+ const putRes = await req('PUT', `/drive/v2/files/${fileId}`, {
57
+ title: 'ETag Test V2 Real Patched'
58
+ });
59
+ console.log('3. PUT /drive/v2/files/:id status:', putRes.status);
60
+ console.log('3. PUT /drive/v2/files/:id ETag Header:', putRes.headers.get('etag'));
61
+ console.log('3. PUT /drive/v2/files/:id Body etag:', putRes.body.etag);
62
+
63
+ // 4. POST media upload (create content)
64
+ // In V2, media upload is POST /upload/drive/v2/files
65
+ const uploadCreateRes = await req('POST', `/upload/drive/v2/files?uploadType=media`, 'initial content v2', {
66
+ 'Content-Type': 'text/plain'
67
+ });
68
+ console.log('4. POST /upload/drive/v2/files status:', uploadCreateRes.status);
69
+ console.log('4. POST /upload/drive/v2/files ETag Header:', uploadCreateRes.headers.get('etag'));
70
+ console.log('4. POST /upload/drive/v2/files Body etag:', uploadCreateRes.body.etag);
71
+
72
+ const uploadedFileId = uploadCreateRes.body.id;
73
+
74
+ // 5. PUT media upload (update content)
75
+ const uploadUpdateRes = await req('PUT', `/upload/drive/v2/files/${uploadedFileId}?uploadType=media`, 'updated content v2', {
76
+ 'Content-Type': 'text/plain'
77
+ });
78
+ console.log('5. PUT /upload/drive/v2/files/:id status:', uploadUpdateRes.status);
79
+ console.log('5. PUT /upload/drive/v2/files/:id ETag Header:', uploadUpdateRes.headers.get('etag'));
80
+ console.log('5. PUT /upload/drive/v2/files/:id Body etag:', uploadUpdateRes.body.etag);
81
+
82
+ // 6. GET content (alt=media)
83
+ const getContentRes = await req('GET', `/drive/v2/files/${uploadedFileId}?alt=media`);
84
+ console.log('6. GET /drive/v2/files/:id?alt=media status:', getContentRes.status);
85
+ console.log('6. GET /drive/v2/files/:id?alt=media ETag Header:', getContentRes.headers.get('etag'));
86
+
87
+ // Cleanup
88
+ if (fileId) await req('DELETE', `/drive/v2/files/${fileId}`);
89
+ if (uploadedFileId) await req('DELETE', `/drive/v2/files/${uploadedFileId}`);
90
+ }
91
+
92
+ run().catch(console.error);
package/vitest.config.ts CHANGED
@@ -12,13 +12,19 @@ export default defineConfig({
12
12
  'process.env.GDRIVE_TOKEN': JSON.stringify(process.env.GDRIVE_TOKEN),
13
13
  'process.env.TEST_TARGET': JSON.stringify(process.env.TEST_TARGET),
14
14
  'process.env.BROWSER_ENABLED': JSON.stringify(process.env.BROWSER_ENABLED),
15
+ 'process.env.PORT': JSON.stringify(process.env.PORT || '3000'),
16
+ 'process.env.USE_SHARED_MOCK': JSON.stringify(process.env.USE_SHARED_MOCK || 'false'),
15
17
  },
16
18
  test: {
19
+ testTimeout: 10000,
20
+ fileParallelism: true,
17
21
  env: {
18
22
  // Inject these variables into the browser environment
19
23
  GDRIVE_TOKEN: process.env.GDRIVE_TOKEN,
20
24
  TEST_TARGET: process.env.TEST_TARGET,
21
- BROWSER_ENABLED: process.env.BROWSER_ENABLED
25
+ BROWSER_ENABLED: process.env.BROWSER_ENABLED,
26
+ PORT: process.env.PORT || '3000',
27
+ USE_SHARED_MOCK: process.env.USE_SHARED_MOCK || 'false',
22
28
  },
23
29
  browser: {
24
30
  enabled: process.env.BROWSER_ENABLED === 'true',