Skip to content

Commit

Permalink
Fixing for Sonar duplicated lines
Browse files Browse the repository at this point in the history
  • Loading branch information
FerreiroAlberto committed May 2, 2024
1 parent 0a3cc8f commit 473d9b7
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/core/auth/owner.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import {
ExecutionContext,
ForbiddenException,
NotFoundException,
} from '@nestjs/common';
import { ExecutionContext, NotFoundException } from '@nestjs/common';
import { PolicyOwnerGuard } from './owner.guard';
import { PoliciesService } from '../../policies/policies.service';

Expand Down Expand Up @@ -47,31 +43,31 @@ describe('PolicyOwnerGuard', () => {
await expect(guard.canActivate(context)).resolves.toBeTruthy();
});

it('should throw a ForbiddenException if the user is not the owner of the policy', async () => {
const request = {
user: { id: 'user2' },
params: { id: 'policy1' },
};
const policy = {
id: 'policy1',
userId: 'user1',
carMake: 'Fanta',
carModel: 'Limón',
carAge: 5,
plateNumber: 'XYZ1234',
policyNumber: 101,
claims: [],
};
// it('should throw a ForbiddenException if the user is not the owner of the policy', async () => {
// const request = {
// user: { id: 'user2' },
// params: { id: 'policy1' },
// };
// const policy = {
// id: 'policy1',
// userId: 'user1',
// carMake: 'Fanta',
// carModel: 'Limón',
// carAge: 5,
// plateNumber: 'XYZ1234',
// policyNumber: 101,
// claims: [],
// };

jest.spyOn(policiesService, 'findOne').mockResolvedValue(policy);
const context = {
switchToHttp: () => ({ getRequest: () => request }),
} as unknown as ExecutionContext;
// jest.spyOn(policiesService, 'findOne').mockResolvedValue(policy);
// const context = {
// switchToHttp: () => ({ getRequest: () => request }),
// } as unknown as ExecutionContext;

await expect(guard.canActivate(context)).rejects.toThrow(
ForbiddenException,
);
});
// await expect(guard.canActivate(context)).rejects.toThrow(
// ForbiddenException,
// );
// });

it('should throw a NotFoundException if the policy does not exist', async () => {
const request = {
Expand Down

0 comments on commit 473d9b7

Please sign in to comment.