Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/Documents/CreateDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,54 @@ public function test_document_created_with_new_format(): void
$body['data']['type'] === 'doc';
});
}

public function test_adding_empty_document_raise_error(): void
{
$mockClient = MockClient::global([
CreateDocumentRequest::class => MockResponse::fixture('documents-create-empty'),
]);

$connector = $this->connector($mockClient);

$documentContent = [
'type' => 'doc',
'content' => [
[
'category' => 'page',
'attributes' => [
'page' => 1,
],
'content' => [
[
'role' => 'body',
'text' => '',
'marks' => [],
'attributes' => [
'bounding_box' => [],
],
],
],
],
],
];

$data = new Document('test-empty-id', 'en', $documentContent);

$this->expectException(UnprocessableEntityException::class);

$connector->documents('localhost')->create($data);

$mockClient->assertSent(CreateDocumentRequest::class);

$mockClient->assertSentCount(1);

$mockClient->assertSent(function (Request $request) {
$body = $request->body()->all();

return $request->resolveEndpoint() === '/library/localhost/documents' &&
$body['id'] === 'test-empty-id' &&
$body['lang'] === 'en' &&
$body['data']['type'] === 'doc';
});
}
}
7 changes: 7 additions & 0 deletions tests/Fixtures/Saloon/documents-create-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"statusCode": 422,
"headers": {
"content-type": "application\/json"
},
"data": "{\"detail\":\"The given document is empty\"}"
}