google-drive-mock 1.1.1 → 1.1.2

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/index.js CHANGED
@@ -29,6 +29,14 @@ const createApp = (config = {}) => {
29
29
  exposedHeaders: ['ETag', 'Date', 'Content-Length']
30
30
  }));
31
31
  app.set('etag', false); // Disable default ETag generation to match Real API behavior
32
+ // Random delay to simulate real-world network latency (0-20ms)
33
+ app.use((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
34
+ const delay = Math.floor(Math.random() * 21); // 0 to 20ms
35
+ if (delay > 0) {
36
+ yield new Promise(resolve => setTimeout(resolve, delay));
37
+ }
38
+ next();
39
+ }));
32
40
  app.use((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
33
41
  if (config.serverLagBefore && config.serverLagBefore > 0) {
34
42
  yield new Promise(resolve => setTimeout(resolve, config.serverLagBefore));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-drive-mock",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Mock-Server that simulates being google-drive. Used for testing.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -18,6 +18,15 @@ const createApp = (config: AppConfig = {}) => {
18
18
  }));
19
19
  app.set('etag', false); // Disable default ETag generation to match Real API behavior
20
20
 
21
+ // Random delay to simulate real-world network latency (0-20ms)
22
+ app.use(async (req, res, next) => {
23
+ const delay = Math.floor(Math.random() * 21); // 0 to 20ms
24
+ if (delay > 0) {
25
+ await new Promise(resolve => setTimeout(resolve, delay));
26
+ }
27
+ next();
28
+ });
29
+
21
30
  app.use(async (req, res, next) => {
22
31
  if (config.serverLagBefore && config.serverLagBefore > 0) {
23
32
  await new Promise(resolve => setTimeout(resolve, config.serverLagBefore));
@@ -0,0 +1,81 @@
1
+ import { describe, it, expect, beforeAll } from 'vitest';
2
+ import { getTestConfig, TestConfig } from './config';
3
+
4
+ const randomString = () => Math.random().toString(36).substring(7);
5
+
6
+ describe('Folder Search Parity', () => {
7
+ let config: TestConfig;
8
+ let headers: Record<string, string>;
9
+
10
+ beforeAll(async () => {
11
+ config = await getTestConfig();
12
+ headers = {
13
+ Authorization: `Bearer ${config.token}`
14
+ };
15
+ });
16
+
17
+ it('should return only id for folder search with fields=files(id)', async () => {
18
+ const folderName = 'SearchTest_' + randomString();
19
+ const FOLDER_MIME_TYPE = 'application/vnd.google-apps.folder';
20
+
21
+ // 1. Create a parent folder
22
+ const parentRes = await fetch(`${config.baseUrl}/drive/v3/files`, {
23
+ method: 'POST',
24
+ headers: { ...headers, 'Content-Type': 'application/json' },
25
+ body: JSON.stringify({
26
+ name: 'Parent_' + randomString(),
27
+ mimeType: FOLDER_MIME_TYPE
28
+ })
29
+ });
30
+ expect(parentRes.status).toBe(200);
31
+ const parentId = (await parentRes.json()).id;
32
+
33
+ // 2. Create the target folder inside parent
34
+ const targetRes = await fetch(`${config.baseUrl}/drive/v3/files`, {
35
+ method: 'POST',
36
+ headers: { ...headers, 'Content-Type': 'application/json' },
37
+ body: JSON.stringify({
38
+ name: folderName,
39
+ mimeType: FOLDER_MIME_TYPE,
40
+ parents: [parentId]
41
+ })
42
+ });
43
+ expect(targetRes.status).toBe(200);
44
+ const targetId = (await targetRes.json()).id;
45
+
46
+ // Wait for consistency
47
+ await new Promise(r => setTimeout(r, 2000));
48
+
49
+ // 3. User's Query
50
+ const query = `name = '${folderName}' and '${parentId}' in parents and trashed = false and mimeType = '${FOLDER_MIME_TYPE}'`;
51
+
52
+ const params = new URLSearchParams({
53
+ q: query,
54
+ fields: 'files(id,mimeType)',
55
+ orderBy: 'createdTime asc'
56
+ });
57
+
58
+ const url = `${config.baseUrl}/drive/v3/files?${params.toString()}`;
59
+ console.log('Requesting URL:', url);
60
+
61
+ const res = await fetch(url, { headers });
62
+ expect(res.status).toBe(200);
63
+ const data = await res.json();
64
+
65
+ expect(data.files).toBeDefined();
66
+ expect(data.files.length).toBeGreaterThan(0);
67
+
68
+ const foundFolder = data.files[0];
69
+ expect(foundFolder.id).toBe(targetId);
70
+ expect(foundFolder.mimeType).toBe(FOLDER_MIME_TYPE);
71
+
72
+ // Strict Key Check
73
+ const actualKeys = Object.keys(foundFolder).sort();
74
+ const expectedKeys = ['id', 'mimeType'].sort(); // User requested only id
75
+
76
+ if (JSON.stringify(actualKeys) !== JSON.stringify(expectedKeys)) {
77
+ console.log('Keys mismatch! Actual:', actualKeys);
78
+ }
79
+ expect(actualKeys).toEqual(expectedKeys);
80
+ }, 60000);
81
+ });