Skip to content

Commit

Permalink
Merge pull request #11 from homanp/feat/update-return-object
Browse files Browse the repository at this point in the history
Feat/update return object
  • Loading branch information
homanp authored Nov 18, 2024
2 parents 487d770 + 33683e7 commit f8cb4ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
52 changes: 26 additions & 26 deletions src/__tests__/OpenHandHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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)
});
});
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f8cb4ec

Please sign in to comment.