Skip to content

Commit 887c94e

Browse files
authored
Treat adding an empty document as an error (#12)
1 parent 92287f6 commit 887c94e

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

tests/Documents/CreateDocumentTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,54 @@ public function test_document_created_with_new_format(): void
166166
$body['data']['type'] === 'doc';
167167
});
168168
}
169+
170+
public function test_adding_empty_document_raise_error(): void
171+
{
172+
$mockClient = MockClient::global([
173+
CreateDocumentRequest::class => MockResponse::fixture('documents-create-empty'),
174+
]);
175+
176+
$connector = $this->connector($mockClient);
177+
178+
$documentContent = [
179+
'type' => 'doc',
180+
'content' => [
181+
[
182+
'category' => 'page',
183+
'attributes' => [
184+
'page' => 1,
185+
],
186+
'content' => [
187+
[
188+
'role' => 'body',
189+
'text' => '',
190+
'marks' => [],
191+
'attributes' => [
192+
'bounding_box' => [],
193+
],
194+
],
195+
],
196+
],
197+
],
198+
];
199+
200+
$data = new Document('test-empty-id', 'en', $documentContent);
201+
202+
$this->expectException(UnprocessableEntityException::class);
203+
204+
$connector->documents('localhost')->create($data);
205+
206+
$mockClient->assertSent(CreateDocumentRequest::class);
207+
208+
$mockClient->assertSentCount(1);
209+
210+
$mockClient->assertSent(function (Request $request) {
211+
$body = $request->body()->all();
212+
213+
return $request->resolveEndpoint() === '/library/localhost/documents' &&
214+
$body['id'] === 'test-empty-id' &&
215+
$body['lang'] === 'en' &&
216+
$body['data']['type'] === 'doc';
217+
});
218+
}
169219
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"statusCode": 422,
3+
"headers": {
4+
"content-type": "application\/json"
5+
},
6+
"data": "{\"detail\":\"The given document is empty\"}"
7+
}

0 commit comments

Comments
 (0)