Skip to content

Commit

Permalink
addPeriod, reducers etc to test demo game
Browse files Browse the repository at this point in the history
  • Loading branch information
jajakob committed Jun 13, 2024
1 parent f2f1d92 commit 3ce6e22
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
60 changes: 51 additions & 9 deletions apps/demo-game/__tests__/gameMachine.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { GameService, UserRole } from '@gbl-uzh/platform'
import { GameService, Reducers, UserRole } from '@gbl-uzh/platform'
import { PrismaClient } from '@prisma/client'
import { PeriodFacts, PeriodFactsSchema } from '../src/graphql/types'
import * as reds from '../src/reducers'

// TODO(Jakob):
// - Check where we get the facts from to addPeriod
// - flag for clearing the prisma db and do from scratch -> only over cli?

// - Why do we always provide all reducers for every function in GameServie?

// - Add state machine in the platform code and add it here
// - Use the functions in util and GameService and alter them iteratively
// in order to use the state machine -> also check how to use the actor

describe('Testing Demo Game', () => {
const nameGame = 'TestDemoGame'
Expand All @@ -10,6 +22,28 @@ describe('Testing Demo Game', () => {
const userSub = '716f7632-ed33-4701-a281-0f27bd4f6e82'
const roleAssigner = (ix: number): UserRole => UserRole.PLAYER
const prisma = new PrismaClient()
const reducers: Reducers<PrismaClient> = {
Actions: {
apply: reds.Actions.apply,
ActionTypes: reds.Actions.ActionTypes,
},
Period: {
apply: reds.Period.apply,
ActionTypes: reds.Period.ActionTypes,
},
PeriodResult: {
apply: reds.PeriodResult.apply,
ActionTypes: reds.PeriodResult.ActionTypes,
},
Segment: {
apply: reds.Segment.apply,
ActionTypes: reds.Segment.ActionTypes,
},
SegmentResult: {
apply: reds.SegmentResult.apply,
ActionTypes: reds.SegmentResult.ActionTypes,
},
}

let ctx: GameService.Context = {
prisma: prisma,
Expand Down Expand Up @@ -58,14 +92,6 @@ describe('Testing Demo Game', () => {
})
}

// TODO(Jakob):
// - flag for clearing the prisma db and do from scratch
// - what is the return of GameService.createGame and what is it used for?

// - Add state machine in the platform code and add it here
// - Use the functions in util and GameService and alter them iteratively
// in order to use the state machine -> also check how to use the actor

it('creates a new Game', async () => {
if (createNewGame) {
game = await GameService.createGame(
Expand All @@ -77,6 +103,22 @@ describe('Testing Demo Game', () => {
} else {
game = await findGame(gameId)
}

let facts = {
rollsPerSegment: 1,
scenario: {
bankReturn: 1,
seed: 1,
trendStocks: 1,
trendBonds: 1,
gapStocks: 1,
gapBonds: 1,
},
}
GameService.addGamePeriod<PeriodFacts>({ gameId, facts }, ctx, {
schema: PeriodFactsSchema,
reducers,
})
})
})

Expand Down
1 change: 1 addition & 0 deletions apps/demo-game/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@tsconfig/recommended": "1.0.2",
"@types/jest": "^29.5.4",
"@types/node": "^18.11.9",
"@types/ramda": "^0.28.25",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.0",
"autoprefixer": "10.4.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface Reducer<
ActionTypes: Record<string, string>
}

interface Reducers<PrismaType> {
export interface Reducers<PrismaType> {
Actions: Reducer<any, any, any, any, any, any, PrismaType>
Period: Reducer<any, any, any, any, any, any, PrismaType>
PeriodResult: Reducer<any, any, any, any, any, any, PrismaType>
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ce6e22

Please sign in to comment.