feat: allow any logged-in user to create a team

This commit is contained in:
Bastian Wagner
2026-08-03 15:38:43 +02:00
parent 09da67b8ef
commit 92eacbc5bb
2 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
import { GUARDS_METADATA } from '@nestjs/common/constants';
import { RoleEnum } from '../roles/roles.enum';
import { RolesGuard } from '../roles/roles.guard';
import { TeamsController } from './teams.controller';
describe('TeamsController', () => {
const service = { createNewTeam: jest.fn() };
const publicAccess = {};
const teamMembers = {};
const teamPermissions = {};
const controller = new TeamsController(
service as any,
publicAccess as any,
teamMembers as any,
teamPermissions as any,
);
beforeEach(() => jest.clearAllMocks());
it('allows any logged-in user (not just admins) to create a team', () => {
expect(Reflect.getMetadata('roles', TeamsController.prototype.create)).toEqual([
RoleEnum.user,
RoleEnum.admin,
]);
expect(
Reflect.getMetadata(GUARDS_METADATA, TeamsController.prototype.create),
).toContain(RolesGuard);
});
it('passes the authenticated user and the DTO to the service', () => {
const req = { user: { id: 42 } };
const dto = { name: '1. Herren' };
controller.create(req as any, dto as any);
expect(service.createNewTeam).toHaveBeenCalledWith(dto, 42);
});
});

View File

@@ -244,7 +244,7 @@ export class TeamsController {
'Erstellt ein neues Team mit gegebenem Namen und gibt es zurück.',
})
@ApiBearerAuth()
@Roles([RoleEnum.admin])
@Roles([RoleEnum.user, RoleEnum.admin])
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Post()
@HttpCode(HttpStatus.CREATED)