Skip to content

Commit

Permalink
Add SecurityController tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed May 19, 2024
1 parent 675c7dd commit d6930fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 11 additions & 1 deletion apps/api/src/security/security.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { CreateSecurityRuleDto } from './dto/create-security-rule.dto';
import { DeleteSecurityRuleDto } from './dto/delete-security-rule.dto';
import { UpdateSecurityRuleDto } from './dto/update-security-rule.dto';
import { HasOrganizationAccessPipe } from './pipes/has-organization-access.pipe';
import { HasOwnerAccessPipe } from './pipes/has-owner-access.pipe';
import { SecurityValidationPipe } from './pipes/security-validation.pipe';
import { SecurityController } from './security.controller';
import { SecurityService } from './security.service';
import { HasOwnerAccessPipe } from './pipes/has-owner-access.pipe';

describe('SecurityController', () => {
let controller: SecurityController;
Expand All @@ -23,6 +23,7 @@ describe('SecurityController', () => {
updateRule: jest.fn(),
deleteRule: jest.fn(),
paginateMembers: jest.fn(() => ({ meta: { page: 1 }, items: [] }) as PageDto<SecurityRuleDto>),
transferOwnership: jest.fn(),
};

const mockUserService = {
Expand Down Expand Up @@ -204,4 +205,13 @@ describe('SecurityController', () => {

expect(result.role).toBe(OrganizationSecurityRole.ADMIN);
});

it('should transfer ownership', async () => {
const organization = new Types.ObjectId();
const to = new Types.ObjectId();
const result = await controller.transfer(organization, { user: to.toString() });

expect(result.statusCode).toBe(200);
expect(mockSecurityService.transferOwnership).toBeCalledWith(organization, to);
});
});
1 change: 0 additions & 1 deletion apps/api/src/security/security.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export class SecurityController {
@Body() body: TransferOrganizationDto,
): Promise<any> {
const to = new Types.ObjectId(body.user);

await this.securityService.transferOwnership(org, to);
return { statusCode: 200 };
}
Expand Down

0 comments on commit d6930fe

Please sign in to comment.