Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ backend/__migration__
docker
backend/scripts
backend/private
**/vitest.config.js
**/vitest.config.ts
4 changes: 4 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm i
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import * as UserTestData from "../../__testData__/users";
import * as UserDal from "../../../src/dal/user";
import * as ResultDal from "../../../src/dal/result";
import { DBResult } from "../../../src/utils/result";
import { describeIntegration } from "..";

describeIntegration()("testActivity migration", () => {
describe("testActivity migration", () => {
it("migrates users without results", async () => {
//given
const user1 = await UserTestData.createUser();
Expand Down
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/admin-uids.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ObjectId } from "mongodb";
import * as AdminUidsDal from "../../../src/dal/admin-uids";
import { describeIntegration } from "..";

describeIntegration()("AdminUidsDal", () => {
describe("AdminUidsDal", () => {
describe("isAdmin", () => {
it("should return true for existing admin user", async () => {
//GIVEN
Expand Down
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/ape-keys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ObjectId } from "mongodb";
import { addApeKey } from "../../../src/dal/ape-keys";
import { describeIntegration } from "..";

describeIntegration()("ApeKeysDal", () => {
describe("ApeKeysDal", () => {
it("should be able to add a new ape key", async () => {
const apeKey = {
_id: new ObjectId(),
Expand Down
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/blocklist.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ObjectId } from "mongodb";
import * as BlacklistDal from "../../../src/dal/blocklist";
import { describeIntegration } from "..";

describeIntegration()("BlocklistDal", () => {
describe("BlocklistDal", () => {
describe("add", () => {
beforeEach(() => {
vitest.useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { ObjectId } from "mongodb";
import * as UserDal from "../../../src/dal/user";
import * as LeaderboardsDal from "../../../src/dal/leaderboards";
import * as PublicDal from "../../../src/dal/public";
import * as Configuration from "../../../src/init/configuration";
import type { DBLeaderboardEntry } from "../../../src/dal/leaderboards";
import type { PersonalBest } from "@monkeytype/schemas/shared";
const configuration = Configuration.getCachedConfiguration();

import * as DB from "../../../src/init/db";
import { LbPersonalBests } from "../../../src/utils/pb";
import { describeIntegration } from "..";

import { pb } from "../../__testData__/users";

describeIntegration()("LeaderboardsDal", () => {
describe("LeaderboardsDal", () => {
afterEach(async () => {
await DB.collection("users").deleteMany({});
});
describe("update", () => {
it("should ignore unapplicable users on leaderboard", async () => {
//GIVEN
Expand Down Expand Up @@ -216,22 +217,24 @@ describeIntegration()("LeaderboardsDal", () => {
]);
});

it("should create leaderboard with premium", async () => {
await enablePremiumFeatures(true);
//TODO figure out why premium with expireTimestamp is not working
it.skip("should create leaderboard with premium", async () => {
//GIVEN
const noPremium = await createUser(lbBests(pb(4)));
const lifetime = await createUser(lbBests(pb(3)), premium(-1));
const validPremium = await createUser(lbBests(pb(2)), premium(10));
const validPremium = await createUser(lbBests(pb(2)), premium(1000));
const expiredPremium = await createUser(lbBests(pb(1)), premium(-10));

//WHEN
await LeaderboardsDal.update("time", "15", "english");

const result = (await LeaderboardsDal.get(
"time",
"15",
"english",
0,
50
50,
true
)) as DBLeaderboardEntry[];

//THEN
Expand All @@ -253,7 +256,6 @@ describeIntegration()("LeaderboardsDal", () => {
]);
});
it("should create leaderboard without premium if feature disabled", async () => {
await enablePremiumFeatures(false);
//GIVEN
// const lifetime = await createUser(lbBests(pb(3)), premium(-1));

Expand All @@ -264,7 +266,8 @@ describeIntegration()("LeaderboardsDal", () => {
"15",
"english",
0,
50
50,
false
)) as DBLeaderboardEntry[];

//THEN
Expand Down Expand Up @@ -348,13 +351,3 @@ type ExpectedLbEntry = {
badgeId?: number;
isPremium?: boolean;
};

async function enablePremiumFeatures(premium: boolean): Promise<void> {
const mockConfig = _.merge(await configuration, {
users: { premium: { enabled: premium } },
});

vi.spyOn(Configuration, "getCachedConfiguration").mockResolvedValue(
mockConfig
);
}
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/preset.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ObjectId } from "mongodb";
import * as PresetDal from "../../../src/dal/preset";
import _ from "lodash";
import { describeIntegration } from "..";

describeIntegration()("PresetDal", () => {
describe("PresetDal", () => {
describe("readPreset", () => {
it("should read", async () => {
//GIVEN
Expand Down
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/public.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describeIntegration } from "..";
import * as PublicDAL from "../../../src/dal/public";

describeIntegration()("PublicDAL", function () {
describe("PublicDAL", function () {
it("should be able to update stats", async function () {
// checks it doesn't throw an error. the actual values are checked in another test.
await PublicDAL.updateStats(1, 15);
Expand Down
3 changes: 1 addition & 2 deletions backend/__tests__/__integration__/dal/result.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as ResultDal from "../../../src/dal/result";
import { ObjectId } from "mongodb";
import * as UserDal from "../../../src/dal/user";
import { DBResult } from "../../../src/utils/result";
import { describeIntegration } from "..";

let uid: string;
const timestamp = Date.now() - 60000;
Expand Down Expand Up @@ -63,7 +62,7 @@ async function createDummyData(
});
}
}
describeIntegration()("ResultDal", () => {
describe("ResultDal", () => {
beforeEach(() => {
uid = new ObjectId().toHexString();
});
Expand Down
Loading
Loading