forked from nestjs/nest
-
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.
tests(@nestjs/core) fix failing unit tests
- Loading branch information
1 parent
c9184ac
commit 4cfda07
Showing
8 changed files
with
152 additions
and
78 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
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,131 @@ | ||
import { RequestMethod } from '@nestjs/common'; | ||
import { expect } from 'chai'; | ||
import { Controller, Get } from '../../../common'; | ||
import { NestContainer } from '../../injector/container'; | ||
import { MiddlewareBuilder } from '../../middleware/builder'; | ||
import { RoutesMapper } from '../../middleware/routes-mapper'; | ||
|
||
describe('MiddlewareBuilder', () => { | ||
let builder: MiddlewareBuilder; | ||
|
||
beforeEach(() => { | ||
builder = new MiddlewareBuilder(new RoutesMapper(new NestContainer())); | ||
}); | ||
describe('apply', () => { | ||
let configProxy; | ||
beforeEach(() => { | ||
configProxy = builder.apply([]); | ||
}); | ||
it('should return configuration proxy', () => { | ||
const metatype = (MiddlewareBuilder as any).ConfigProxy; | ||
expect(configProxy instanceof metatype).to.be.true; | ||
}); | ||
describe('configuration proxy', () => { | ||
it('should returns itself on "with()" call', () => { | ||
expect(configProxy.with()).to.be.eq(configProxy); | ||
}); | ||
describe('when "forRoutes()" called', () => { | ||
@Controller('path') | ||
class Test { | ||
@Get('route') | ||
public getAll() {} | ||
} | ||
const route = { path: '/test', method: 0 }; | ||
it('should store configuration passed as argument', () => { | ||
configProxy.forRoutes(route, Test); | ||
|
||
expect(builder.build()).to.deep.equal([ | ||
{ | ||
middleware: [], | ||
forRoutes: [ | ||
{ | ||
method: 0, | ||
path: route.path, | ||
}, | ||
{ | ||
method: 0, | ||
path: '/path/route', | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('exclude', () => { | ||
it('should map string to RouteInfo', () => { | ||
const path = '/test'; | ||
const proxy: any = builder.apply().exclude(path); | ||
|
||
expect(proxy.getExcludedRoutes()).to.be.eql([ | ||
{ | ||
path, | ||
method: RequestMethod.ALL, | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('isRouteExcluded', () => { | ||
const routeInfo = { path: '/test', method: RequestMethod.POST }; | ||
let proxy: any; | ||
|
||
beforeEach(() => { | ||
proxy = builder.apply(); | ||
}); | ||
describe('when path is equal', () => { | ||
describe('when method is ALL', () => { | ||
it('should return true', () => { | ||
proxy.exclude(routeInfo.path); | ||
|
||
expect(proxy.isRouteExcluded(routeInfo)).to.be.true; | ||
}); | ||
}); | ||
describe('when method is equal', () => { | ||
it('should return true', () => { | ||
proxy.exclude({ | ||
path: routeInfo.path, | ||
method: RequestMethod.POST, | ||
}); | ||
|
||
expect(proxy.isRouteExcluded(routeInfo)).to.be.true; | ||
}); | ||
}); | ||
describe('when path has / at the end', () => { | ||
it('should return true', () => { | ||
proxy.exclude({ | ||
path: 'test', | ||
method: RequestMethod.POST, | ||
}); | ||
|
||
expect(proxy.isRouteExcluded({ | ||
...routeInfo, | ||
path: '/test/', | ||
})).to.be.true; | ||
}); | ||
}); | ||
describe('when method is not equal', () => { | ||
it('should return false', () => { | ||
proxy.exclude({ | ||
path: routeInfo.path, | ||
method: RequestMethod.GET, | ||
}); | ||
|
||
expect(proxy.isRouteExcluded(routeInfo)).to.be.false; | ||
}); | ||
}); | ||
}); | ||
describe('when path is not equal', () => { | ||
it('should return false', () => { | ||
proxy.exclude({ | ||
path: 'testx', | ||
method: RequestMethod.POST, | ||
}); | ||
|
||
expect(proxy.isRouteExcluded(routeInfo)).to.be.false; | ||
}); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.