Skip to content

Commit f216ce7

Browse files
committed
Always mocking whole Drive in tests
1 parent 1a3bbf4 commit f216ce7

File tree

5 files changed

+203
-229
lines changed

5 files changed

+203
-229
lines changed

__tests__/backend/utils/SafeDriveService.test.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import { expect, test } from "@jest/globals";
22

33
import { SafeDriveService_ } from "../../../src/backend/utils/SafeDriveService";
4-
import {
5-
mockedCommentsCollection,
6-
mockedDrive,
7-
mockedDrivesCollection,
8-
mockedFilesCollection,
9-
mockedRepliesCollection,
10-
} from "../../test-utils/gas-stubs";
4+
import { mockedDrive } from "../../test-utils/gas-stubs";
115

126
test("SafeDriveService constructs correctly", () => {
13-
global.Drive = {
14-
...mockedDrive(),
15-
Comments: mockedCommentsCollection(),
16-
Drives: mockedDrivesCollection(),
17-
Files: mockedFilesCollection(),
18-
Replies: mockedRepliesCollection(),
19-
};
7+
global.Drive = mockedDrive();
208

219
expect(() => {
2210
new SafeDriveService_();

__tests__/backend/utils/SafeDriveService/SafeCommentsCollection.test.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import { expect, test } from "@jest/globals";
22
import { mocked } from "jest-mock";
33

44
import { SafeCommentsCollection_ } from "../../../../src/backend/utils/SafeDriveService/SafeCommentsCollection";
5-
import {
6-
mockedCommentsCollection,
7-
mockedDrive,
8-
} from "../../../test-utils/gas-stubs";
5+
import { mockedDrive } from "../../../test-utils/gas-stubs";
96

107
test("SafeCommentsCollection constructs correctly", () => {
11-
global.Drive = {
12-
...mockedDrive(),
13-
Comments: mockedCommentsCollection(),
14-
};
8+
global.Drive = mockedDrive();
159

1610
expect(() => {
1711
new SafeCommentsCollection_();
@@ -37,7 +31,7 @@ test("create works", () => {
3731
],
3832
};
3933

40-
global.Drive.Comments = mockedCommentsCollection();
34+
global.Drive = mockedDrive();
4135
const create = mocked(global.Drive.Comments).create.mockReturnValueOnce(
4236
comment,
4337
);
@@ -69,7 +63,7 @@ test("create throws an error on an invalid comment", () => {
6963
],
7064
};
7165

72-
global.Drive.Comments = mockedCommentsCollection();
66+
global.Drive = mockedDrive();
7367
const create = mocked(global.Drive.Comments).create.mockReturnValueOnce(
7468
comment,
7569
);
@@ -123,7 +117,7 @@ test("list works", () => {
123117
],
124118
};
125119

126-
global.Drive.Comments = mockedCommentsCollection();
120+
global.Drive = mockedDrive();
127121
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
128122
commentList,
129123
);
@@ -177,7 +171,7 @@ test("list works with optional arguments", () => {
177171
],
178172
};
179173

180-
global.Drive.Comments = mockedCommentsCollection();
174+
global.Drive = mockedDrive();
181175
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
182176
commentList,
183177
);
@@ -238,7 +232,7 @@ test("list throws an error on an invalid comment", () => {
238232
],
239233
};
240234

241-
global.Drive.Comments = mockedCommentsCollection();
235+
global.Drive = mockedDrive();
242236
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
243237
commentList,
244238
);
@@ -257,7 +251,7 @@ test("list throws an error on an invalid comment list", () => {
257251
nextPageToken: "TOKEN",
258252
};
259253

260-
global.Drive.Comments = mockedCommentsCollection();
254+
global.Drive = mockedDrive();
261255
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
262256
commentList,
263257
);
@@ -302,7 +296,7 @@ test("list throws an error on missing replies", () => {
302296
],
303297
};
304298

305-
global.Drive.Comments = mockedCommentsCollection();
299+
global.Drive = mockedDrive();
306300
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
307301
commentList,
308302
);
@@ -355,7 +349,7 @@ test("list throws an error on an invalid reply", () => {
355349
],
356350
};
357351

358-
global.Drive.Comments = mockedCommentsCollection();
352+
global.Drive = mockedDrive();
359353
const list = mocked(global.Drive.Comments).list.mockReturnValueOnce(
360354
commentList,
361355
);

__tests__/backend/utils/SafeDriveService/SafeDrivesCollection.test.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import { expect, test } from "@jest/globals";
22
import { mocked } from "jest-mock";
33

44
import { SafeDrivesCollection_ } from "../../../../src/backend/utils/SafeDriveService/SafeDrivesCollection";
5-
import {
6-
mockedDrive,
7-
mockedDrivesCollection,
8-
} from "../../../test-utils/gas-stubs";
5+
import { mockedDrive } from "../../../test-utils/gas-stubs";
96

107
test("SafeDrivesCollection constructs correctly", () => {
11-
global.Drive = {
12-
...mockedDrive(),
13-
Drives: mockedDrivesCollection(),
14-
};
8+
global.Drive = mockedDrive();
159

1610
expect(() => {
1711
new SafeDrivesCollection_();
@@ -32,7 +26,7 @@ test("list works", () => {
3226
],
3327
};
3428

35-
global.Drive.Drives = mockedDrivesCollection();
29+
global.Drive = mockedDrive();
3630
const list = mocked(global.Drive.Drives).list.mockReturnValueOnce(driveList);
3731

3832
const drivesCollection = new SafeDrivesCollection_();
@@ -57,7 +51,7 @@ test("list works with optional parameters", () => {
5751
],
5852
};
5953

60-
global.Drive.Drives = mockedDrivesCollection();
54+
global.Drive = mockedDrive();
6155
const list = mocked(global.Drive.Drives).list.mockReturnValueOnce(driveList);
6256

6357
const drivesCollection = new SafeDrivesCollection_();
@@ -98,7 +92,7 @@ test("list works with selective fields", () => {
9892
],
9993
};
10094

101-
global.Drive.Drives = mockedDrivesCollection();
95+
global.Drive = mockedDrive();
10296
const list = mocked(global.Drive.Drives)
10397
.list.mockReturnValueOnce(driveList1)
10498
.mockReturnValueOnce(driveList2);
@@ -131,7 +125,7 @@ test("list throws an error on an invalid drive", () => {
131125
],
132126
};
133127

134-
global.Drive.Drives = mockedDrivesCollection();
128+
global.Drive = mockedDrive();
135129
const list = mocked(global.Drive.Drives).list.mockReturnValueOnce(driveList);
136130

137131
const drivesCollection = new SafeDrivesCollection_();
@@ -143,7 +137,7 @@ test("list throws an error on an invalid drive", () => {
143137
});
144138

145139
test("list throws an error on an invalid drive list", () => {
146-
global.Drive.Drives = mockedDrivesCollection();
140+
global.Drive = mockedDrive();
147141
const list = mocked(global.Drive.Drives).list.mockReturnValueOnce({});
148142

149143
const drivesCollection = new SafeDrivesCollection_();

__tests__/backend/utils/SafeDriveService/SafeFilesCollection.test.ts

+24-30
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import { expect, test } from "@jest/globals";
22
import { mocked } from "jest-mock";
33

44
import { SafeFilesCollection_ } from "../../../../src/backend/utils/SafeDriveService/SafeFilesCollection";
5-
import {
6-
mockedDrive,
7-
mockedFilesCollection,
8-
} from "../../../test-utils/gas-stubs";
5+
import { mockedDrive } from "../../../test-utils/gas-stubs";
96

107
test("SafeFilesCollection constructs correctly", () => {
11-
global.Drive = {
12-
...mockedDrive(),
13-
Files: mockedFilesCollection(),
14-
};
8+
global.Drive = mockedDrive();
159

1610
expect(() => {
1711
new SafeFilesCollection_();
@@ -29,7 +23,7 @@ test("copy works", () => {
2923
name: "FILE_TITLE",
3024
};
3125

32-
global.Drive.Files = mockedFilesCollection();
26+
global.Drive = mockedDrive();
3327
const copy = mocked(global.Drive.Files).copy.mockReturnValueOnce(file);
3428

3529
const filesCollection = new SafeFilesCollection_();
@@ -53,7 +47,7 @@ test("copy works with optional arguments", () => {
5347
name: "FILE_TITLE",
5448
};
5549

56-
global.Drive.Files = mockedFilesCollection();
50+
global.Drive = mockedDrive();
5751
const copy = mocked(global.Drive.Files).copy.mockReturnValueOnce(file);
5852

5953
const filesCollection = new SafeFilesCollection_();
@@ -76,7 +70,7 @@ test("copy works with selective fields", () => {
7670
mimeType: "text/plain",
7771
};
7872

79-
global.Drive.Files = mockedFilesCollection();
73+
global.Drive = mockedDrive();
8074
const copy = mocked(global.Drive.Files).copy.mockReturnValueOnce(file);
8175

8276
const filesCollection = new SafeFilesCollection_();
@@ -109,7 +103,7 @@ test("copy throws and error on invalid file", () => {
109103
name: "FILE_TITLE",
110104
};
111105

112-
global.Drive.Files = mockedFilesCollection();
106+
global.Drive = mockedDrive();
113107
const copy = mocked(global.Drive.Files).copy.mockReturnValueOnce(file);
114108

115109
const filesCollection = new SafeFilesCollection_();
@@ -133,7 +127,7 @@ test("get works", () => {
133127
name: "FILE_TITLE",
134128
};
135129

136-
global.Drive.Files = mockedFilesCollection();
130+
global.Drive = mockedDrive();
137131
const get = mocked(global.Drive.Files).get.mockReturnValueOnce(file);
138132

139133
const filesCollection = new SafeFilesCollection_();
@@ -156,7 +150,7 @@ test("get works with optional arguments", () => {
156150
name: "FILE_TITLE",
157151
};
158152

159-
global.Drive.Files = mockedFilesCollection();
153+
global.Drive = mockedDrive();
160154
const get = mocked(global.Drive.Files).get.mockReturnValueOnce(file);
161155

162156
const filesCollection = new SafeFilesCollection_();
@@ -174,7 +168,7 @@ test("get works with selective fields", () => {
174168
name: "FILE_TITLE",
175169
};
176170

177-
global.Drive.Files = mockedFilesCollection();
171+
global.Drive = mockedDrive();
178172
const get = mocked(global.Drive.Files).get.mockReturnValueOnce(file);
179173

180174
const filesCollection = new SafeFilesCollection_();
@@ -196,7 +190,7 @@ test("get throws an error on invalid file", () => {
196190
name: "FILE_TITLE",
197191
};
198192

199-
global.Drive.Files = mockedFilesCollection();
193+
global.Drive = mockedDrive();
200194
const get = mocked(global.Drive.Files).get.mockReturnValueOnce(file);
201195

202196
const filesCollection = new SafeFilesCollection_();
@@ -219,7 +213,7 @@ test("create works", () => {
219213
name: "FILE_TITLE",
220214
};
221215

222-
global.Drive.Files = mockedFilesCollection();
216+
global.Drive = mockedDrive();
223217
const create = mocked(global.Drive.Files).create.mockReturnValueOnce(file);
224218

225219
const filesCollection = new SafeFilesCollection_();
@@ -243,7 +237,7 @@ test("create works with optional arguments", () => {
243237
name: "FILE_TITLE",
244238
};
245239

246-
global.Drive.Files = mockedFilesCollection();
240+
global.Drive = mockedDrive();
247241
const create = mocked(global.Drive.Files).create.mockReturnValueOnce(file);
248242

249243
const filesCollection = new SafeFilesCollection_();
@@ -266,7 +260,7 @@ test("create works with selective fields", () => {
266260
name: "FILE_TITLE",
267261
};
268262

269-
global.Drive.Files = mockedFilesCollection();
263+
global.Drive = mockedDrive();
270264
const create = mocked(global.Drive.Files).create.mockReturnValueOnce(file);
271265

272266
const filesCollection = new SafeFilesCollection_();
@@ -296,7 +290,7 @@ test("create throws an error on invalid file", () => {
296290
name: "FILE_TITLE",
297291
};
298292

299-
global.Drive.Files = mockedFilesCollection();
293+
global.Drive = mockedDrive();
300294
const create = mocked(global.Drive.Files).create.mockReturnValueOnce(file);
301295

302296
const filesCollection = new SafeFilesCollection_();
@@ -333,7 +327,7 @@ test("list works", () => {
333327
],
334328
};
335329

336-
global.Drive.Files = mockedFilesCollection();
330+
global.Drive = mockedDrive();
337331
const list = mocked(global.Drive.Files).list.mockReturnValueOnce(fileList);
338332

339333
const filesCollection = new SafeFilesCollection_();
@@ -368,7 +362,7 @@ test("list works with optional arguments", () => {
368362
],
369363
};
370364

371-
global.Drive.Files = mockedFilesCollection();
365+
global.Drive = mockedDrive();
372366
const list = mocked(global.Drive.Files).list.mockReturnValueOnce(fileList);
373367

374368
const filesCollection = new SafeFilesCollection_();
@@ -405,7 +399,7 @@ test("list works with selective fields", () => {
405399
],
406400
};
407401

408-
global.Drive.Files = mockedFilesCollection();
402+
global.Drive = mockedDrive();
409403
const list = mocked(global.Drive.Files).list.mockReturnValueOnce(fileList);
410404

411405
const filesCollection = new SafeFilesCollection_();
@@ -444,7 +438,7 @@ test("list throws an error on invalid file", () => {
444438
],
445439
};
446440

447-
global.Drive.Files = mockedFilesCollection();
441+
global.Drive = mockedDrive();
448442
const list = mocked(global.Drive.Files).list.mockReturnValueOnce(fileList);
449443

450444
const filesCollection = new SafeFilesCollection_();
@@ -458,7 +452,7 @@ test("list throws an error on invalid file", () => {
458452
test("list throws an error on invalid file list", () => {
459453
const fileList = {};
460454

461-
global.Drive.Files = mockedFilesCollection();
455+
global.Drive = mockedDrive();
462456
const list = mocked(global.Drive.Files).list.mockReturnValueOnce(fileList);
463457

464458
const filesCollection = new SafeFilesCollection_();
@@ -470,7 +464,7 @@ test("list throws an error on invalid file list", () => {
470464
});
471465

472466
test("remove works", () => {
473-
global.Drive.Files = mockedFilesCollection();
467+
global.Drive = mockedDrive();
474468
const remove = mocked(global.Drive.Files).remove.mockImplementationOnce(
475469
// eslint-disable-next-line @typescript-eslint/no-empty-function -- Implementation needed so the function is bound to local this
476470
() => {},
@@ -495,7 +489,7 @@ test("update works", () => {
495489
name: "FILE_TITLE",
496490
};
497491

498-
global.Drive.Files = mockedFilesCollection();
492+
global.Drive = mockedDrive();
499493
const update = mocked(global.Drive.Files).update.mockReturnValueOnce(file);
500494

501495
const filesCollection = new SafeFilesCollection_();
@@ -520,7 +514,7 @@ test("update works with optional arguments", () => {
520514
name: "FILE_TITLE",
521515
};
522516

523-
global.Drive.Files = mockedFilesCollection();
517+
global.Drive = mockedDrive();
524518
const update = mocked(global.Drive.Files).update.mockReturnValueOnce(file);
525519

526520
const filesCollection = new SafeFilesCollection_();
@@ -549,7 +543,7 @@ test("update works with selective fields", () => {
549543
},
550544
};
551545

552-
global.Drive.Files = mockedFilesCollection();
546+
global.Drive = mockedDrive();
553547
const update = mocked(global.Drive.Files).update.mockReturnValueOnce(file);
554548

555549
const filesCollection = new SafeFilesCollection_();
@@ -574,7 +568,7 @@ test("update throws an error on invalid file", () => {
574568
id: "FILE_ID",
575569
};
576570

577-
global.Drive.Files = mockedFilesCollection();
571+
global.Drive = mockedDrive();
578572
const update = mocked(global.Drive.Files).update.mockReturnValueOnce(file);
579573

580574
const filesCollection = new SafeFilesCollection_();

0 commit comments

Comments
 (0)