generated from nhcarrigan/template
feat: initial prototype — core game systems (#30)
## Summary This PR represents the full v1 prototype, implementing the core game systems for Elysium. - Full idle/clicker RPG loop: resource collection, crafting, boss fights, exploration, and quests - Adventurer hiring with batch size selector and progressive tier cost scaling - Prestige, transcendence, and apotheosis systems with auto-prestige support - Character sheet, titles, leaderboards, companion system, and daily login bonuses - Auto-quest and auto-boss toggles - Discord webhook notifications on prestige/transcendence/apotheosis - Discord role awarded on apotheosis - Responsive design and overarching story/lore system - In-game sound effects and browser notifications for key events - Support link button in the resource bar - Full test coverage (100% on `apps/api` and `packages/types`) - CI pipeline: lint → build → test ## Closes Closes #1 Closes #2 Closes #3 Closes #4 Closes #5 Closes #6 Closes #7 Closes #8 Closes #9 Closes #10 Closes #11 Closes #12 Closes #13 Closes #14 Closes #16 Closes #19 Closes #20 Closes #21 Closes #22 Closes #23 Closes #24 Closes #25 Closes #26 Closes #27 Closes #29 ✨ This issue was created with help from Hikari~ 🌸 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Reviewed-on: #30 Co-authored-by: Hikari <hikari@nhcarrigan.com> Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #30.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
|
||||
/* eslint-disable max-nested-callbacks -- Vitest structure requires nesting */
|
||||
/**
|
||||
* @file Tests for daily challenge progress utilities.
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { updateChallengeProgress } from "../src/utils/dailyChallenges.js";
|
||||
import type { DailyChallengeState } from "@elysium/types";
|
||||
|
||||
const makeState = (overrides: Partial<DailyChallengeState> = {}): DailyChallengeState => ({
|
||||
challenges: [],
|
||||
lastResetDay: "2024-01-01",
|
||||
...overrides,
|
||||
});
|
||||
|
||||
describe("updateChallengeProgress", () => {
|
||||
it("should return unchanged state when there are no challenges", () => {
|
||||
const state = makeState();
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 10);
|
||||
expect(crystalsAwarded).toBe(0);
|
||||
expect(updatedChallenges.challenges).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should skip challenges of a different type", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: false, progress: 0, rewardCrystals: 5, target: 10, type: "gold_earned" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 5);
|
||||
expect(crystalsAwarded).toBe(0);
|
||||
expect(updatedChallenges.challenges[0].progress).toBe(0);
|
||||
});
|
||||
|
||||
it("should skip already-completed challenges", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: true, progress: 10, rewardCrystals: 5, target: 10, type: "clicks" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 5);
|
||||
expect(crystalsAwarded).toBe(0);
|
||||
expect(updatedChallenges.challenges[0].progress).toBe(10);
|
||||
});
|
||||
|
||||
it("should increment progress without completing the challenge", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: false, progress: 0, rewardCrystals: 5, target: 10, type: "clicks" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 4);
|
||||
expect(crystalsAwarded).toBe(0);
|
||||
expect(updatedChallenges.challenges[0].progress).toBe(4);
|
||||
expect(updatedChallenges.challenges[0].completed).toBe(false);
|
||||
});
|
||||
|
||||
it("should complete the challenge and award crystals when progress meets target", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: false, progress: 8, rewardCrystals: 5, target: 10, type: "clicks" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 2);
|
||||
expect(crystalsAwarded).toBe(5);
|
||||
expect(updatedChallenges.challenges[0].completed).toBe(true);
|
||||
expect(updatedChallenges.challenges[0].progress).toBe(10);
|
||||
});
|
||||
|
||||
it("should cap progress at the target when amount overshoots", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: false, progress: 0, rewardCrystals: 3, target: 10, type: "clicks" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 100);
|
||||
expect(crystalsAwarded).toBe(3);
|
||||
expect(updatedChallenges.challenges[0].progress).toBe(10);
|
||||
expect(updatedChallenges.challenges[0].completed).toBe(true);
|
||||
});
|
||||
|
||||
it("should accumulate crystals from multiple completed challenges", () => {
|
||||
const state = makeState({
|
||||
challenges: [
|
||||
{ completed: false, progress: 0, rewardCrystals: 5, target: 10, type: "clicks" },
|
||||
{ completed: false, progress: 0, rewardCrystals: 10, target: 10, type: "clicks" },
|
||||
],
|
||||
});
|
||||
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(state, "clicks", 10);
|
||||
expect(crystalsAwarded).toBe(15);
|
||||
expect(updatedChallenges.challenges[0].completed).toBe(true);
|
||||
expect(updatedChallenges.challenges[1].completed).toBe(true);
|
||||
});
|
||||
|
||||
it("should preserve the lastResetDay from the original state", () => {
|
||||
const state = makeState({ lastResetDay: "2024-06-15" });
|
||||
const { updatedChallenges } = updateChallengeProgress(state, "clicks", 1);
|
||||
expect(updatedChallenges.lastResetDay).toBe("2024-06-15");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user