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
3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=26.0.1-tem
2 changes: 2 additions & 0 deletions exclusions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export const backendExclusions = [
export const frontendExclusions = [
`${frontendBaseDir}/**/*.test.ts`,
`${frontendBaseDir}/**/*.test.tsx`,
`${frontendBaseDir}/lib/api/queries/**/*.ts`,
`${frontendBaseDir}/lib/api/schema/**/*.ts`,
];
2 changes: 2 additions & 0 deletions js/src/lib/api/queries/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useQuery } from "@tanstack/react-query";

/**
Expand Down Expand Up @@ -28,6 +29,7 @@ async function validateAuthentication({
const json = res(await response.json());

if (json.success) {
await sleep(350);
return {
session: json.payload.session,
user: json.payload.user,
Expand Down
5 changes: 5 additions & 0 deletions js/src/lib/api/queries/auth/leetcode/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

/**
Expand Down Expand Up @@ -45,6 +46,8 @@ async function updateLeetcodeUsername({
}),
});

await sleep(350);

return res(await response.json());
}

Expand All @@ -57,5 +60,7 @@ async function getLeetcodeQueryKey({
method,
});

await sleep(350);

return res(await response.json());
}
3 changes: 3 additions & 0 deletions js/src/lib/api/queries/club/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

export const useClubQuery = ({ clubSlug }: { clubSlug: string }) => {
Expand All @@ -25,6 +26,8 @@ async function fetchClubDto({
method,
});

await sleep(650);

return res(await response.json());
}

Expand Down
3 changes: 3 additions & 0 deletions js/src/lib/api/queries/embed/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useQuery } from "@tanstack/react-query";

export const useFetchPotdEmbedQuery = () => {
Expand All @@ -22,6 +23,8 @@ async function fetchPotdEmbed({
method,
});

await sleep(750);

const json = res(await response.json());

return json;
Expand Down
13 changes: 13 additions & 0 deletions js/src/lib/api/queries/leaderboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { ApiUtils } from "@/lib/api/utils";
import { sleep } from "@/lib/api/utils/lag";
import { useFilters } from "@/lib/hooks/useFilters";
import { usePagination } from "@/lib/hooks/usePagination";
import { useURLState } from "@/lib/hooks/useUrlState";
Expand Down Expand Up @@ -421,6 +422,8 @@ async function fetchLeaderboardUsers({
method,
});

await sleep(800);

const json = res(await response.json());

return json;
Expand All @@ -435,6 +438,8 @@ async function fetchLeaderboardUsersByLeaderboardId({
method,
});

await sleep(800);

const json = res(await response.json());

return json;
Expand All @@ -449,6 +454,8 @@ async function getCurrentLeaderboardMetadata({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand All @@ -463,6 +470,8 @@ async function getLeaderboardMetadataById({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand Down Expand Up @@ -496,6 +505,8 @@ export async function getMyRecentLeaderboardData({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand All @@ -510,6 +521,8 @@ async function fetchAllLeaderboardsMetadata({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand Down
3 changes: 3 additions & 0 deletions js/src/lib/api/queries/potd/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useQuery } from "@tanstack/react-query";

export const useFetchPotdQuery = () => {
Expand All @@ -22,6 +23,8 @@ async function fetchPotd({
method,
});

await sleep(750);

const json = res(await response.json());

return json;
Expand Down
3 changes: 3 additions & 0 deletions js/src/lib/api/queries/submissions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { sleep } from "@/lib/api/utils/lag";
import { useQuery } from "@tanstack/react-query";

/**
Expand Down Expand Up @@ -32,6 +33,8 @@ async function fetchSubmissionDetails({
const response = await fetch(url, {
method,
});

await sleep(750);
const json = res(await response.json());

return json;
Expand Down
7 changes: 7 additions & 0 deletions js/src/lib/api/queries/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiURL } from "@/lib/api/common/apiURL";
import { LeetcodeTopicEnum } from "@/lib/api/types/schema";
import { sleep } from "@/lib/api/utils/lag";
import { usePagination } from "@/lib/hooks/usePagination";
import useURLDateRange from "@/lib/hooks/useURLDateRange";
import { useURLState } from "@/lib/hooks/useUrlState";
Expand Down Expand Up @@ -312,6 +313,8 @@ async function fetchUserProfile({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand All @@ -326,6 +329,8 @@ async function fetchUserSubmissions({
method,
});

await sleep(500);

const json = res(await response.json());
return json;
}
Expand All @@ -339,6 +344,8 @@ async function fetchAllUsers({
method,
});

await sleep(650);

const json = res(await response.json());

return json;
Expand Down
8 changes: 8 additions & 0 deletions js/src/lib/api/utils/lag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function sleep(ms: number) {
if (import.meta.env.MODE === "test") return;
return await new Promise<void>((resolve) => {
setTimeout(() => {
resolve(void 0);
}, ms);
});
}
40 changes: 40 additions & 0 deletions js/src/lib/api/utils/sleep.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { sleep } from "@/lib/api/utils/lag";
import { afterEach, describe, expect, it, vi } from "vitest";

describe("sleep", () => {
beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.useRealTimers();
vi.unstubAllEnvs();
});

it("skips delay in test environment", async () => {
let resolved = false;
sleep(10_000).then(() => {
resolved = true;
});

await vi.advanceTimersByTimeAsync(0);

expect(resolved).toBe(true);
expect(vi.getTimerCount()).toBe(0);
});

it("waits when not in test environment", async () => {
vi.stubEnv("MODE", "production");

let resolved = false;
void sleep(1_000).then(() => {
resolved = true;
});

await vi.advanceTimersByTimeAsync(0);
expect(resolved).toBe(false);

await vi.advanceTimersByTimeAsync(1_000);
expect(resolved).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.patinanetwork.codebloom.common.email.options.SendEmailOptions;
import org.patinanetwork.codebloom.common.email.template.ReactEmailTemplater;
import org.patinanetwork.codebloom.common.jwt.JWTClient;
import org.patinanetwork.codebloom.common.lag.FakeLag;
import org.patinanetwork.codebloom.common.reporter.Reporter;
import org.patinanetwork.codebloom.common.reporter.report.Report;
import org.patinanetwork.codebloom.common.schools.SchoolEnum;
Expand Down Expand Up @@ -107,7 +106,6 @@ public AuthController(
@GetMapping("/validate")
public ResponseEntity<ApiResponder<AuthenticationObjectDto>> validateAuth(
@Protected final AuthenticationObject authenticationObject) {
FakeLag.sleep(350);

return ResponseEntity.ok()
.body(ApiResponder.success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.patinanetwork.codebloom.common.db.repos.club.ClubRepository;
import org.patinanetwork.codebloom.common.db.repos.usertag.UserTagRepository;
import org.patinanetwork.codebloom.common.dto.ApiResponder;
import org.patinanetwork.codebloom.common.lag.FakeLag;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -43,7 +42,6 @@ public ClubController(

@GetMapping("/{clubSlug}")
public ResponseEntity<ApiResponder<ClubDto>> getClubDataBySlug(@PathVariable final String clubSlug) {
FakeLag.sleep(650);

ClubDto club = clubService.getClubDtoBySlug(clubSlug);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.patinanetwork.codebloom.common.dto.autogen.UnsafeGenericFailureResponse;
import org.patinanetwork.codebloom.common.dto.leaderboard.LeaderboardDto;
import org.patinanetwork.codebloom.common.dto.user.UserWithScoreDto;
import org.patinanetwork.codebloom.common.lag.FakeLag;
import org.patinanetwork.codebloom.common.page.Indexed;
import org.patinanetwork.codebloom.common.page.Page;
import org.patinanetwork.codebloom.common.security.AuthenticationObject;
Expand Down Expand Up @@ -68,7 +67,6 @@ public LeaderboardController(
})
public ResponseEntity<ApiResponder<LeaderboardDto>> getLeaderboardMetadataByLeaderboardId(
final @PathVariable String leaderboardId, final HttpServletRequest request) {
FakeLag.sleep(650);

Optional<Leaderboard> leaderboardData = leaderboardManager.getLeaderboardMetadata(leaderboardId);

Expand Down Expand Up @@ -132,7 +130,6 @@ public ResponseEntity<ApiResponder<Page<Indexed<UserWithScoreDto>>>> getLeaderbo
@RequestParam(required = false, defaultValue = "false")
final boolean globalIndex,
final HttpServletRequest request) {
FakeLag.sleep(800);

final int parsedPageSize = Math.min(pageSize, MAX_LEADERBOARD_PAGE_SIZE);

Expand Down Expand Up @@ -173,7 +170,6 @@ public ResponseEntity<ApiResponder<Page<Indexed<UserWithScoreDto>>>> getLeaderbo
})
public ResponseEntity<ApiResponder<LeaderboardDto>> getCurrentLeaderboardMetadata(
final HttpServletRequest request) {
FakeLag.sleep(650);

var current = leaderboardRepository
.getRecentLeaderboardMetadata()
Expand Down Expand Up @@ -240,7 +236,6 @@ public ResponseEntity<ApiResponder<Page<Indexed<UserWithScoreDto>>>> getCurrentL
@Parameter(description = "Enable global leaderboard index")
@RequestParam(required = false, defaultValue = "false")
final boolean globalIndex) {
FakeLag.sleep(800);

final int parsedPageSize = Math.min(pageSize, MAX_LEADERBOARD_PAGE_SIZE);

Expand Down Expand Up @@ -284,7 +279,6 @@ public ResponseEntity<ApiResponder<Page<Indexed<UserWithScoreDto>>>> getCurrentL
})
public ResponseEntity<ApiResponder<UserWithScoreDto>> getUserCurrentLeaderboardFull(
final HttpServletRequest request, @PathVariable final String userId) {
FakeLag.sleep(650);

Optional<Leaderboard> leaderboardData = leaderboardRepository.getRecentLeaderboardMetadata();

Expand Down Expand Up @@ -345,7 +339,6 @@ public ResponseEntity<ApiResponder<Indexed<UserWithScoreDto>>> getUserCurrentLea
final boolean columbia,
@Parameter(description = "Filter for BMCC users") @RequestParam(required = false, defaultValue = "false")
final boolean bmcc) {
FakeLag.sleep(650);

String userId = authenticationObject.getUser().getId();

Expand Down Expand Up @@ -411,7 +404,6 @@ public ResponseEntity<ApiResponder<Page<LeaderboardDto>>> getAllLeaderboardMetad
@Parameter(description = "Page size (maximum of " + MAX_LEADERBOARD_PAGE_SIZE)
@RequestParam(required = false, defaultValue = "" + MAX_LEADERBOARD_PAGE_SIZE)
final int pageSize) {
FakeLag.sleep(650);

final int parsedPageSize = Math.min(pageSize, MAX_LEADERBOARD_PAGE_SIZE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.patinanetwork.codebloom.common.dto.autogen.UnsafeRateLimitResponse;
import org.patinanetwork.codebloom.common.dto.potd.PotdDto;
import org.patinanetwork.codebloom.common.dto.question.QuestionWithUserDto;
import org.patinanetwork.codebloom.common.lag.FakeLag;
import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeSubmission;
import org.patinanetwork.codebloom.common.leetcode.models.UserProfile;
import org.patinanetwork.codebloom.common.leetcode.throttled.ThrottledLeetcodeClient;
Expand Down Expand Up @@ -108,7 +107,6 @@ public SubmissionController(
@GetMapping("/key")
public ResponseEntity<ApiResponder<String>> getVerificationKey(
@Protected final AuthenticationObject authenticationObject) {
FakeLag.sleep(350);

User user = authenticationObject.getUser();

Expand Down Expand Up @@ -144,7 +142,6 @@ public ResponseEntity<ApiResponder<String>> getVerificationKey(
public ResponseEntity<ApiResponder<Empty>> setLeetcodeUsername(
@Protected final AuthenticationObject authenticationObject,
@Valid @RequestBody final LeetcodeUsernameObject leetcodeUsernameObject) {
FakeLag.sleep(350);

User user = authenticationObject.getUser();

Expand Down Expand Up @@ -256,7 +253,6 @@ public ResponseEntity<ApiResponder<ArrayList<AcceptedSubmission>>> checkLatestSu
@GetMapping("/potd")
public ResponseEntity<ApiResponder<PotdDto>> getCurrentPotd(
@Protected final AuthenticationObject authenticationObject) {
FakeLag.sleep(750);

User user = authenticationObject.getUser();

Expand Down Expand Up @@ -296,8 +292,6 @@ public ResponseEntity<ApiResponder<PotdDto>> getCurrentPotd(
})
@GetMapping("/potd/embed")
public ResponseEntity<ApiResponder<PotdDto>> getCurrentPotdEmbed() {
FakeLag.sleep(750);

POTD potd = potdRepository
.getCurrentPOTD()
.filter(p -> isSameDay(p.getCreatedAt()))
Expand Down Expand Up @@ -329,7 +323,6 @@ public ResponseEntity<ApiResponder<PotdDto>> getCurrentPotdEmbed() {
@GetMapping("/submission/{submissionId}")
public ResponseEntity<ApiResponder<QuestionWithUserDto>> getSubmissionBySubmissionId(
final HttpServletRequest request, @PathVariable final String submissionId) {
FakeLag.sleep(750);

var question = questionRepository.getQuestionWithUserById(submissionId);

Expand Down
Loading
Loading