Skip to content

Commit

Permalink
test coverage for permissions.decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
pkleybolte committed Dec 12, 2024
1 parent e943c55 commit 40621e8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/authentication/api/permissions.decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PersonPermissions } from '../domain/person-permissions.js';
import { ExecutionContext } from '@nestjs/common';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import express from 'express';
import { PassportUser } from '../types/user.js';

describe('The Permissions-Decorator', () => {
let factory: (data: unknown, context: ExecutionContext) => Promise<PersonPermissions | undefined>;
Expand Down Expand Up @@ -46,6 +47,13 @@ describe('The Permissions-Decorator', () => {
await expect(factory(null, executionContext)).resolves.toBe(personPermissions);
});

it('should reject if passport user is set without personPermission function', async () => {
const context: ExecutionContext = createMock();
context.switchToHttp().getRequest<DeepMocked<express.Request>>().passportUser = {} as PassportUser;

await expect(factory(null, context)).rejects.toBeUndefined();
});

it('should reject if there is no passport user', async () => {
const context: ExecutionContext = createMock();
context.switchToHttp().getRequest<DeepMocked<express.Request>>().passportUser = undefined;
Expand Down

0 comments on commit 40621e8

Please sign in to comment.