Skip to content

Commit c286c38

Browse files
Merge pull request #824 from jmcdo29/fix/property-injection-optional
fix: add optional decorator for property based injection
2 parents 15a3595 + b3370b1 commit c286c38

File tree

9 files changed

+38
-12
lines changed

9 files changed

+38
-12
lines changed

jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module.exports = {
22
moduleFileExtensions: ['js', 'json', 'ts'],
33
rootDir: '.',
4-
testMatch: ['<rootDir>/test/*.e2e-spec.ts'],
4+
testMatch: ['<rootDir>/test/**/*.e2e-spec.ts'],
55
transform: {
66
'^.+\\.ts$': 'ts-jest'
77
},
88
testEnvironment: 'node',
9-
collectCoverage: true
9+
collectCoverage: true,
10+
collectCoverageFrom: ['lib/**/*.ts']
1011
};

lib/auth.guard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const NO_STRATEGY_ERROR = `In order to use "defaultStrategy", please, ensure to
3131

3232
function createAuthGuard(type?: string | string[]): Type<CanActivate> {
3333
class MixinAuthGuard<TUser = any> implements CanActivate {
34+
@Optional()
3435
@Inject(AuthModuleOptions)
3536
protected options: AuthModuleOptions;
3637
constructor(@Optional() options?: AuthModuleOptions) {

test/app.controller.ts renamed to test/common/app.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
2-
import { AuthGuard } from '../lib';
2+
import { AuthGuard } from '../../lib';
33

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

test/app.e2e-spec.ts renamed to test/common/app.e2e-spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Test } from '@nestjs/testing';
33
import { spec, request } from 'pactum';
4-
import { AppModule } from './app.module';
4+
import { AppModule as WithRegisterModule } from '../with-register/app.module';
5+
import { AppModule as WithoutRegisterModule } from '../without-register/app.module';
56

6-
describe('Passport Module', () => {
7+
describe.each`
8+
AppModule | RegisterUse
9+
${WithRegisterModule} | ${'with'}
10+
${WithoutRegisterModule} | ${'without'}
11+
`('Passport Module $RegisterUse register()', ({ AppModule }) => {
712
let app: INestApplication;
813

914
beforeAll(async () => {
File renamed without changes.

test/jwt.strategy.ts renamed to test/common/jwt.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { ExtractJwt, Strategy } from 'passport-jwt';
3-
import { PassportStrategy } from '../lib';
3+
import { PassportStrategy } from '../../lib';
44

55
@Injectable()
66
export class JwtStrategy extends PassportStrategy(Strategy) {

test/local.strategy.ts renamed to test/common/local.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { Strategy } from 'passport-local';
3-
import { PassportStrategy } from '../lib';
3+
import { PassportStrategy } from '../../lib';
44
import { AppService } from './app.service';
55

66
@Injectable()

test/app.module.ts renamed to test/with-register/app.module.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Module } from '@nestjs/common';
22
import { JwtModule } from '@nestjs/jwt';
3-
import { PassportModule } from '../lib';
4-
import { AppController } from './app.controller';
5-
import { AppService } from './app.service';
6-
import { JwtStrategy } from './jwt.strategy';
7-
import { LocalStrategy } from './local.strategy';
3+
import { PassportModule } from '../../lib';
4+
import { AppController } from '../common/app.controller';
5+
import { AppService } from '../common/app.service';
6+
import { JwtStrategy } from '../common/jwt.strategy';
7+
import { LocalStrategy } from '../common/local.strategy';
88

99
@Module({
1010
controllers: [AppController],

test/without-register/app.module.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Module } from '@nestjs/common';
2+
import { JwtModule } from '@nestjs/jwt';
3+
import { PassportModule } from '../../lib';
4+
import { AppController } from '../common/app.controller';
5+
import { AppService } from '../common/app.service';
6+
import { JwtStrategy } from '../common/jwt.strategy';
7+
import { LocalStrategy } from '../common/local.strategy';
8+
9+
@Module({
10+
controllers: [AppController],
11+
imports: [
12+
JwtModule.register({
13+
secret: 's3cr3t'
14+
}),
15+
PassportModule
16+
],
17+
providers: [AppService, LocalStrategy, JwtStrategy]
18+
})
19+
export class AppModule {}

0 commit comments

Comments
 (0)