-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Miroslav Bajtoš <mbajtoss@gmail.com>
- Loading branch information
1 parent
124c078
commit f47ccc5
Showing
10 changed files
with
609 additions
and
13 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
151 changes: 151 additions & 0 deletions
151
packages/rest/src/__tests__/unit/router/assign-router-spec.unit.ts
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,151 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/rest | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {expect} from '@loopback/testlab'; | ||
import {assignRouterSpec, RouterSpec} from '../../../router'; | ||
|
||
describe('assignRouterSpec', () => { | ||
it('duplicates the additions spec if the target spec is empty', async () => { | ||
const target: RouterSpec = {paths: {}}; | ||
const additions: RouterSpec = { | ||
paths: { | ||
'/': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'greeting', | ||
content: { | ||
'application/json': { | ||
schema: {type: 'string'}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
Greeting: { | ||
type: 'object', | ||
properties: { | ||
message: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
tags: [{name: 'greeting', description: 'greetings'}], | ||
}; | ||
|
||
assignRouterSpec(target, additions); | ||
expect(target).to.eql(additions); | ||
}); | ||
|
||
it('does not assign components without schema', async () => { | ||
const target: RouterSpec = { | ||
paths: {}, | ||
components: {}, | ||
}; | ||
|
||
const additions: RouterSpec = { | ||
paths: {}, | ||
components: { | ||
parameters: { | ||
addParam: { | ||
name: 'add', | ||
in: 'query', | ||
description: 'number of items to add', | ||
required: true, | ||
schema: { | ||
type: 'integer', | ||
format: 'int32', | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
Hello: { | ||
description: 'Hello.', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
assignRouterSpec(target, additions); | ||
expect(target.components).to.be.empty(); | ||
}); | ||
|
||
it('uses the route registered first', async () => { | ||
const target: RouterSpec = { | ||
paths: { | ||
'/': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'greeting', | ||
content: { | ||
'application/json': { | ||
schema: {type: 'string'}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const additions: RouterSpec = { | ||
paths: { | ||
'/': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'additional greeting', | ||
content: { | ||
'application/json': { | ||
schema: {type: 'string'}, | ||
}, | ||
}, | ||
}, | ||
'404': { | ||
description: 'Error: no greeting', | ||
content: { | ||
'application/json': { | ||
schema: {type: 'string'}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
assignRouterSpec(target, additions); | ||
expect(target.paths).to.equal(target.paths); | ||
}); | ||
|
||
it('does not duplicate tags from the additional spec', async () => { | ||
const target: RouterSpec = { | ||
paths: {}, | ||
tags: [{name: 'greeting', description: 'greetings'}], | ||
}; | ||
const additions: RouterSpec = { | ||
paths: {}, | ||
tags: [ | ||
{name: 'greeting', description: 'additional greetings'}, | ||
{name: 'salutation', description: 'salutations!'}, | ||
], | ||
}; | ||
|
||
assignRouterSpec(target, additions); | ||
expect(target.tags).to.containDeep([ | ||
{name: 'greeting', description: 'greetings'}, | ||
{name: 'salutation', description: 'salutations!'}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.