the-game-domain
Version:
Complete domain layer for 'The Game' card game with rich business entities, automatic persistence, action tracking, and advanced game mechanics. Features Game, Player, Card, Deck, Pile entities with repository pattern, turn management, victory/defeat dete
54 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Card_1 = require("./Card");
describe('Card', () => {
describe('Constructor and Properties', () => {
it('should create a valid card', () => {
const card = new Card_1.Card(5);
expect(card.value).toBe(5);
});
it('should reject invalid card values', () => {
expect(() => new Card_1.Card(0)).toThrow('Card value must be between 1 and 100');
expect(() => new Card_1.Card(101)).toThrow('Card value must be between 1 and 100');
});
it('should reject non-integer values', () => {
expect(() => new Card_1.Card(5.5)).toThrow('Card value must be an integer');
});
it('should handle optional id', () => {
const card = new Card_1.Card(5, 'card-123');
expect(card.id).toBe('card-123');
});
});
describe('Equals', () => {
it('should compare cards correctly', () => {
const card1 = new Card_1.Card(5);
const card2 = new Card_1.Card(5);
const card3 = new Card_1.Card(10);
expect(card1.equals(card2)).toBe(true);
expect(card1.equals(card3)).toBe(false);
});
});
describe('ToString', () => {
it('should return correct string representation', () => {
const card = new Card_1.Card(42);
expect(card.toString()).toBe('Card(42)');
});
});
describe('JSON Serialization', () => {
it('should serialize and deserialize correctly', () => {
const card = new Card_1.Card(42);
const json = card.toJSON();
const reconstructed = Card_1.Card.fromJSON(json);
expect(reconstructed.value).toBe(42);
expect(card.equals(reconstructed)).toBe(true);
});
it('should handle optional id in serialization', () => {
const card = new Card_1.Card(5, 'card-123');
const json = card.toJSON();
expect(json.id).toBe('card-123');
const reconstructed = Card_1.Card.fromJSON(json);
expect(reconstructed.id).toBe('card-123');
});
});
});
//# sourceMappingURL=Card.test.js.map