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.
update(@nestjs) increase test coverage, update package dependencies
- Loading branch information
kamil.mysliwiec
committed
Jul 23, 2017
1 parent
b79eda2
commit 260fd56
Showing
56 changed files
with
1,227 additions
and
208 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ npm-debug.log | |
# example | ||
/quick-start | ||
/example_dist | ||
/example | ||
|
||
# tests | ||
/test | ||
|
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 |
---|---|---|
|
@@ -8,5 +8,4 @@ before_script: | |
- sh -e /etc/init.d/xvfb start | ||
script: | ||
- npm test | ||
- npm run build | ||
after_success: npm run coverage |
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
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,26 @@ | ||
import 'reflect-metadata'; | ||
import { expect } from 'chai'; | ||
import { UseGuards } from '../../utils/decorators/use-guards.decorator'; | ||
import { GUARDS_METADATA } from './../../constants'; | ||
|
||
describe('@UseGuards', () => { | ||
const guards = [ 'guard1', 'guard2' ]; | ||
|
||
@UseGuards(...guards as any) class Test {} | ||
|
||
class TestWithMethod { | ||
@UseGuards(...guards as any) | ||
public static test() {} | ||
} | ||
|
||
it('should enhance class with expected guards array', () => { | ||
const metadata = Reflect.getMetadata(GUARDS_METADATA, Test); | ||
expect(metadata).to.be.eql(guards); | ||
}); | ||
|
||
it('should enhance method with expected guards array', () => { | ||
const metadata = Reflect.getMetadata(GUARDS_METADATA, TestWithMethod.test); | ||
expect(metadata).to.be.eql(guards); | ||
}); | ||
|
||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { isFunction } from '@nestjs/common/utils/shared.utils'; | ||
import { Metatype } from '@nestjs/common/interfaces'; | ||
|
||
export const filterMiddlewares = (middlewares) => { | ||
return [].concat(middlewares) | ||
.filter(isFunction) | ||
.map((middleware) => mapToClass(middleware)); | ||
}; | ||
|
||
export const mapToClass = (middleware) => { | ||
if (this.isClass(middleware)) { | ||
return middleware; | ||
} | ||
return assignToken(class { | ||
public resolve = (...args) => (req, res, next) => middleware(req, res, next); | ||
}); | ||
}; | ||
|
||
export const isClass = (middleware) => { | ||
return middleware.toString().substring(0, 5) === 'class'; | ||
}; | ||
|
||
export const assignToken = (metatype): Metatype<any> => { | ||
this.id = this.id || 1; | ||
Object.defineProperty(metatype, 'name', { value: ++this.id }); | ||
return metatype; | ||
}; |
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
Oops, something went wrong.