https://github.com/flowcore-io/library-testing-nestjs-oidc-protect-ts
A NestJS OidcProtect plugin for the @jbiskur/nestjs-test-utilities testing library. To facilitate mocking successfull calls to protected routes during testing.
https://github.com/flowcore-io/library-testing-nestjs-oidc-protect-ts
Last synced: 5 days ago
JSON representation
A NestJS OidcProtect plugin for the @jbiskur/nestjs-test-utilities testing library. To facilitate mocking successfull calls to protected routes during testing.
- Host: GitHub
- URL: https://github.com/flowcore-io/library-testing-nestjs-oidc-protect-ts
- Owner: flowcore-io
- License: mit
- Created: 2023-01-02T22:49:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-26T13:36:26.000Z (about 3 years ago)
- Last Synced: 2025-10-10T05:25:51.310Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 188 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README

# Testing Nestjs-oidc-protect
A NestJS OidcProtect plugin for
the [@jbiskur/nestjs-test-utilities](https://www.npmjs.com/package/@jbiskur/nestjs-test-utilities) testing library. To
facilitate mocking
successfull
calls to protected routes during testing.
## Installation
install with npm:
```bash
npm install @flowcore/testing-nestjs-oidc-protect @flowcore/nestjs-oidc-protect
```
or yarn:
```bash
yarn add @flowcore/testing-nestjs-oidc-protect @flowcore/nestjs-oidc-protect
```
## Usage
To use the library with the `@jbiskur/nestjs-test-utilities` testing library, you need to invoke it using `with`:
```typescript
import {OidcProtectModulePlugin} from '@flowcore/testing-nestjs-oidc-protect';
app = await new NestApplicationBuilder()
.withTestModule((testModule) => testModule.withModule(TestModule))
// ... other plugins
.with(OidcProtectModulePlugin)
// ... other plugins
.build();
```
It is possible to set the authenticated payload that will be returned by the `AuthGuard`:
```typescript
import {OidcProtectModulePlugin} from '@flowcore/testing-nestjs-oidc-protect';
app = await new NestApplicationBuilder()
.withTestModule((testModule) => testModule.withModule(TestModule))
// ... other plugins
.with(OidcProtectModulePlugin, pluginBuilder => pluginBuilder.usingAuthenticatedPayload(validTokenPayload))
.build();
```
It is also possible to set the module to always act as if the user is unauthenticated:
```typescript
import {OidcProtectModulePlugin} from '@flowcore/testing-nestjs-oidc-protect';
app = await new NestApplicationBuilder()
.withTestModule((testModule) => testModule.withModule(TestModule))
// ... other plugins
.with(OidcProtectModulePlugin, pluginBuilder => pluginBuilder.forceUnauthenticatedUser())
.build();
```
## Development
```bash
yarn install
```
or with npm:
```bash
npm install
```