@flowcore/testing-nestjs-oidc-protect
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Build

Testing Nestjs-oidc-protect

A NestJS OidcProtect plugin for the @jbiskur/nestjs-test-utilities testing library. To facilitate mocking successfull calls to protected routes during testing.

Installation

install with npm:

npm install @flowcore/testing-nestjs-oidc-protect @flowcore/nestjs-oidc-protect

or yarn:

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:

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:

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:

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

yarn install

or with npm:

npm install

Readme

Keywords

Package Sidebar

Install

npm i @flowcore/testing-nestjs-oidc-protect

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

222 kB

Total Files

16

Last publish

Collaborators

  • jbiskur