generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: 賴鴻德 <[email protected]>
Co-authored-by: Pikacnu <[email protected]> Co-authored-by: Tuhacrt <[email protected]>
- Loading branch information
1 parent
433451f
commit f21033b
Showing
3 changed files
with
200 additions
and
27 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/domain_layer/src/player/checkPlayerHasUnrevealedCardOfHands.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Creature, Status } from 'card'; | ||
import { createIdToPlayer, createPlayer } from 'player'; | ||
import { pipe } from 'fp-ts/function'; | ||
import O from 'fp-ts/Option'; | ||
|
||
import { checkPlayerHasUnrevealedCardOfHands } from './checkPlayerHasUnrevealedCardOfHands'; | ||
|
||
describe('checkPlayerHasUnrevealedCardOfHands', () => { | ||
it(` | ||
given a player | ||
hands [ | ||
{ id: 1, status: 'UNREVEALED', creature: 'BAT' } | ||
] | ||
when check player has unrevealed card | ||
then | ||
player has unrevealedCard | ||
`, () => { | ||
const hasUnrevealedCard = pipe( | ||
{ uid: '1', name: 'player1' }, | ||
createPlayer, | ||
createIdToPlayer, | ||
O.map((player) => { | ||
player.hands = [ | ||
{ id: 1, status: Status.Unrevealed, creature: Creature.Bat }, | ||
]; | ||
return player; | ||
}), | ||
O.map(checkPlayerHasUnrevealedCardOfHands), | ||
); | ||
|
||
expect(hasUnrevealedCard).toStrictEqual(O.some(true)); | ||
}); | ||
|
||
it(` | ||
given a player | ||
hands [ | ||
] | ||
when check player has unrevealed card | ||
then | ||
player not has unrevealedCard | ||
`, () => { | ||
const hasUnrevealedCard = pipe( | ||
{ uid: '1', name: 'player1' }, | ||
createPlayer, | ||
createIdToPlayer, | ||
O.map(checkPlayerHasUnrevealedCardOfHands), | ||
); | ||
|
||
expect(hasUnrevealedCard).toStrictEqual(O.some(false)); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/domain_layer/src/player/checkPlayerHasUnrevealedCardOfHands.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Player } from 'player'; | ||
import { pipe } from 'fp-ts/function'; | ||
import { prop } from 'remeda'; | ||
|
||
export interface CheckPlayerHasUnrevealedCardOfHands { | ||
(player: Player): boolean; | ||
} | ||
|
||
export const checkPlayerHasUnrevealedCardOfHands: CheckPlayerHasUnrevealedCardOfHands = | ||
(player: Player) => | ||
pipe( | ||
// | ||
player, | ||
prop('hands'), | ||
prop('length'), | ||
(length) => length > 0, | ||
); |
Oops, something went wrong.