Skip to content

Commit 069a189

Browse files
committed
Pluralize folders route
It is our convention that resources should be pluralized in routes in this API. Some of the routes, however, were created before we settled on that convention. This commit adds a plural /folders route, while leaving the /folder route in place for backward compatibility.
1 parent 46c3a14 commit 069a189

File tree

6 files changed

+63
-62
lines changed

6 files changed

+63
-62
lines changed

packages/api/src/folder/controller/get_folder.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ describe("GET /folder", () => {
3434
});
3535

3636
test("should return 200 code for successful call", async () => {
37-
await agent.get("/api/v2/folder?folderIds[]=1").expect(200);
37+
await agent.get("/api/v2/folders?folderIds[]=1").expect(200);
3838
});
3939

4040
test("should call extractUserEmailFromAuthToken middleware", async () => {
41-
await agent.get("/api/v2/folder?folderIds[]=1").expect(200);
41+
await agent.get("/api/v2/folders?folderIds[]=1").expect(200);
4242
expect(extractUserEmailFromAuthToken).toHaveBeenCalled();
4343
});
4444

4545
test("should call extractShareTokenFromHeaders middleware", async () => {
46-
await agent.get("/api/v2/folder?folderIds[]=1").expect(200);
46+
await agent.get("/api/v2/folders?folderIds[]=1").expect(200);
4747
expect(extractShareTokenFromHeaders).toHaveBeenCalled();
4848
});
4949

5050
test("should return 400 code if the header values are improper", async () => {
5151
mockExtractUserEmailFromAuthToken("not_an_email");
52-
await agent.get("/api/v2/folder?folderIds[]=1").expect(400);
52+
await agent.get("/api/v2/folders?folderIds[]=1").expect(400);
5353
});
5454

