diff --git a/src/services/game.service.ts b/src/services/game.service.ts index f50ff60b..c5f12ea7 100644 --- a/src/services/game.service.ts +++ b/src/services/game.service.ts @@ -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 diff --git a/tests/services/game/patch.test.ts b/tests/services/game/patch.test.ts index 09d31c24..351207a8 100644 --- a/tests/services/game/patch.test.ts +++ b/tests/services/game/patch.test.ts @@ -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'] + } + }) + }) })