Skip to content

Commit

Permalink
Added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
turegjorup committed Oct 25, 2024
1 parent 73afcb8 commit 8b605c8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/Api/ScreensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@
use App\Entity\ScreenLayout;
use App\Entity\ScreenLayoutRegions;
use App\Entity\Tenant\Playlist;
use App\Entity\Tenant\PlaylistScreenRegion;
use App\Entity\Tenant\Screen;
use App\Entity\Tenant\ScreenGroup;
use App\Tests\AbstractBaseApiTestCase;
use Doctrine\ORM\EntityManager;

class ScreensTest extends AbstractBaseApiTestCase
{
private ?EntityManager $entityManager;

protected function setUp(): void
{
parent::setUp();

$kernel = self::bootKernel();

$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
}

public function testGetCollection(): void
{
$response = $this->getAuthenticatedClient('ROLE_ADMIN')->request('GET', '/v2/screens?itemsPerPage=5', ['headers' => ['Content-Type' => 'application/ld+json']]);
Expand Down Expand Up @@ -168,12 +183,21 @@ public function testCreateInvalidScreen(): void

public function testUpdateScreen(): void
{
$playlistScreenRegionRepository = $this->entityManager->getRepository(PlaylistScreenRegion::class);
$playlistScreenRegionCountBefore = $playlistScreenRegionRepository->count([]);

$playlistIri = $this->findIriBy(Playlist::class, ['title' => 'playlist_abc_3']);
$playlistUlid = $this->iriHelperUtils->getUlidFromIRI($playlistIri);
$regionIri = $this->findIriBy(ScreenLayoutRegions::class, ['title' => 'full']);
$regionUlid = $this->iriHelperUtils->getUlidFromIRI($regionIri);

$client = $this->getAuthenticatedClient('ROLE_ADMIN');
$iri = $this->findIriBy(Screen::class, ['tenant' => $this->tenant]);
$iri = $this->findIriBy(Screen::class, ['title' => 'screen_abc_1']);

$client->request('PUT', $iri, [
$response = $client->request('PUT', $iri, [
'json' => [
'title' => 'Updated title',
'regions' => [['playlists' => [['id' => $playlistUlid, 'weight' => 0]], 'regionId' => $regionUlid]],
],
'headers' => [
'Content-Type' => 'application/ld+json',
Expand All @@ -185,7 +209,10 @@ public function testUpdateScreen(): void
'@type' => 'Screen',
'@id' => $iri,
'title' => 'Updated title',
'regions' => ['/v2/screens/'.$response->toArray()['id'].'/regions/'.$regionUlid.'/playlists'],
]);
$playlistScreenRegionCountAfter = $playlistScreenRegionRepository->count([]);
$this->assertEquals($playlistScreenRegionCountBefore, $playlistScreenRegionCountAfter, 'PlaylistScreenRegion count should not change');
}

public function testDeleteScreen(): void
Expand Down

0 comments on commit 8b605c8

Please sign in to comment.