From c205102e6c96d79430c8049df163935290eb0090 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Mon, 18 Nov 2024 09:46:58 +0100 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20return=20ohh=20format=20in=20=C2=A0?= =?UTF-8?q?method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/OpenHandHistory.test.ts | 52 +++++++++++++-------------- src/index.ts | 4 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/__tests__/OpenHandHistory.test.ts b/src/__tests__/OpenHandHistory.test.ts index a7675df..0e63b3d 100644 --- a/src/__tests__/OpenHandHistory.test.ts +++ b/src/__tests__/OpenHandHistory.test.ts @@ -10,13 +10,13 @@ describe("OpenHandHistory", () => { test("creates instance with default values", () => { const json = ohh.toJSON(); - expect(json.spec_version).toBe("1.4.6"); - expect(json.game_type).toBe("Holdem"); - expect(json.table_size).toBe(3); - expect(json.currency).toBe("Chips"); - expect(json.players).toEqual([]); - expect(json.rounds).toEqual([]); - expect(json.pots).toEqual([]); + expect(json.ohh.spec_version).toBe("1.4.6"); + expect(json.ohh.game_type).toBe("Holdem"); + expect(json.ohh.table_size).toBe(3); + expect(json.ohh.currency).toBe("Chips"); + expect(json.ohh.players).toEqual([]); + expect(json.ohh.rounds).toEqual([]); + expect(json.ohh.pots).toEqual([]); }); test("creates instance with custom values", () => { @@ -28,10 +28,10 @@ describe("OpenHandHistory", () => { }); const json = customOHH.toJSON(); - expect(json.spec_version).toBe("2.0.0"); - expect(json.game_type).toBe("PLO"); - expect(json.table_size).toBe(6); - expect(json.currency).toBe("USD"); + expect(json.ohh.spec_version).toBe("2.0.0"); + expect(json.ohh.game_type).toBe("PLO"); + expect(json.ohh.table_size).toBe(6); + expect(json.ohh.currency).toBe("USD"); }); test("adds player correctly", () => { @@ -43,8 +43,8 @@ describe("OpenHandHistory", () => { }; ohh.addPlayer(player); const json = ohh.toJSON(); - expect(json.players).toHaveLength(1); - expect(json.players[0]).toEqual(player); + expect(json.ohh.players).toHaveLength(1); + expect(json.ohh.players[0]).toEqual(player); }); test("adds multiple players correctly", () => { @@ -55,8 +55,8 @@ describe("OpenHandHistory", () => { players.forEach((player) => ohh.addPlayer(player)); const json = ohh.toJSON(); - expect(json.players).toHaveLength(2); - expect(json.players).toEqual(players); + expect(json.ohh.players).toHaveLength(2); + expect(json.ohh.players).toEqual(players); }); test("adds round correctly", () => { @@ -69,8 +69,8 @@ describe("OpenHandHistory", () => { ohh.addRound(round); const json = ohh.toJSON(); - expect(json.rounds).toHaveLength(1); - expect(json.rounds[0]).toEqual(round); + expect(json.ohh.rounds).toHaveLength(1); + expect(json.ohh.rounds[0]).toEqual(round); }); test("adds action to round correctly", () => { @@ -91,8 +91,8 @@ describe("OpenHandHistory", () => { ohh.addActionToRound(1, action); const json = ohh.toJSON(); - expect(json.rounds[0].actions).toHaveLength(1); - expect(json.rounds[0].actions[0]).toEqual(action); + expect(json.ohh.rounds[0].actions).toHaveLength(1); + expect(json.ohh.rounds[0].actions[0]).toEqual(action); }); test("adds pot correctly", () => { @@ -104,8 +104,8 @@ describe("OpenHandHistory", () => { ohh.addPot(pot); const json = ohh.toJSON(); - expect(json.pots).toHaveLength(1); - expect(json.pots[0]).toEqual(pot); + expect(json.ohh.pots).toHaveLength(1); + expect(json.ohh.pots[0]).toEqual(pot); }); test("handles complex hand history correctly", () => { @@ -140,10 +140,10 @@ describe("OpenHandHistory", () => { }); const json = ohh.toJSON(); - expect(json.players).toHaveLength(2); - expect(json.rounds).toHaveLength(1); - expect(json.rounds[0].actions).toHaveLength(2); - expect(json.pots).toHaveLength(1); + expect(json.ohh.players).toHaveLength(2); + expect(json.ohh.rounds).toHaveLength(1); + expect(json.ohh.rounds[0].actions).toHaveLength(2); + expect(json.ohh.pots).toHaveLength(1); }); describe("winning calculations", () => { @@ -198,7 +198,7 @@ describe("OpenHandHistory", () => { }); const json = ohh.toJSON(); - expect(json.pots[0].player_wins[0].win_amount).toBe(30); // 50 (pot) - 20 (raise) + expect(json.ohh.pots[0].player_wins[0].win_amount).toBe(30); // 50 (pot) - 20 (raise) }); }); }); diff --git a/src/index.ts b/src/index.ts index 82626fe..19c5fce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -68,8 +68,8 @@ export class OpenHandHistory { this.ohh.pots.push(pot); } - toJSON(): OHHData { - return this.ohh; + toJSON(): { ohh: OHHData } { + return { ohh: this.ohh }; } saveToFile(filename: string): void { From 33683e76beb9e52967ee93afaf36a401d201d8bc Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Mon, 18 Nov 2024 09:47:34 +0100 Subject: [PATCH 2/2] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f22d846..49f7b69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-hand-tracker", - "version": "1.0.5", + "version": "1.0.6", "description": "A package for creating and managing poker hand histories", "main": "dist/index.js", "types": "dist/index.d.ts",