From 3ea9f976903b62c9131980ae799c85168cb516d1 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Mon, 7 Oct 2024 12:41:17 +0200 Subject: [PATCH] test(core): implement test for empty content --- .../api/discussions/CreateTest.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/framework/core/tests/integration/api/discussions/CreateTest.php b/framework/core/tests/integration/api/discussions/CreateTest.php index d306bc99b5..a8a03e7d28 100644 --- a/framework/core/tests/integration/api/discussions/CreateTest.php +++ b/framework/core/tests/integration/api/discussions/CreateTest.php @@ -68,6 +68,75 @@ public function cannot_create_discussion_without_content() ], json_decode($body, true)); } + /** + * @test + */ + public function cannot_create_discussion_without_content_property() + { + $response = $this->send( + $this->request('POST', '/api/discussions', [ + 'authenticatedAs' => 1, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'title' => 'Test post', + ], + ], + ], + ]) + ); + + $this->assertEquals(422, $response->getStatusCode()); + + $body = (string) $response->getBody(); + $this->assertJson($body); + $this->assertEquals([ + 'errors' => [ + [ + 'status' => '422', + 'code' => 'validation_error', + 'detail' => 'The content field is required.', + 'source' => ['pointer' => '/data/attributes/content'], + ], + ], + ], json_decode($body, true)); + } + + /** + * @test + */ + public function cannot_create_discussion_with_content_set_to_null() + { + $response = $this->send( + $this->request('POST', '/api/discussions', [ + 'authenticatedAs' => 1, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'title' => 'Test post', + 'content' => null, + ], + ], + ], + ]) + ); + + $this->assertEquals(422, $response->getStatusCode()); + + $body = (string) $response->getBody(); + $this->assertJson($body); + $this->assertEquals([ + 'errors' => [ + [ + 'status' => '422', + 'code' => 'validation_error', + 'detail' => 'The content field is required.', + 'source' => ['pointer' => '/data/attributes/content'], + ], + ], + ], json_decode($body, true)); + } + /** * @test */