mirror of
https://github.com/flarum/core.git
synced 2025-08-04 15:37:51 +02:00
Rename API tests for more consistency
I could not come up with a noun for the new "UpdateTest" for users, so this is easier in terms of consistency.
This commit is contained in:
115
tests/integration/api/groups/CreateTest.php
Normal file
115
tests/integration/api/groups/CreateTest.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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\Tests\integration\api\groups;
|
||||
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->prepareDatabase([
|
||||
'users' => [
|
||||
$this->adminUser(),
|
||||
$this->normalUser(),
|
||||
],
|
||||
'groups' => [
|
||||
$this->adminGroup(),
|
||||
],
|
||||
'group_user' => [
|
||||
['user_id' => 1, 'group_id' => 1],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function admin_cannot_create_group_without_data()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/groups', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(422, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function admin_can_create_group()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/groups', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'data' => [
|
||||
'attributes' => [
|
||||
'nameSingular' => 'flarumite',
|
||||
'namePlural' => 'flarumites',
|
||||
'icon' => 'test',
|
||||
'color' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
// Verify API response body
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$this->assertEquals('flarumite', Arr::get($data, 'data.attributes.nameSingular'));
|
||||
$this->assertEquals('flarumites', Arr::get($data, 'data.attributes.namePlural'));
|
||||
$this->assertEquals('test', Arr::get($data, 'data.attributes.icon'));
|
||||
$this->assertNull(Arr::get($data, 'data.attributes.color'));
|
||||
|
||||
// Verify database entry
|
||||
$group = Group::where('icon', 'test')->firstOrFail();
|
||||
$this->assertEquals('flarumite', $group->name_singular);
|
||||
$this->assertEquals('flarumites', $group->name_plural);
|
||||
$this->assertEquals('test', $group->icon);
|
||||
$this->assertNull($group->color);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function normal_user_cannot_create_group()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/groups', [
|
||||
'authenticatedAs' => 2,
|
||||
'json' => [
|
||||
'data' => [
|
||||
'attributes' => [
|
||||
'nameSingular' => 'flarumite',
|
||||
'namePlural' => 'flarumites',
|
||||
'icon' => 'test',
|
||||
'color' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user