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
4 changes: 4 additions & 0 deletions apps/web/lib/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ describe("env numeric configuration", () => {
it("loads valid positive integer limits and USD prices", async () => {
vi.stubEnv("MAX_IMAGE_UPLOAD_MB", "24");
vi.stubEnv("MAX_VIDEO_DURATION_SECONDS", "45");
vi.stubEnv("PRIZE_MIN_SCORED", "5");
vi.stubEnv("PRICE_API_ACCESS_USD", "1.50");

const env = await loadEnv();

expect(env.maxImageUploadMb).toBe(24);
expect(env.maxVideoDurationSeconds).toBe(45);
expect(env.prizeMinScored).toBe(5);
expect(env.priceApiAccessUsd).toBe(1.5);
});

it("falls back for malformed or non-positive limits", async () => {
vi.stubEnv("MAX_IMAGE_UPLOAD_MB", "10abc");
vi.stubEnv("MAX_VIDEO_UPLOAD_MB", "0");
vi.stubEnv("RSS_CACHE_SECONDS", "1.5");
vi.stubEnv("PRIZE_MIN_SCORED", "3abc");

const env = await loadEnv();

expect(env.maxImageUploadMb).toBe(12);
expect(env.maxVideoUploadMb).toBe(75);
expect(env.rssCacheSeconds).toBe(300);
expect(env.prizeMinScored).toBe(3);
});

it("falls back for invalid checkout prices", async () => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const env = {
maxVideoDurationSeconds: int(process.env.MAX_VIDEO_DURATION_SECONDS, 30),

rssCacheSeconds: int(process.env.RSS_CACHE_SECONDS, 300),
prizeMinScored: int(process.env.PRIZE_MIN_SCORED, 3),
voteSalt: process.env.VOTE_SALT || "dev-vote-salt",
submissionSalt: process.env.SUBMISSION_SALT || "dev-submission-salt",
rateLimitSalt: process.env.RATE_LIMIT_SALT || "dev-rate-limit-salt",
Expand Down
3 changes: 1 addition & 2 deletions apps/web/lib/prizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const BASE_REWARDS: Array<{ kind: string; label: string }> = [
{ kind: "crawlproof_25", label: "25% off CrawlProof.com fill-ups" },
];

const PRIZE_MIN_SCORED = Number(process.env.PRIZE_MIN_SCORED || 3);
const CLAIM_WINDOW_DAYS = 7;

export type PrizeRow = {
Expand Down Expand Up @@ -64,7 +63,7 @@ async function winnersForPeriod(startISO: string, endISO: string, limit: number)
HAVING scored >= ?
ORDER BY correct DESC, (CAST(correct AS REAL) / scored) DESC, scored DESC, last DESC
LIMIT ?`,
args: [startISO, endISO, PRIZE_MIN_SCORED, limit],
args: [startISO, endISO, env.prizeMinScored, limit],
});
return res.rows.map((r) => ({ userId: r.user_id as string, correct: Number(r.correct), scored: Number(r.scored) }));
}
Expand Down
Loading