Skip to content

Commit

Permalink
Merge pull request #824 from jmcdo29/fix/property-injection-optional
Browse files Browse the repository at this point in the history
fix: add optional decorator for property based injection
  • Loading branch information
kamilmysliwiec authored Feb 15, 2022
2 parents 15a3595 + b3370b1 commit c286c38
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 12 deletions.
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testMatch: ['<rootDir>/test/*.e2e-spec.ts'],
testMatch: ['<rootDir>/test/**/*.e2e-spec.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
testEnvironment: 'node',
collectCoverage: true
collectCoverage: true,
collectCoverageFrom: ['lib/**/*.ts']
};
1 change: 1 addition & 0 deletions lib/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const NO_STRATEGY_ERROR = `In order to use "defaultStrategy", please, ensure to

function createAuthGuard(type?: string | string[]): Type<CanActivate> {
class MixinAuthGuard<TUser = any> implements CanActivate {
@Optional()
@Inject(AuthModuleOptions)
protected options: AuthModuleOptions;
constructor(@Optional() options?: AuthModuleOptions) {
Expand Down
2 changes: 1 addition & 1 deletion test/app.controller.ts → test/common/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../lib';
import { AuthGuard } from '../../lib';

import { AppService } from './app.service';

Expand Down
9 changes: 7 additions & 2 deletions test/app.e2e-spec.ts → test/common/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { spec, request } from 'pactum';
import { AppModule } from './app.module';
import { AppModule as WithRegisterModule } from '../with-register/app.module';
import { AppModule as WithoutRegisterModule } from '../without-register/app.module';

describe('Passport Module', () => {
describe.each`
AppModule | RegisterUse
${WithRegisterModule} | ${'with'}
${WithoutRegisterModule} | ${'without'}
`('Passport Module $RegisterUse register()', ({ AppModule }) => {
let app: INestApplication;

beforeAll(async () => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/jwt.strategy.ts → test/common/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '../lib';
import { PassportStrategy } from '../../lib';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
Expand Down
2 changes: 1 addition & 1 deletion test/local.strategy.ts → test/common/local.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Strategy } from 'passport-local';
import { PassportStrategy } from '../lib';
import { PassportStrategy } from '../../lib';
import { AppService } from './app.service';

@Injectable()
Expand Down
10 changes: 5 additions & 5 deletions test/app.module.ts → test/with-register/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '../lib';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { JwtStrategy } from './jwt.strategy';
import { LocalStrategy } from './local.strategy';
import { PassportModule } from '../../lib';
import { AppController } from '../common/app.controller';
import { AppService } from '../common/app.service';
import { JwtStrategy } from '../common/jwt.strategy';
import { LocalStrategy } from '../common/local.strategy';

@Module({
controllers: [AppController],
Expand Down
19 changes: 19 additions & 0 deletions test/without-register/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '../../lib';
import { AppController } from '../common/app.controller';
import { AppService } from '../common/app.service';
import { JwtStrategy } from '../common/jwt.strategy';
import { LocalStrategy } from '../common/local.strategy';

@Module({
controllers: [AppController],
imports: [
JwtModule.register({
secret: 's3cr3t'
}),
PassportModule
],
providers: [AppService, LocalStrategy, JwtStrategy]
})
export class AppModule {}

0 comments on commit c286c38

Please sign in to comment.