Skip to content

Commit dd1549e

Browse files
committed
review comments
1 parent 3379c94 commit dd1549e

File tree

20 files changed

+67
-57
lines changed

20 files changed

+67
-57
lines changed

backend/__tests__/__integration__/dal/leaderboards.isolated.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ describe("LeaderboardsDal", () => {
6060
)) as DBLeaderboardEntry[];
6161

6262
//THEN
63-
const lb = results.map((it) => omit(it, "_id"));
63+
64+
const lb = results.map((it) => omit(it, ["_id"]));
6465

6566
expect(lb).toEqual([
6667
expectedLbEntry("15", { rank: 1, user: rank1 }),
@@ -87,8 +88,7 @@ describe("LeaderboardsDal", () => {
8788
)) as LeaderboardsDal.DBLeaderboardEntry[];
8889

8990
//THEN
90-
91-
const lb = results.map((it) => omit(it, "_id"));
91+
const lb = results.map((it) => omit(it, ["_id"]));
9292

9393
expect(lb).toEqual([
9494
expectedLbEntry("60", { rank: 1, user: rank1 }),
@@ -202,7 +202,7 @@ describe("LeaderboardsDal", () => {
202202
)) as DBLeaderboardEntry[];
203203

204204
//THEN
205-
const lb = result.map((it) => omit(it, "_id"));
205+
const lb = result.map((it) => omit(it, ["_id"]));
206206

207207
expect(lb).toEqual([
208208
expectedLbEntry("15", { rank: 1, user: noBadge }),
@@ -241,7 +241,7 @@ describe("LeaderboardsDal", () => {
241241
)) as DBLeaderboardEntry[];
242242

243243
//THEN
244-
const lb = result.map((it) => omit(it, "_id"));
244+
const lb = result.map((it) => omit(it, ["_id"]));
245245

246246
expect(lb).toEqual([
247247
expectedLbEntry("15", { rank: 1, user: noPremium }),
@@ -299,7 +299,7 @@ describe("LeaderboardsDal", () => {
299299
)) as LeaderboardsDal.DBLeaderboardEntry[];
300300

301301
//THEN
302-
const lb = results.map((it) => omit(it, "_id"));
302+
const lb = results.map((it) => omit(it, ["_id"]));
303303

304304
expect(lb).toEqual([
305305
expectedLbEntry("60", { rank: 3, user: rank3 }),
@@ -338,7 +338,7 @@ describe("LeaderboardsDal", () => {
338338
)) as LeaderboardsDal.DBLeaderboardEntry[];
339339

340340
//THEN
341-
const lb = results.map((it) => omit(it, "_id"));
341+
const lb = results.map((it) => omit(it, ["_id"]));
342342

343343
expect(lb).toEqual([
344344
expectedLbEntry("60", { rank: 1, user: rank1, friendsRank: 1 }),
@@ -377,7 +377,7 @@ describe("LeaderboardsDal", () => {
377377
)) as LeaderboardsDal.DBLeaderboardEntry[];
378378

379379
//THEN
380-
const lb = results.map((it) => omit(it, "_id"));
380+
const lb = results.map((it) => omit(it, ["_id"]));
381381

382382
expect(lb).toEqual([
383383
expectedLbEntry("60", { rank: 4, user: rank4, friendsRank: 3 }),

backend/__tests__/api/controllers/connections.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import app from "../../../src/app";
44
import { mockBearerAuthentication } from "../../__testData__/auth";
55
import * as Configuration from "../../../src/init/configuration";
66
import { ObjectId } from "mongodb";
7-
import _ from "lodash";
87
import * as ConnectionsDal from "../../../src/dal/connections";
98
import * as UserDal from "../../../src/dal/user";
109

@@ -383,14 +382,14 @@ describe("ConnectionsController", () => {
383382
});
384383

385384
async function enableConnectionsEndpoints(enabled: boolean): Promise<void> {
386-
const mockConfig = _.merge(await configuration, {
387-
connections: { enabled },
388-
});
385+
const mockConfig = await configuration;
386+
mockConfig.connections = { ...mockConfig.connections, enabled };
389387

390388
vi.spyOn(Configuration, "getCachedConfiguration").mockResolvedValue(
391389
mockConfig
392390
);
393391
}
392+
394393
async function expectFailForDisabledEndpoint(call: SuperTest): Promise<void> {
395394
await enableConnectionsEndpoints(false);
396395
const { body } = await call.expect(503);

backend/__tests__/api/controllers/leaderboard.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,11 +1451,9 @@ async function weeklyLeaderboardEnabled(enabled: boolean): Promise<void> {
14511451
mockConfig
14521452
);
14531453
}
1454-
14551454
async function enableConnectionsFeature(enabled: boolean): Promise<void> {
1456-
const mockConfig = _.merge(await configuration, {
1457-
connections: { enabled: { enabled } },
1458-
});
1455+
const mockConfig = await configuration;
1456+
mockConfig.connections = { ...mockConfig.connections, enabled };
14591457

14601458
vi.spyOn(Configuration, "getCachedConfiguration").mockResolvedValue(
14611459
mockConfig

backend/__tests__/api/controllers/result.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,14 @@ describe("result controller test", () => {
489489
it("should apply defaults on missing data", async () => {
490490
//GIVEN
491491
const result = givenDbResult(uid);
492-
const partialResult = omit(
493-
result,
492+
const partialResult = omit(result, [
494493
"difficulty",
495494
"language",
496495
"funbox",
497496
"lazyMode",
498497
"punctuation",
499-
"numbers"
500-
);
498+
"numbers",
499+
]);
501500

502501
const resultIdString = result._id.toHexString();
503502
const tagIds = [

backend/__tests__/api/controllers/user.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,14 +4042,14 @@ async function enableReporting(enabled: boolean): Promise<void> {
40424042
}
40434043

40444044
async function enableConnectionsEndpoints(enabled: boolean): Promise<void> {
4045-
const mockConfig = _.merge(await configuration, {
4046-
connections: { enabled },
4047-
});
4045+
const mockConfig = await configuration;
4046+
mockConfig.connections = { ...mockConfig.connections, enabled };
40484047

40494048
vi.spyOn(Configuration, "getCachedConfiguration").mockResolvedValue(
40504049
mockConfig
40514050
);
40524051
}
4052+
40534053
async function expectFailForDisabledEndpoint(call: SuperTest): Promise<void> {
40544054
await enableConnectionsEndpoints(false);
40554055
const { body } = await call.expect(503);

backend/__tests__/utils/misc.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,26 @@ describe("Misc Utils", () => {
408408
describe("omit()", () => {
409409
it("should omit a single key", () => {
410410
const input = { a: 1, b: 2, c: 3 };
411-
const result = Misc.omit(input, "b");
411+
const result = Misc.omit(input, ["b"]);
412412
expect(result).toEqual({ a: 1, c: 3 });
413413
});
414414

415415
it("should omit multiple keys", () => {
416416
const input = { a: 1, b: 2, c: 3, d: 4 };
417-
const result = Misc.omit(input, "a", "d");
417+
const result = Misc.omit(input, ["a", "d"]);
418418
expect(result).toEqual({ b: 2, c: 3 });
419419
});
420420

421421
it("should return the same object if no keys are omitted", () => {
422422
const input = { x: 1, y: 2 };
423-
const result = Misc.omit(input);
423+
const result = Misc.omit(input, []);
424424
expect(result).toEqual({ x: 1, y: 2 });
425425
});
426426

427427
it("should not mutate the original object", () => {
428428
const input = { foo: "bar", baz: "qux" };
429429
const copy = { ...input };
430-
Misc.omit(input, "baz");
430+
Misc.omit(input, ["baz"]);
431431
expect(input).toEqual(copy);
432432
});
433433

@@ -445,7 +445,7 @@ describe("Misc Utils", () => {
445445
obj: { x: 1 },
446446
arr: [1, 2, 3],
447447
};
448-
const result = Misc.omit(input, "bool", "arr");
448+
const result = Misc.omit(input, ["bool", "arr"]);
449449
expect(result).toEqual({
450450
str: "hello",
451451
num: 123,

backend/src/api/controllers/ape-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ApeKey } from "@monkeytype/schemas/ape-keys";
1717
import { MonkeyRequest } from "../types";
1818

1919
function cleanApeKey(apeKey: ApeKeysDAL.DBApeKey): ApeKey {
20-
return omit(apeKey, "hash", "_id", "uid", "useCount") as ApeKey;
20+
return omit(apeKey, ["hash", "_id", "uid", "useCount"]) as ApeKey;
2121
}
2222

2323
export async function getApeKeys(

backend/src/api/controllers/connections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { MonkeyRequest } from "../types";
1010
import { MonkeyResponse } from "../../utils/monkey-response";
1111
import * as ConnectionsDal from "../../dal/connections";
1212
import * as UserDal from "../../dal/user";
13-
import { replaceObjectId } from "../../utils/misc";
13+
import { replaceObjectId, omit } from "../../utils/misc";
1414
import MonkeyError from "../../utils/error";
15-
import { omit } from "lodash";
15+
1616
import { Connection } from "@monkeytype/schemas/connections";
1717

1818
function convert(db: ConnectionsDal.DBConnection): Connection {
19-
return replaceObjectId(omit(db, "key"));
19+
return replaceObjectId(omit(db, ["key"]));
2020
}
2121
export async function getConnections(
2222
req: MonkeyRequest<GetConnectionsQuery>

backend/src/api/controllers/leaderboard.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function getLeaderboard(
6868
language,
6969
friendsOnlyUid
7070
);
71-
const normalizedLeaderboard = leaderboard.map((it) => omit(it, "_id"));
71+
const normalizedLeaderboard = leaderboard.map((it) => omit(it, ["_id"]));
7272

7373
return new MonkeyResponse("Leaderboard retrieved", {
7474
count,
@@ -98,7 +98,10 @@ export async function getRankFromLeaderboard(
9898
);
9999
}
100100

101-
return new MonkeyResponse("Rank retrieved", _.omit(data, "_id"));
101+
return new MonkeyResponse(
102+
"Rank retrieved",
103+
omit(data as LeaderboardsDAL.DBLeaderboardEntry, ["_id"])
104+
);
102105
}
103106

104107
function getDailyLeaderboardWithError(

backend/src/api/controllers/result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export async function addResult(
224224

225225
const resulthash = completedEvent.hash;
226226
if (req.ctx.configuration.results.objectHashCheckEnabled) {
227-
const objectToHash = omit(completedEvent, "hash");
227+
const objectToHash = omit(completedEvent, ["hash"]);
228228
const serverhash = objectHash(objectToHash);
229229
if (serverhash !== resulthash) {
230230
void addLog(

0 commit comments

Comments
 (0)