// - to first test all mistakes a developer might make, and assert that the
// error responses provide a good DX
// - to eventually result in a well-formed request that succeeds.
$url = Url::
fromRoute(sprintf('jsonapi.%s.collection.post',
static::
$resourceTypeName));
$request_options =
[];
$request_options[RequestOptions::HEADERS
]['Accept'
] = 'application/vnd.api+json';
$request_options = NestedArray::
mergeDeep($request_options,
$this->
getAuthenticationRequestOptions());
// DX: 405 when read-only mode is enabled.
$response =
$this->
request('POST',
$url,
$request_options);
$this->
assertResourceErrorResponse(405,
sprintf("JSON:API is configured to accept only read operations. Site administrators can configure this at %s.", Url::
fromUri('base:/admin/config/services/jsonapi'
)->
setAbsolute()->
toString(TRUE
)->
getGeneratedUrl()),
$url,
$response);
if ($this->resourceType->
isLocatable()) { $this->
assertSame(['GET'
],
$response->
getHeader('Allow'
));
} else { $this->
assertSame([''
],
$response->
getHeader('Allow'
));
} $this->
config('jsonapi.settings'
)->
set('read_only', FALSE
)->
save(TRUE
);
// DX: 415 when no Content-Type request header.
$response =
$this->
request('POST',
$url,
$request_options);
$this->
assertSame(415,
$response->
getStatusCode());