feat: allow any logged-in user to create a team
This commit is contained in:
38
myteamwallet_backend/src/teams/teams.controller.spec.ts
Normal file
38
myteamwallet_backend/src/teams/teams.controller.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user