From 28e54d502f0a24b4ff6c24202ff6d6f074d30299 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Tue, 24 Feb 2026 22:34:19 -0500 Subject: [PATCH] Export shuffle from state and add getAllCards to cards module --- src/cards.js | 4 ++++ src/cards.test.js | 17 ++++++++++++++++- src/state.js | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cards.js b/src/cards.js index a7c5500..c32caa0 100644 --- a/src/cards.js +++ b/src/cards.js @@ -17,3 +17,7 @@ export function getStarterDeck(character) { } return []; } + +export function getAllCards() { + return Object.values(cardDb); +} diff --git a/src/cards.test.js b/src/cards.test.js index b845db5..ed2ce76 100644 --- a/src/cards.test.js +++ b/src/cards.test.js @@ -1,5 +1,5 @@ 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 () => { await initCards(); @@ -26,3 +26,18 @@ describe("cards", () => { 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(); + } + }); +}); diff --git a/src/state.js b/src/state.js index cac35f3..c2019b1 100644 --- a/src/state.js +++ b/src/state.js @@ -192,7 +192,7 @@ export function endTurn(state, playerIndex) { }; } -function shuffle(arr) { +export function shuffle(arr) { const a = [...arr]; for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1));