Export shuffle from state and add getAllCards to cards module

This commit is contained in:
Jared Miller 2026-02-24 22:34:19 -05:00
parent 970796f85a
commit 28e54d502f
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
3 changed files with 21 additions and 2 deletions

View file

@ -17,3 +17,7 @@ export function getStarterDeck(character) {
} }
return []; return [];
} }
export function getAllCards() {
return Object.values(cardDb);
}

View file

@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from "bun:test"; import { beforeAll, describe, expect, test } from "bun:test";
import { getCard, getStarterDeck, initCards } from "./cards.js"; import { getAllCards, getCard, getStarterDeck, initCards } from "./cards.js";
beforeAll(async () => { beforeAll(async () => {
await initCards(); await initCards();
@ -26,3 +26,18 @@ describe("cards", () => {
expect(deck.filter((id) => id === "bash")).toHaveLength(1); expect(deck.filter((id) => id === "bash")).toHaveLength(1);
}); });
}); });
describe("getAllCards", () => {
test("returns array with more than 100 cards", () => {
const cards = getAllCards();
expect(cards.length).toBeGreaterThan(100);
});
test("each card has id and name properties", () => {
const cards = getAllCards();
for (const card of cards) {
expect(card.id).toBeDefined();
expect(card.name).toBeDefined();
}
});
});

View file

@ -192,7 +192,7 @@ export function endTurn(state, playerIndex) {
}; };
} }
function shuffle(arr) { export function shuffle(arr) {
const a = [...arr]; const a = [...arr];
for (let i = a.length - 1; i > 0; i--) { for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); const j = Math.floor(Math.random() * (i + 1));