2022-01-10 16:19:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-01-27 09:30:00 +01:00
|
|
|
namespace App\Test\TestCase\Api\Organisations;
|
2022-01-10 16:19:58 +01:00
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
|
|
|
|
|
|
|
class AddOrganisationApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/organisations/add';
|
2022-01-10 16:19:58 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
|
|
|
'app.Organisations',
|
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testAddOrganisation(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'name' => 'Test Organisation',
|
|
|
|
'description' => $faker->text,
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'url' => 'http://example.com',
|
|
|
|
'nationality' => 'US',
|
|
|
|
'sector' => 'sector',
|
|
|
|
'type' => 'type',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseOk();
|
|
|
|
$this->assertResponseContains(sprintf('"uuid": "%s"', $uuid));
|
|
|
|
$this->assertDbRecordExists('Organisations', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
|
2022-01-11 17:17:04 +01:00
|
|
|
public function testAddOrganisationNotAllowedAsRegularUser(): void
|
2022-01-10 16:19:58 +01:00
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'name' => 'Test Organisation',
|
|
|
|
'description' => $faker->text,
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'url' => 'http://example.com',
|
|
|
|
'nationality' => 'US',
|
|
|
|
'sector' => 'sector',
|
|
|
|
'type' => 'type',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseCode(405);
|
|
|
|
$this->assertDbRecordNotExists('Organisations', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
}
|