Skip to content

Commit

Permalink
dont include players in groups if their leaderboard entry is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Dec 16, 2024
1 parent 9df60db commit 200e461
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/entities/player-group-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default class PlayerGroupRule {
leaderboard: {
internalName: this.getNamespacedValue('leaderboardEntryScore')
},
hidden: false,
[this.getCastedKey('score')]: fieldQuery
})
}
Expand Down
30 changes: 30 additions & 0 deletions tests/entities/player-group-rule/equals-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,34 @@ describe('EQUALS rule', () => {

expect(res.body.count).toEqual(1)
})

it('should not add a player to a group if their leaderboard entry is hidden', async () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).one()
const player2 = await new PlayerFactory([game]).one()

const leaderboard = await new LeaderboardFactory([game]).one()
const leaderboardEntry = await new LeaderboardEntryFactory(leaderboard, [player1]).state(() => ({ score: 60, hidden: true })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2, leaderboardEntry])

const rules: Partial<PlayerGroupRule>[] = [
{
name: PlayerGroupRuleName.EQUALS,
field: `leaderboardEntryScore.${leaderboard.internalName}`,
operands: ['60'],
negate: false,
castType: PlayerGroupRuleCastType.DOUBLE
}
]

const res = await request(global.app)
.get(`/games/${game.id}/player-groups/preview-count`)
.query({ ruleMode: '$and', rules: encodeURI(JSON.stringify(rules)) })
.auth(token, { type: 'bearer' })
.expect(200)

expect(res.body.count).toEqual(0)
})
})

0 comments on commit 200e461

Please sign in to comment.