-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { findResponseContent, ContentType } from '../src/middlewares/util'; | ||
import { expect } from 'chai'; | ||
|
||
describe('contentType', () => { | ||
it('should match wildcard type */*', async () => { | ||
const expectedTypes = ['application/json', 'application/xml']; | ||
const accepts = ['*/*']; | ||
|
||
const contentType = findResponseContent(accepts, expectedTypes); | ||
expect(contentType).to.equal(expectedTypes[0]); | ||
}); | ||
|
||
it('should match wildcard type application/*', async () => { | ||
const expectedTypes = ['application/json', 'application/xml']; | ||
const accepts = ['application/*']; | ||
|
||
const contentType = findResponseContent(accepts, expectedTypes); | ||
expect(contentType).to.equal(expectedTypes[0]); | ||
}); | ||
|
||
it('should null if no accept specified', async () => { | ||
const expectedTypes = ['application/json', 'application/xml']; | ||
const accepts = []; | ||
|
||
const contentType = findResponseContent(accepts, expectedTypes); | ||
expect(contentType).to.equal(null); | ||
}); | ||
|
||
it('should match media type if charset is not specified in accepts', async () => { | ||
const expectedTypes = [ | ||
'application/json; charset=utf-8', | ||
'application/xml', | ||
]; | ||
const accepts = ['application/json']; | ||
|
||
const contentType = findResponseContent(accepts, expectedTypes); | ||
expect(contentType).to.equal(expectedTypes[0]); | ||
}); | ||
|
||
it('should match media type if charset is specified in accepts, but charset not defined in schema', async () => { | ||
const expectedTypes = [ | ||
'application/json', | ||
'application/xml', | ||
]; | ||
const accepts = ['application/json; charset=utf-8']; | ||
|
||
const contentType = findResponseContent(accepts, expectedTypes); | ||
expect(contentType).to.equal(expectedTypes[0]); | ||
}); | ||
}); |
Oops, something went wrong.