64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import 'reflect-metadata';
|
|
import { BadRequestException, ValidationPipe } from '@nestjs/common';
|
|
import { plainToInstance } from 'class-transformer';
|
|
import { validateSync } from 'class-validator';
|
|
import mongoose from 'mongoose';
|
|
import { CreateMatchDto, JoinMatchDto } from './create-match.dto';
|
|
|
|
describe('CreateMatchDto game mode cutover', () => {
|
|
it('rejects the removed live bracket mode', () => {
|
|
const dto = plainToInstance(CreateMatchDto, {
|
|
title: 'legacy bracket',
|
|
scheduledAt: '2026-07-13T10:00:00.000Z',
|
|
gameMode: 'bracket',
|
|
});
|
|
|
|
expect(validateSync(dto)).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ property: 'gameMode' }),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it.each(['pair', 'round-robin', 'double-elimination'] as const)(
|
|
'accepts the live %s mode',
|
|
(gameMode) => {
|
|
const dto = plainToInstance(CreateMatchDto, {
|
|
title: 'Competition',
|
|
scheduledAt: '2026-07-13T10:00:00.000Z',
|
|
gameMode,
|
|
});
|
|
|
|
expect(validateSync(dto)).toEqual([]);
|
|
},
|
|
);
|
|
});
|
|
|
|
describe('JoinMatchDto self-join boundary', () => {
|
|
it('rejects a caller-supplied userId', async () => {
|
|
const pipe = new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
});
|
|
|
|
try {
|
|
await pipe.transform(
|
|
{
|
|
preferredPositions: [{ position: 'MID', priority: 1 }],
|
|
userId: new mongoose.Types.ObjectId().toString(),
|
|
},
|
|
{ type: 'body', metatype: JoinMatchDto },
|
|
);
|
|
throw new Error('Expected validation to reject userId.');
|
|
} catch (error) {
|
|
expect(error).toBeInstanceOf(BadRequestException);
|
|
expect((error as BadRequestException).getResponse()).toEqual({
|
|
error: 'Bad Request',
|
|
message: ['property userId should not exist'],
|
|
statusCode: 400,
|
|
});
|
|
}
|
|
});
|
|
});
|