-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "REST: Test supported media types in edit routes"
- Loading branch information
Showing
12 changed files
with
47 additions
and
226 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
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
47 changes: 47 additions & 0 deletions
47
repo/rest-api/tests/mocha/api-testing/SupportedMediaTypeTest.js
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,47 @@ | ||
'use strict'; | ||
|
||
const { expect } = require( '../helpers/chaiHelper' ); | ||
const { | ||
getItemEditRequests, | ||
getPropertyEditRequests, | ||
getItemCreateRequest | ||
} = require( '../helpers/happyPathRequestBuilders' ); | ||
const { describeWithTestData } = require( '../helpers/describeWithTestData' ); | ||
|
||
describeWithTestData( | ||
'supported media type requests', | ||
( itemRequestInputs, propertyRequestInputs, describeEachRouteWithReset ) => { | ||
const requestsToTest = [ | ||
...getItemEditRequests( itemRequestInputs ), | ||
...getPropertyEditRequests( propertyRequestInputs ), | ||
getItemCreateRequest( itemRequestInputs ) | ||
]; | ||
describeEachRouteWithReset( requestsToTest, ( newRequestBuilder ) => { | ||
// We implicitly check that edit routes support application/json | ||
// So no need to add additional test for it. | ||
|
||
// Accept DELETE endpoints with no content-type | ||
if ( newRequestBuilder().getMethod() === 'DELETE' ) { | ||
it( `${newRequestBuilder().getRouteDescription()} responds OK with no content type`, | ||
async () => { | ||
const response = await newRequestBuilder().assertValidRequest().makeRequest(); | ||
expect( response.status ).to.be.within( 200, 299 ); | ||
} | ||
); | ||
} | ||
|
||
// Accept 'application/json-patch+json' content-type for PATCH endpoints | ||
if ( newRequestBuilder().getMethod() === 'PATCH' ) { | ||
it( `${newRequestBuilder().getRouteDescription()} responds OK for application/json-patch+json`, async () => { | ||
const contentType = 'application/json-patch+json'; | ||
const response = await newRequestBuilder() | ||
.withHeader( 'content-type', contentType ) | ||
.assertValidRequest() | ||
.makeRequest(); | ||
|
||
expect( response.status ).to.be.within( 200, 299 ); | ||
} ); | ||
} | ||
} ); | ||
} | ||
); |