File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1+ {
2+ "statusCode" : 422 ,
3+ "headers" : {
4+ "content-type" : " application\/ json"
5+ },
6+ "data" : " {\" detail\" :\" The given document is empty\" }"
7+ }
You can’t perform that action at this time.
0 commit comments