Export shuffle from state and add getAllCards to cards module
This commit is contained in:
parent
970796f85a
commit
28e54d502f
3 changed files with 21 additions and 2 deletions
|
|
@ -17,3 +17,7 @@ export function getStarterDeck(character) {
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAllCards() {
|
||||||
|
return Object.values(cardDb);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue