This repository has been archived by the owner on Jul 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from apiaryio/kylef/produces-json
Don't build request/response example pairs for all produces types
- Loading branch information
Showing
4 changed files
with
94 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { expect } from 'chai'; | ||
import fury from 'fury'; | ||
import Parser from '../src/parser'; | ||
|
||
describe('Parser', () => { | ||
let parser; | ||
|
||
before(() => { | ||
parser = new Parser({ minim: fury.minim }); | ||
parser.swagger = { | ||
consumes: [], | ||
produces: [], | ||
}; | ||
}); | ||
|
||
context('content types', () => { | ||
it('gathers null response type when no examples or produces', () => { | ||
const methodValue = {}; | ||
const examples = {}; | ||
const contentTypes = parser.gatherResponseContentTypes(methodValue, examples); | ||
|
||
expect(contentTypes).to.deep.equal([null]); | ||
}); | ||
|
||
it('gathers all example response content types', () => { | ||
const methodValue = {}; | ||
const examples = { | ||
'application/json': '', | ||
'application/hal+json': '', | ||
'application/xml': '', | ||
}; | ||
const contentTypes = parser.gatherResponseContentTypes(methodValue, examples); | ||
|
||
expect(contentTypes).to.deep.equal([ | ||
'application/json', | ||
'application/hal+json', | ||
'application/xml', | ||
]); | ||
}); | ||
|
||
it('gathers first JSON produces without examples', () => { | ||
const methodValue = { | ||
produces: [ | ||
'text/plain', | ||
'application/json', | ||
'application/hal+json', | ||
], | ||
}; | ||
const examples = {}; | ||
const contentTypes = parser.gatherResponseContentTypes(methodValue, examples); | ||
|
||
expect(contentTypes).to.deep.equal(['application/json']); | ||
}); | ||
|
||
it('gathers only example response content types with produces', () => { | ||
const methodValue = { | ||
produces: [ | ||
'application/json', | ||
'application/problem+json', | ||
], | ||
}; | ||
const examples = { | ||
'application/vnd.error+json': '', | ||
}; | ||
const contentTypes = parser.gatherResponseContentTypes(methodValue, examples); | ||
|
||
expect(contentTypes).to.deep.equal(['application/vnd.error+json']); | ||
}); | ||
|
||
it('rejects invalid content types when gathering response content types', () => { | ||
const methodValue = {}; | ||
const examples = { '!!!': '' }; | ||
const contentTypes = parser.gatherResponseContentTypes(methodValue, examples); | ||
|
||
expect(contentTypes).to.deep.equal([null]); | ||
}); | ||
}); | ||
}); |