86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Test\TestCase\Api\Users;
|
||
|
|
||
|
use Cake\TestSuite\IntegrationTestTrait;
|
||
|
use Cake\TestSuite\TestCase;
|
||
|
use App\Test\Fixture\AuthKeysFixture;
|
||
|
use App\Test\Helper\ApiTestTrait;
|
||
|
|
||
|
class AddOrganisationApiTest extends TestCase
|
||
|
{
|
||
|
use IntegrationTestTrait;
|
||
|
use ApiTestTrait;
|
||
|
|
||
|
protected const ENDPOINT = '/api/v1/organisations/add';
|
||
|
|
||
|
protected $fixtures = [
|
||
|
'app.Organisations',
|
||
|
'app.Individuals',
|
||
|
'app.Roles',
|
||
|
'app.Users',
|
||
|
'app.AuthKeys'
|
||
|
];
|
||
|
|
||
|
public function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->initializeValidator(APP . '../webroot/docs/openapi.yaml');
|
||
|
}
|
||
|
|
||
|
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]);
|
||
|
//TODO: $this->assertRequestMatchesOpenApiSpec();
|
||
|
$this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post');
|
||
|
}
|
||
|
|
||
|
public function testAddOrganisationNotAllowedToRegularUser(): void
|
||
|
{
|
||
|
$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]);
|
||
|
//TODO: $this->assertRequestMatchesOpenApiSpec();
|
||
|
$this->assertResponseMatchesOpenApiSpec(self::ENDPOINT, 'post');
|
||
|
}
|
||
|
}
|