File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { MiddlewareMiddleware } from './index' ;
2
+ import { expect } from 'chai' ;
3
+
4
+ describe ( 'MiddlewareMiddleware' , ( ) => {
5
+ let middleware : MiddlewareMiddleware ;
6
+ describe ( 'properly configured' , ( ) => {
7
+ beforeEach ( ( ) => {
8
+ MiddlewareMiddleware . configure ( { } ) ;
9
+ middleware = new MiddlewareMiddleware ( ) ;
10
+ } ) ;
11
+
12
+ it ( 'should be defined' , ( ) => {
13
+ expect ( middleware ) . to . not . be . undefined ;
14
+ } ) ;
15
+
16
+ it ( 'should have a function called resolve' , ( ) => {
17
+ expect ( middleware . resolve ) . to . be . instanceof ( Function ) ;
18
+ } ) ;
19
+
20
+ it ( 'should should return a middleware from calling resolve' , ( ) => {
21
+ expect ( middleware . resolve ( ) ) . to . be . an . instanceof ( Function ) ;
22
+ } ) ;
23
+ afterEach ( ( ) => {
24
+ MiddlewareMiddleware . configure ( undefined ) ;
25
+ } ) ;
26
+ } ) ;
27
+
28
+ describe ( 'not configured' , ( ) => {
29
+ middleware = new MiddlewareMiddleware ( ) ;
30
+ it ( 'should should return a middleware from calling resolve' , ( ) => {
31
+ expect ( middleware . resolve ( ) ) . to . be . an . instanceof ( Function ) ;
32
+ } ) ;
33
+ } ) ;
34
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import * as cookieSession from 'cookie-session' ;
2
+
3
+ import { Middleware , NestMiddleware } from '@nestjs/common' ;
4
+
5
+ import { RequestHandler } from 'express' ;
6
+
7
+ @Middleware ( )
8
+ export class MiddlewareMiddleware implements NestMiddleware {
9
+
10
+ // DELETE THESE LINES IF MIDDLEWARE DOES NOT TAKE OPTIONS
11
+ public static configure ( opts : cookieSession . CookieSessionOptions ) {
12
+ this . options = opts ;
13
+ }
14
+
15
+ private static options : cookieSession . CookieSessionOptions ;
16
+
17
+ public resolve ( ...args : any [ ] ) {
18
+ if ( MiddlewareMiddleware . options ) {
19
+ return cookieSession ( MiddlewareMiddleware . options ) ;
20
+ } else {
21
+ return cookieSession ( ) ;
22
+ }
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @nest-middlewares/middleware-name" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " NestJS middleware for Middleware" ,
5
+ "main" : " index" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/wbhob/nest-middlewares.git"
12
+ },
13
+ "keywords" : [
14
+ " nest" ,
15
+ " middlewares" ,
16
+ " express" ,
17
+ " node"
18
+ ],
19
+ "author" : " Wilson Hobbs <wilsonhobbs1@gmail.com>" ,
20
+ "license" : " MIT" ,
21
+ "bugs" : {
22
+ "url" : " https://github.com/wbhob/nest-middlewares/issues"
23
+ },
24
+ "homepage" : " https://github.com/wbhob/nest-middlewares#readme" ,
25
+ "peerDependencies" : {
26
+ "@nestjs/common" : " ^4.0.0"
27
+ },
28
+ "dependencies" : {
29
+ "cookie-session" : " ^2.0.0-beta.3"
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments