Skip to content

Commit

Permalink
chore: move tests to mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Oct 7, 2024
1 parent 35d2be1 commit 4c89945
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 91 deletions.
104 changes: 104 additions & 0 deletions extensions/mentions/tests/integration/api/CreateDiscussionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Mentions\Tests\integration\api;

use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Testing\integration\TestCase;
use Illuminate\Support\Arr;

class CreateDiscussionTest extends TestCase
{
/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();

$this->extension('flarum-mentions');

$this->extend(
(new Extend\Event())
->listen(\Flarum\Post\Event\Saving::class, function ($event) {
$event->post->content;
})
);
}

/**
* @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));
}
}
91 changes: 0 additions & 91 deletions framework/core/tests/integration/api/discussions/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,97 +69,6 @@ public function cannot_create_discussion_without_content()
], json_decode($body, true));
}

/**
* @test
*/
public function cannot_create_discussion_without_content_property()
{
$this->extend(
(new Extend\Formatter)
->unparse(function ($context, string $content) {
return $content;
}),
(new Extend\Event())
->listen(\Flarum\Post\Event\Saving::class, function ($event) {
$event->post->content;
})
);

$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()
{
$this->extend(
(new Extend\Formatter)
->unparse(function ($context, string $content) {
return $content;
}),
(new Extend\Event())
->listen(\Flarum\Post\Event\Saving::class, function ($event) {
$event->post->content;
})
);

$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
*/
Expand Down

0 comments on commit 4c89945

Please sign in to comment.