2022-01-14 17:43:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-01-27 09:30:00 +01:00
|
|
|
namespace App\Test\TestCase\Api\Broods;
|
2022-01-14 17:43:53 +01:00
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\OrganisationsFixture;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
|
|
|
|
|
|
|
class AddBroodApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/broods/add';
|
2022-01-14 17:43:53 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
|
|
|
'app.Organisations',
|
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys',
|
|
|
|
'app.Broods'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testAddBrood(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'name' => 'Brood A',
|
|
|
|
'url' => $faker->url,
|
|
|
|
'description' => $faker->text,
|
|
|
|
'organisation_id' => OrganisationsFixture::ORGANISATION_A_ID,
|
|
|
|
'trusted' => true,
|
|
|
|
'pull' => true,
|
|
|
|
'skip_proxy' => true,
|
|
|
|
'authkey' => $faker->sha1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseOk();
|
|
|
|
$this->assertResponseContains(sprintf('"uuid": "%s"', $uuid));
|
|
|
|
$this->assertDbRecordExists('Broods', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddBroodNotAllowedAsRegularUser(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'name' => 'Brood A',
|
|
|
|
'url' => $faker->url,
|
|
|
|
'description' => $faker->text,
|
|
|
|
'organisation_id' => OrganisationsFixture::ORGANISATION_A_ID,
|
|
|
|
'trusted' => true,
|
|
|
|
'pull' => true,
|
|
|
|
'skip_proxy' => true,
|
|
|
|
'authkey' => $faker->sha1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseCode(405);
|
|
|
|
$this->assertDbRecordNotExists('Broods', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
}
|