5555
test("should return a public folder if the user is not authenticated", async () => {
5656
mockExtractUserEmailFromAuthToken();
5757
const response = await agent
58-
.get("/api/v2/folder?folderIds[]=1")
58+
.get("/api/v2/folders?folderIds[]=1")
5959
.expect(200);
6060
const {
6161
body: { items: folders },
@@ -67,7 +67,7 @@ describe("GET /folder", () => {
6767
test("should not return a private folder if the user is not authenticated", async () => {
6868
mockExtractUserEmailFromAuthToken();
6969
const response = await agent
70-
.get("/api/v2/folder?folderIds[]=2")
70+
.get("/api/v2/folders?folderIds[]=2")
7171
.expect(200);
7272
const {
7373
body: { items: folders },
@@ -77,7 +77,7 @@ describe("GET /folder", () => {
7777

7878
test("should return a private folder if the user is authenticated", async () => {
7979
const response = await agent
80-
.get("/api/v2/folder?folderIds[]=2")
80+
.get("/api/v2/folders?folderIds[]=2")
8181
.expect(200);
8282
const {
8383
body: { items: folders },
@@ -90,7 +90,7 @@ describe("GET /folder", () => {
9090
mockExtractUserEmailFromAuthToken("[email protected]");
9191

9292
const response = await agent
93-
.get("/api/v2/folder?folderIds[]=2")
93+
.get("/api/v2/folders?folderIds[]=2")
9494
.expect(200);
9595
const {
9696
body: { items: folders },
@@ -102,7 +102,7 @@ describe("GET /folder", () => {
102102
mockExtractUserEmailFromAuthToken();
103103
mockExtractShareTokenFromHeaders("c0f523e4-48d8-4c39-8cda-5e95161532e4");
104104
const response = await agent
105-
.get("/api/v2/folder?folderIds[]=2")
105+
.get("/api/v2/folders?folderIds[]=2")
106106
.set("X-Permanent-Share-Token", "c0f523e4-48d8-4c39-8cda-5e95161532e4")
107107
.expect(200);
108108
const {
@@ -116,7 +116,7 @@ describe("GET /folder", () => {
116116
mockExtractUserEmailFromAuthToken();
117117
mockExtractShareTokenFromHeaders("56f7c246-e4ec-41f3-b117-6df4c9377075");
118118
const response = await agent
119-
.get("/api/v2/folder?folderIds[]=2")
119+
.get("/api/v2/folders?folderIds[]=2")
120120
.set("X-Permanent-Share-Token", "56f7c246-e4ec-41f3-b117-6df4c9377075")
121121
.expect(200);
122122
const {
@@ -130,7 +130,7 @@ describe("GET /folder", () => {
130130
mockExtractUserEmailFromAuthToken();
131131
mockExtractShareTokenFromHeaders("7d6412af-5abe-4acb-808a-64e9ce3b7535");
132132
const response = await agent
133-
.get("/api/v2/folder?folderIds[]=2")
133+
.get("/api/v2/folders?folderIds[]=2")
134134
.set("X-Permanent-Share-Token", "7d6412af-5abe-4acb-808a-64e9ce3b7535")
135135
.expect(200);
136136
const {
@@ -143,7 +143,7 @@ describe("GET /folder", () => {
143143
mockExtractUserEmailFromAuthToken();
144144
mockExtractShareTokenFromHeaders("9cc057f0-d3e8-41df-94d6-9b315b4921af");
145145
const response = await agent
146-
.get("/api/v2/folder?folderIds[]=2")
146+
.get("/api/v2/folders?folderIds[]=2")
147147
.set("X-Permanent-Share-Token", "9cc057f0-d3e8-41df-94d6-9b315b4921af")
148148
.expect(200);
149149
const {
@@ -155,7 +155,7 @@ describe("GET /folder", () => {
155155
test("should return a private folder if the folder is shared with the caller", async () => {
156156
mockExtractUserEmailFromAuthToken("[email protected]");
157157
const response = await agent
158-
.get("/api/v2/folder?folderIds[]=2")
158+
.get("/api/v2/folders?folderIds[]=2")
159159
.expect(200);
160160
const {
161161
body: { items: folders },
@@ -167,7 +167,7 @@ describe("GET /folder", () => {
167167
test("should not return a private folder if caller access relies on a deleted share", async () => {
168168
mockExtractUserEmailFromAuthToken("[email protected]");
169169
const response = await agent
170-
.get("/api/v2/folder?folderIds[]=2")
170+
.get("/api/v2/folders?folderIds[]=2")
171171
.expect(200);
172172
const {
173173
body: { items: folders },
@@ -178,7 +178,7 @@ describe("GET /folder", () => {
178178
test("should not return a private folder if caller access relies on a share to an archive caller can no longer access", async () => {
179179
mockExtractUserEmailFromAuthToken("[email protected]");
180180
const response = await agent
181-
.get("/api/v2/folder?folderIds[]=2")
181+
.get("/api/v2/folders?folderIds[]=2")
182182
.expect(200);
183183
const {
184184
body: { items: folders },
@@ -188,7 +188,7 @@ describe("GET /folder", () => {
188188

189189
test("should return all folder data", async () => {
190190
const response = await agent
191-
.get("/api/v2/folder?folderIds[]=2")
191+
.get("/api/v2/folders?folderIds[]=2")
192192
.expect(200);
193193
const {
194194
body: { items: folders },
@@ -282,7 +282,7 @@ describe("GET /folder", () => {
282282

283283
test("should retrieve multiple folders if requested", async () => {
284284
const response = await agent
285-
.get("/api/v2/folder?folderIds[]=2&folderIds[]=1")
285+
.get("/api/v2/folders?folderIds[]=2&folderIds[]=1")
286286
.expect(200);
287287
const {
288288
body: { items: folders },
@@ -292,7 +292,7 @@ describe("GET /folder", () => {
292292

293293
test("should not retrieve a deleted folder", async () => {
294294
const response = await agent
295-
.get("/api/v2/folder?folderIds[]=4")
295+
.get("/api/v2/folders?folderIds[]=4")
296296
.expect(200);
297297
const {
298298
body: { items: folders },
@@ -302,7 +302,7 @@ describe("GET /folder", () => {
302302

303303
test("should not retrieve a folder with a deleted folder_link", async () => {
304304
const response = await agent
305-
.get("/api/v2/folder?folderIds[]=3")
305+
.get("/api/v2/folders?folderIds[]=3")
306306
.expect(200);
307307
const {
308308
body: { items: folders },
@@ -312,7 +312,7 @@ describe("GET /folder", () => {
312312

313313
test("should omit size from a folder with a deleted folder_size", async () => {
314314
const response = await agent
315-
.get("/api/v2/folder?folderIds[]=7")
315+
.get("/api/v2/folders?folderIds[]=7")
316316
.expect(200);
317317
const {
318318
body: { items: folders },
@@ -323,6 +323,6 @@ describe("GET /folder", () => {
323323

324324
test("should throw a 500 error if database call fails", async () => {
325325
jest.spyOn(db, "sql").mockRejectedValue(new Error("test error"));
326-
await agent.get("/api/v2/folder?folderIds[]=2").expect(500);
326+
await agent.get("/api/v2/folders?folderIds[]=2").expect(500);
327327
});
328328
});

packages/api/src/folder/controller/get_folder_children.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ describe("GET /folder/{id}/children", () => {
3333
});
3434

3535
test("should return 200 on a valid request", async () => {
36-
await agent.get("/api/v2/folder/1/children?pageSize=100").expect(200);
36+
await agent.get("/api/v2/folders/1/children?pageSize=100").expect(200);
3737
});
3838

3939
test("should call extractUserEmailFromAuthToken middleware", async () => {
40-
await agent.get("/api/v2/folder/1/children?pageSize=100").expect(200);
40+
await agent.get("/api/v2/folders/1/children?pageSize=100").expect(200);
4141
expect(extractUserEmailFromAuthToken).toHaveBeenCalled();
4242
});
4343

4444
test("should call extractShareTokenFromHeaders middleware", async () => {
45-
await agent.get("/api/v2/folder/1/children?pageSize=100").expect(200);
45+
await agent.get("/api/v2/folders/1/children?pageSize=100").expect(200);
4646
expect(extractShareTokenFromHeaders).toHaveBeenCalled();
4747
});
4848

4949
test("should return 400 code if the header values are invalid", async () => {
5050
mockExtractUserEmailFromAuthToken("not_an_email");
51-
await agent.get("/api/v2/folder/1/children").expect(400);
51+
await agent.get("/api/v2/folders/1/children").expect(400);
5252
});
5353

5454
test("should return 400 code if the query parameters are invalid", async () => {
55-
await agent.get("/api/v2/folder/1/children?cursor=1").expect(400);
55+
await agent.get("/api/v2/folders/1/children?cursor=1").expect(400);
5656
});
5757

5858
test("should return the whole folder object", async () => {
5959
const response = await agent
60-
.get("/api/v2/folder/10/children?pageSize=100")
60+
.get("/api/v2/folders/10/children?pageSize=100")
6161
.expect(200);
6262
const {
6363
body: { items: children },
@@ -149,7 +149,7 @@ describe("GET /folder/{id}/children", () => {
149149

150150
test("should return the whole record object", async () => {
151151
const response = await agent
152-
.get("/api/v2/folder/10/children?pageSize=100")
152+
.get("/api/v2/folders/10/children?pageSize=100")
153153
.expect(200);
154154
const {
155155
body: { items: children },
@@ -279,7 +279,7 @@ describe("GET /folder/{id}/children", () => {
279279

280280
test("should return folder contents in alphabetical ascending order", async () => {
281281
const response = await agent
282-
.get("/api/v2/folder/10/children?pageSize=100")
282+
.get("/api/v2/folders/10/children?pageSize=100")
283283
.expect(200);
284284
const {
285285
body: { items: children },
@@ -294,7 +294,7 @@ describe("GET /folder/{id}/children", () => {
294294
"UPDATE folder SET sort = 'sort.alphabetical_desc' WHERE folderid = 10",
295295
);
296296
const response = await agent
297-
.get("/api/v2/folder/10/children?pageSize=100")
297+
.get("/api/v2/folders/10/children?pageSize=100")
298298
.expect(200);
299299
const {
300300
body: { items: children },
@@ -309,7 +309,7 @@ describe("GET /folder/{id}/children", () => {
309309
"UPDATE folder SET sort = 'sort.display_date_asc' WHERE folderid = 10",
310310
);
311311
const response = await agent
312-
.get("/api/v2/folder/10/children?pageSize=100")
312+
.get("/api/v2/folders/10/children?pageSize=100")
313313
.expect(200);
314314
const {
315315
body: { items: children },
@@ -324,7 +324,7 @@ describe("GET /folder/{id}/children", () => {
324324
"UPDATE folder SET sort = 'sort.display_date_desc' WHERE folderid = 10",
325325
);
326326
const response = await agent
327-
.get("/api/v2/folder/10/children?pageSize=100")
327+
.get("/api/v2/folders/10/children?pageSize=100")
328328
.expect(200);
329329
const {
330330
body: { items: children },
@@ -339,7 +339,7 @@ describe("GET /folder/{id}/children", () => {
339339
"UPDATE folder SET sort = 'sort.type_asc' WHERE folderid = 10",
340340
);
341341
const response = await agent
342-
.get("/api/v2/folder/10/children?pageSize=100")
342+
.get("/api/v2/folders/10/children?pageSize=100")
343343
.expect(200);
344344
const {
345345
body: { items: children },
@@ -354,7 +354,7 @@ describe("GET /folder/{id}/children", () => {
354354
"UPDATE folder SET sort = 'sort.type_desc' WHERE folderid = 10",
355355
);
356356
const response = await agent
357-
.get("/api/v2/folder/10/children?pageSize=100")
357+
.get("/api/v2/folders/10/children?pageSize=100")
358358
.expect(200);
359359
const {
360360
body: { items: children },
@@ -367,7 +367,7 @@ describe("GET /folder/{id}/children", () => {
367367
test("should return an empty list if the caller doesn't have access to the folder", async () => {
368368
mockExtractUserEmailFromAuthToken("[email protected]");
369369
const response = await agent
370-
.get("/api/v2/folder/2/children?pageSize=100")
370+
.get("/api/v2/folders/2/children?pageSize=100")
371371
.expect(200);
372372
const {
373373
body: { items: children },
@@ -377,7 +377,7 @@ describe("GET /folder/{id}/children", () => {
377377

378378
test("should return no more than pageSize items", async () => {
379379
const response = await agent
380-
.get("/api/v2/folder/10/children?pageSize=1")
380+
.get("/api/v2/folders/10/children?pageSize=1")
381381
.expect(200);
382382
const {
383383
body: { items: children },
@@ -387,7 +387,7 @@ describe("GET /folder/{id}/children", () => {
387387

388388
test("should only return items past the cursor", async () => {
389389
const response = await agent
390-
.get("/api/v2/folder/10/children?pageSize=1&cursor=1")
390+
.get("/api/v2/folders/10/children?pageSize=1&cursor=1")
391391
.expect(200);
392392
const {
393393
body: { items: children },
@@ -398,7 +398,7 @@ describe("GET /folder/{id}/children", () => {
398398

399399
test("should include pagination data in response", async () => {
400400
const response = await agent
401-
.get("/api/v2/folder/10/children?pageSize=1")
401+
.get("/api/v2/folders/10/children?pageSize=1")
402402
.expect(200);
403403
const {
404404
body: { pagination: paginationData },
@@ -415,13 +415,13 @@ describe("GET /folder/{id}/children", () => {
415415
expect(paginationData.nextPage).toEqual(
416416
`https://${
417417
process.env["SITE_URL"] ?? ""
418-
}/api/v2/folder/10/children?pageSize=1&cursor=1`,
418+
}/api/v2/folders/10/children?pageSize=1&cursor=1`,
419419
);
420420
expect(paginationData.totalPages).toEqual(2);
421421
});
422422

423423
test("should return 500 if the database call fails", async () => {
424424
jest.spyOn(db, "sql").mockRejectedValue(new Error("test error"));
425-
await agent.get("/api/v2/folder/10/children?pageSize=1").expect(500);
425+
await agent.get("/api/v2/folders/10/children?pageSize=1").expect(500);
426426
});
427427
});

packages/api/src/folder/controller/get_folder_share_links.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("GET /folder/{id}/share_links", () => {
3333

3434
test("expect to return share links for a folder", async () => {
3535
const response = await agent
36-
.get("/api/v2/folder/2/share_links")
36+
.get("/api/v2/folders/2/share_links")
3737
.expect(200);
3838

3939
const {
@@ -55,7 +55,7 @@ describe("GET /folder/{id}/share_links", () => {
5555

5656
test("expect an empty list if folder doesn't exist", async () => {
5757
const response = await agent
58-
.get("/api/v2/folder/999/share_links")
58+
.get("/api/v2/folders/999/share_links")
5959
.expect(200);
6060

6161
const {
@@ -70,7 +70,7 @@ describe("GET /folder/{id}/share_links", () => {
7070
"b5461dc2-1eb0-450e-b710-fef7b2cafe1e",
7171
);
7272
const response = await agent
73-
.get("/api/v2/folder/2/share_links")
73+
.get("/api/v2/folders/2/share_links")
7474
.expect(200);
7575

7676
const {
@@ -85,7 +85,7 @@ describe("GET /folder/{id}/share_links", () => {
8585
throw testError;
8686
});
8787

88-
await agent.get("/api/v2/folder/1/share_links").expect(500);
88+
await agent.get("/api/v2/folders/1/share_links").expect(500);
8989
expect(logger.error).toHaveBeenCalledWith(testError);
9090
});
9191

@@ -95,11 +95,11 @@ describe("GET /folder/{id}/share_links", () => {
9595
.mockImplementation(async (_, __, next: NextFunction) => {
9696
next(createError.Unauthorized("Invalid auth token"));
9797
});
98-
await agent.get("/api/v2/folder/1/share_links").expect(401);
98+
await agent.get("/api/v2/folders/1/share_links").expect(401);
9999
});
100100

101101
test("expect 400 if the header values are missing", async () => {
102102
mockVerifyUserAuthentication();
103-
await agent.get("/api/v2/folder/1/share_links").expect(400);
103+
await agent.get("/api/v2/folders/1/share_links").expect(400);
104104
});
105105
});

0 commit comments

Comments
 (0)