fix: allow public tournament code replacement
This commit is contained in:
1 parent
303886ed53
commit
b9881fcb6f
7 files changed
+117
-27
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED } from '../auth/allow-public-access.decorator';
|
||||
import { TournamentCodeReplacementController } from './tournament-code-replacement.controller';
|
||||
import type { TournamentCodeService } from './tournament-code.service';
|
||||
|
||||
describe('TournamentCodeReplacementController', () => {
|
||||
function createFixture() {
|
||||
const service = {
|
||||
replaceForMatchGame: jest.fn().mockResolvedValue({
|
||||
gameNumber: 1,
|
||||
code: 'NEW-CODE',
|
||||
}),
|
||||
} as unknown as jest.Mocked<
|
||||
Pick<TournamentCodeService, 'replaceForMatchGame'>
|
||||
>;
|
||||
const controller = new TournamentCodeReplacementController(
|
||||
service as unknown as TournamentCodeService,
|
||||
);
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
|
||||
return { controller, service, communityId, matchId };
|
||||
}
|
||||
|
||||
it('allows public replacement requests', async () => {
|
||||
const { controller, service, communityId, matchId } = createFixture();
|
||||
|
||||
await expect(
|
||||
controller.replaceForMatchGame(communityId, matchId, 1),
|
||||
).resolves.toEqual(expect.objectContaining({ code: 'NEW-CODE' }));
|
||||
|
||||
expect(service.replaceForMatchGame).toHaveBeenCalledWith({
|
||||
communityId,
|
||||
matchId,
|
||||
gameNumber: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('marks the replacement endpoint as public access', () => {
|
||||
expect(
|
||||
Reflect.getMetadata(
|
||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
||||
TournamentCodeReplacementController.prototype.replaceForMatchGame,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user