Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export default class GameService extends Service {
method: 'PATCH',
path: '/:id'
})
@Validate({
body: {
name: {
validation: async (val: unknown) => [
{
check: typeof val === 'string' ? val.trim().length > 0 : true,
error: 'Name must be a non-empty string'
}
]
}
}
})
@HasPermission(GamePolicy, 'patch')
async patch(req: Request<{
name?: string
Expand Down
17 changes: 17 additions & 0 deletions tests/services/game/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,21 @@ describe('Game service - patch', () => {
expect((await em.refreshOrFail(game)).purgeLivePlayersRetention).toBe(60)
}
})

it('should not update game names if an empty string is sent', async () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({ type: UserType.ADMIN }, organisation)

const res = await request(app)
.patch(`/games/${game.id}`)
.send({ name: '' })
.auth(token, { type: 'bearer' })
.expect(400)

expect(res.body).toStrictEqual({
errors: {
name: ['Name must be a non-empty string']
}
})
})
})