diff --git a/core/api/reroll.test.ts b/core/api/reroll.test.ts index 2bc9abe..cf42466 100644 --- a/core/api/reroll.test.ts +++ b/core/api/reroll.test.ts @@ -1,20 +1,24 @@ import { test, expect } from "vitest"; import { withTwoPlayerGameStarted } from "../fixtures/with-two-player-game-started"; import { asPlayerReroll } from "../automations/as-player-reroll"; -import { getDisplay } from "../utils/get-display"; +import { getGame } from "../utils/get-game"; +import { getGameShop } from "../utils/get-game-shop"; test("Reroll should swap the shop items with random hero from pool", async () => { const testContext = await withTwoPlayerGameStarted(); - const display = await getDisplay(testContext); + const game = await getGame(testContext); + const publicKey = testContext.frontContexts[0].publicKey || "Error"; + const shop = getGameShop(game, publicKey); const playsig = testContext.frontContexts[0].playsig || "Error"; const pool = await testContext.backContext.dataMapper.readPool(playsig); await asPlayerReroll(testContext); - const displayAfter = await getDisplay(testContext); + const gameAfter = await getGame(testContext); + const shopAfter = getGameShop(gameAfter, publicKey); const poolAfter = await testContext.backContext.dataMapper.readPool(playsig); - expect(displayAfter.shop).not.toEqual(display.shop); + expect(shopAfter).not.toEqual(shop); expect(poolAfter?.heroes).not.toEqual(pool?.heroes); expect(pool?.heroes).toBeTruthy(); - const merged = [...displayAfter.shop, ...(poolAfter?.heroes || [])].sort(); - const mergedAfter = [...display.shop, ...(pool?.heroes || [])].sort(); + const merged = [...shopAfter, ...(poolAfter?.heroes || [])].sort(); + const mergedAfter = [...shop, ...(pool?.heroes || [])].sort(); expect(merged).toEqual(mergedAfter); }); diff --git a/core/utils/get-display.ts b/core/utils/get-display.ts deleted file mode 100644 index d528eed..0000000 --- a/core/utils/get-display.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { TestContext } from "../types/test-context"; -import { firstValueFrom, map } from "rxjs"; -import { portray } from "./portray"; -import { observeGame } from "../api/observe-game"; -import type { Display } from "../types/display"; - -export async function getDisplay( - testContext: TestContext, - playerNumber = 0, -): Promise { - const frontContext = testContext.frontContexts[playerNumber]; - - if (!frontContext) { - throw new Error(`Player ${playerNumber} not found !`); - } - - const display = await firstValueFrom( - observeGame(frontContext).pipe( - map(({ game }) => game), - portray(frontContext.publicKey), - ), - ); - - return display; -} diff --git a/core/utils/get-game-shop.ts b/core/utils/get-game-shop.ts new file mode 100644 index 0000000..b9f6bd2 --- /dev/null +++ b/core/utils/get-game-shop.ts @@ -0,0 +1,13 @@ +import type { Game } from "../types/game"; +import type { Appellation } from "../types/appellation"; +import type { PublicKey } from "../types/public-key"; + +export function getGameShop(game: Game, publicKey: PublicKey): Appellation[] { + const shop = game.playerShops[publicKey]; + + if (!shop) { + throw new Error("Shop not found !"); + } + + return shop; +} diff --git a/core/utils/portray.ts b/interface/utils/portray.ts similarity index 74% rename from core/utils/portray.ts rename to interface/utils/portray.ts index 868c597..d2fc0ea 100644 --- a/core/utils/portray.ts +++ b/interface/utils/portray.ts @@ -1,14 +1,14 @@ -import type { Display } from "../types/display"; -import type { Game } from "../types/game"; +import type { Display } from "core/types/display"; +import type { Game } from "core/types/game"; import type { Observable, OperatorFunction } from "rxjs"; import { map, combineLatestWith, startWith } from "rxjs/operators"; -import { Animation } from "../types/animation"; +import { Animation } from "core/types/animation"; import { interval } from "rxjs"; -import { getLevelUpCost } from "./get-level-up-cost"; -import { observePortrayedConfrontation } from "./observe-portrayed-confrontation"; -import type { PublicKey } from "../types/public-key"; -import type { Piece } from "../types/piece"; -import { portrayBench } from "./portray-bench"; +import { getLevelUpCost } from "core/utils/get-level-up-cost"; +import { observePortrayedConfrontation } from "core/utils/observe-portrayed-confrontation"; +import type { PublicKey } from "core/types/public-key"; +import type { Piece } from "core/types/piece"; +import { portrayBench } from "core/utils/portray-bench"; export function portray(publicKey: PublicKey): OperatorFunction { return (source: Observable) => diff --git a/offline/main.ts b/offline/main.ts index b999168..3cbeb4b 100644 --- a/offline/main.ts +++ b/offline/main.ts @@ -12,7 +12,7 @@ import { startServer } from "core/utils/start-server"; import type { FrontContext } from "core/types/front-context"; import { initiateGame } from "core/api/initiate-game"; import { observeGame } from "core/api/observe-game"; -import { portray } from "core/utils/portray"; +import { portray } from "interface/utils/portray"; import { cast } from "core/utils/cast"; import { observeInteractions } from "interface/utils/observe-interactions"; import { firstValueFrom, of, map } from "rxjs";