Skip to content

Commit

Permalink
refactor: result types (#4980)
Browse files Browse the repository at this point in the history
* further shared improvements
 - moved more types to shared
 - reworked the way results are typed

THIS COULD CHANGE LOGIC, TEST THIS

* removed comment

* update the way completed event is built on the client

* remove unnecessary property

* comment

* move hash check higher

* remove todo

* fix incorrect type

* updated type
remove field if undefined
  • Loading branch information
Miodec authored Feb 1, 2024
1 parent 0920010 commit 8b48347
Show file tree
Hide file tree
Showing 41 changed files with 717 additions and 748 deletions.
8 changes: 4 additions & 4 deletions backend/__tests__/dal/leaderboards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe("LeaderboardsDal", () => {
});

function expectedLbEntry(rank: number, user: MonkeyTypes.User, time: string) {
const lbBest: MonkeyTypes.PersonalBest =
const lbBest: SharedTypes.PersonalBest =
user.lbPersonalBests?.time[time].english;

return {
Expand Down Expand Up @@ -166,8 +166,8 @@ async function createUser(
}

function lbBests(
pb15?: MonkeyTypes.PersonalBest,
pb60?: MonkeyTypes.PersonalBest
pb15?: SharedTypes.PersonalBest,
pb60?: SharedTypes.PersonalBest
): MonkeyTypes.LbPersonalBests {
const result = { time: {} };
if (pb15) result.time["15"] = { english: pb15 };
Expand All @@ -179,7 +179,7 @@ function pb(
wpm: number,
acc: number = 90,
timestamp: number = 1
): MonkeyTypes.PersonalBest {
): SharedTypes.PersonalBest {
return {
acc,
consistency: 100,
Expand Down
4 changes: 3 additions & 1 deletion backend/__tests__/dal/result.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ResultDal from "../../src/dal/result";
import { ObjectId } from "mongodb";
import * as UserDal from "../../src/dal/user";

type MonkeyTypesResult = MonkeyTypes.Result<MonkeyTypes.Mode>;
type MonkeyTypesResult = SharedTypes.DBResult<SharedTypes.Mode>;

let uid: string = "";
const timestamp = Date.now() - 60000;
Expand Down Expand Up @@ -55,6 +55,8 @@ async function createDummyData(
keyDurationStats: { average: 0, sd: 0 },
difficulty: "normal",
language: "english",
isPb: false,
name: "Test",
} as MonkeyTypesResult);
}
}
Expand Down
8 changes: 6 additions & 2 deletions backend/__tests__/dal/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const mockPersonalBest = {
timestamp: 13123123,
};

const mockResultFilter = {
_id: new ObjectId(),
const mockResultFilter: SharedTypes.ResultFilters = {
_id: "id",
name: "sfdkjhgdf",
pb: {
no: true,
yes: true,
},
difficulty: {
normal: true,
expert: false,
Expand Down
Loading

0 comments on commit 8b48347

Please sign in to comment.