-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: resolve conflicts, update tests
- Loading branch information
Showing
7 changed files
with
305 additions
and
23 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
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,56 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
import { DECORATORS } from '../../lib/constants'; | ||
import { ApiParam } from '../../lib/decorators'; | ||
|
||
describe('ApiParam', () => { | ||
describe('when applied on the class level', () => { | ||
@ApiParam({ name: 'testId' }) | ||
@Controller('tests/:testId') | ||
class TestAppController { | ||
@Get() | ||
public get(@Param('testId') testId: string): string { | ||
return testId; | ||
} | ||
|
||
public noAPiMethod(): void {} | ||
} | ||
|
||
it('should attach metadata to all API methods', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toBeTruthy(); | ||
expect( | ||
Reflect.getMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toEqual([{ in: 'path', name: 'testId', required: true }]); | ||
}); | ||
|
||
it('should not attach metadata to non-API method (not a route)', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.noAPiMethod) | ||
).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('when applied on the method level', () => { | ||
@Controller('tests/:testId') | ||
class TestAppController { | ||
@Get() | ||
@ApiParam({ name: 'testId' }) | ||
public get(@Param('testId') testId: string): string { | ||
return testId; | ||
} | ||
} | ||
|
||
it('should attach metadata to a given method', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toBeTruthy(); | ||
expect( | ||
Reflect.getMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toEqual([{ in: 'path', name: 'testId', required: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Controller, Get, Query } from '@nestjs/common'; | ||
import { DECORATORS } from '../../lib/constants'; | ||
import { ApiQuery } from '../../lib/decorators'; | ||
|
||
describe('ApiQuery', () => { | ||
describe('when applied on the class level', () => { | ||
@ApiQuery({ name: 'testId' }) | ||
@Controller('test') | ||
class TestAppController { | ||
@Get() | ||
public get(@Query('testId') testId: string): string { | ||
return testId; | ||
} | ||
|
||
public noAPiMethod(): void {} | ||
} | ||
|
||
it('should attach metadata to all API methods', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toBeTruthy(); | ||
expect( | ||
Reflect.getMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toEqual([{ in: 'query', name: 'testId', required: true }]); | ||
}); | ||
|
||
it('should not attach metadata to non-API method (not a route)', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.noAPiMethod) | ||
).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('when applied on the method level', () => { | ||
@Controller('tests/:testId') | ||
class TestAppController { | ||
@Get() | ||
@ApiQuery({ name: 'testId' }) | ||
public get(@Query('testId') testId: string): string { | ||
return testId; | ||
} | ||
} | ||
|
||
it('should attach metadata to a given method', () => { | ||
const controller = new TestAppController(); | ||
expect( | ||
Reflect.hasMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toBeTruthy(); | ||
expect( | ||
Reflect.getMetadata(DECORATORS.API_PARAMETERS, controller.get) | ||
).toEqual([{ in: 'query', name: 'testId', required: 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