fix: stabilize competition results flow
This commit is contained in:
1 parent
3bd3120eb1
commit
a88562b208
20 files changed
+411
-65
No files matched your search
@@ -7,7 +7,7 @@ import { CompetitionController } from './competition.controller';
|
||||
import { CompetitionQueryService } from './competition-query.service';
|
||||
|
||||
describe('CompetitionController', () => {
|
||||
it('marks only the detail endpoint public and writes a revision ETag', async () => {
|
||||
it('marks the read endpoints public and writes a revision ETag', async () => {
|
||||
const { controller, queryService } = createHarness();
|
||||
const response = { setHeader: jest.fn() };
|
||||
|
||||
@@ -17,18 +17,14 @@ describe('CompetitionController', () => {
|
||||
response as never,
|
||||
);
|
||||
|
||||
expect(
|
||||
Reflect.getMetadata(
|
||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
||||
CompetitionController.prototype.getDetail,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
Reflect.getMetadata(
|
||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
||||
CompetitionController.prototype.getTeamView,
|
||||
),
|
||||
).not.toBe(true);
|
||||
for (const method of ['getDetail', 'getTeamView'] as const) {
|
||||
expect(
|
||||
Reflect.getMetadata(
|
||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
||||
CompetitionController.prototype[method],
|
||||
),
|
||||
).toBe(true);
|
||||
}
|
||||
expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"');
|
||||
expect(result).toMatchObject({ revision: 7 });
|
||||
expect(queryService.getCompetition).toHaveBeenCalledWith({
|
||||
@@ -37,6 +33,65 @@ describe('CompetitionController', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('reads a team view by explicit team id without an authenticated caller', async () => {
|
||||
const { controller, queryService } = createHarness();
|
||||
queryService.getTeamView.mockResolvedValue({ revision: 7 });
|
||||
const response = { setHeader: jest.fn() };
|
||||
|
||||
const result = await controller.getTeamView(
|
||||
undefined,
|
||||
COMMUNITY_ID,
|
||||
MATCH_ID,
|
||||
TEAM_A_ID.toHexString(),
|
||||
response as never,
|
||||
);
|
||||
|
||||
expect(queryService.getTeamView).toHaveBeenCalledWith({
|
||||
communityId: COMMUNITY_ID,
|
||||
matchId: MATCH_ID,
|
||||
teamId: TEAM_A_ID,
|
||||
});
|
||||
expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"');
|
||||
expect(result).toMatchObject({ revision: 7 });
|
||||
});
|
||||
|
||||
it('falls back to the membership-scoped team view for a signed-in caller', async () => {
|
||||
const { controller, queryService } = createHarness();
|
||||
queryService.getTeamView.mockResolvedValue({ revision: 7 });
|
||||
|
||||
await controller.getTeamView(adminUser(), COMMUNITY_ID, MATCH_ID);
|
||||
|
||||
expect(queryService.getTeamView).toHaveBeenCalledWith({
|
||||
communityId: COMMUNITY_ID,
|
||||
matchId: MATCH_ID,
|
||||
userId: ADMIN_ID,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects an anonymous team view request that names no team', async () => {
|
||||
const { controller, queryService } = createHarness();
|
||||
|
||||
await expect(
|
||||
controller.getTeamView(undefined, COMMUNITY_ID, MATCH_ID),
|
||||
).rejects.toMatchObject({
|
||||
status: 401,
|
||||
response: { error: { code: 'COMPETITION_TEAM_UNIDENTIFIED' } },
|
||||
});
|
||||
expect(queryService.getTeamView).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects a malformed team id', async () => {
|
||||
const { controller, queryService } = createHarness();
|
||||
|
||||
await expect(
|
||||
controller.getTeamView(undefined, COMMUNITY_ID, MATCH_ID, 'not-an-id'),
|
||||
).rejects.toMatchObject({
|
||||
status: 422,
|
||||
response: { error: { code: 'INVALID_COMPETITION_REQUEST' } },
|
||||
});
|
||||
expect(queryService.getTeamView).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('protects audit and mutation endpoints with admin roles', () => {
|
||||
for (const method of [
|
||||
'listFacts',
|
||||
|
||||
Reference in new issue
Block a user