This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make tests work again with mocked AuthModule
- Loading branch information
Showing
4 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
import { JwtAuthGuard } from '../src/auth/core/jwt-auth.guard'; | ||
import { APP_GUARD } from '@nestjs/core'; | ||
|
||
/** | ||
* Can be used as an overrideModule replacement of AuthModule to disable the JwtAuthGuard and remove need for external Auth server. | ||
*/ | ||
@Module({ | ||
imports: [ | ||
HttpModule, | ||
JwtModule.register({ | ||
global: true, | ||
secret: 'TEST_SECRET', | ||
}), | ||
], | ||
providers: [ | ||
JwtAuthGuard, | ||
{ | ||
provide: APP_GUARD, | ||
useClass: JwtAuthGuard, | ||
}, | ||
], | ||
exports: [JwtAuthGuard], | ||
}) | ||
export class MockAuthModule { | ||
constructor() { | ||
// disable auth guard | ||
JwtAuthGuard.prototype.canActivate = jest.fn().mockReturnValue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters