Skip to content

Commit

Permalink
Move non-Basic tests to their own folder [API-386]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Aug 11, 2023
1 parent 21bdd02 commit 6cf7c9c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 88 deletions.
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<testsuite name="Contract">
<directory suffix="Test.php">./tests/Contract</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<coverage>
<include>
Expand Down
73 changes: 0 additions & 73 deletions tests/Basic/ArtworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
namespace Tests\Basic;

use App\Models\Collections\Artwork;
use App\Models\Collections\ArtworkType;
use App\Models\Collections\Gallery;
use App\Models\Collections\AgentType;
use App\Models\Collections\Agent;

use Illuminate\Foundation\Testing\RefreshDatabase;

class ArtworkTest extends BasicTestCase
{
use RefreshDatabase;

protected $model = Artwork::class;

protected $keys = ['id'];
Expand All @@ -25,71 +19,4 @@ protected function setUp(): void
$agentType = $this->make(AgentType::class, ['title' => 'Individual']);
$agent = $this->make(Agent::class, ['agent_type_id' => $agentType->id]);
}

/** @test */
public function it_fetches_the_gallery_for_an_artwork(): void
{
$gallery = $this->make(Gallery::class, ['is_closed' => false]);
$galleryKey = $gallery->getAttributeValue($gallery->getKeyName());

$artwork = $this->make(Artwork::class, ['gallery_id' => $galleryKey, 'is_on_view' => true]);
$artworkKey = $artwork->getAttributeValue($artwork->getKeyName());

$response = $this->getJson('api/v1/artworks/' . $artworkKey);
$response->assertSuccessful();

$resource = $response->json()['data'];
$this->assertTrue($resource['is_on_view']);
}

/** @test */
public function it_fetches_artwork_linked_art_endpoint(): void
{
$artworkType = $this->make(ArtworkType::class, ['aat_id' => '300033618', 'title' => 'Painting']);
$artworkTypeKey = $artworkType->getAttributeValue($artworkType->getKeyName());

$artwork = $this->make(Artwork::class, ['artwork_type_id' => $artworkTypeKey]);
$artworkKey = $artwork->getAttributeValue($artwork->getKeyName());

$response = $this->getJson('la/v1/objects/' . $artworkKey);
$response->assertSuccessful();

$resource = $response->json();
$this->assertCount(1, $resource['classified_as']);
$this->assertEquals($resource['classified_as'][0]['id'], 'http://vocab.getty.edu/aat/300033618');
}

/** @test */
public function it_fetches_multiple_artwork_linked_art_endpoint(): void
{
$artwork1Type = $this->make(ArtworkType::class, ['aat_id' => '300033618', 'title' => 'Painting']);
$artwork1TypeKey = $artwork1Type->getAttributeValue($artwork1Type->getKeyName());

$artwork1 = $this->make(Artwork::class, ['artwork_type_id' => $artwork1TypeKey]);
$artwork1Key = $artwork1->getAttributeValue($artwork1->getKeyName());

$artwork2Type = $this->make(ArtworkType::class, ['aat_id' => '300193015', 'title' => 'Vessel']);
$artwork2TypeKey = $artwork2Type->getAttributeValue($artwork2Type->getKeyName());

$artwork2 = $this->make(Artwork::class, ['artwork_type_id' => $artwork2TypeKey]);
$artwork2Key = $artwork2->getAttributeValue($artwork2->getKeyName());

$response = $this->getJson('la/v1/objects?ids=' . $artwork1Key . ',' . $artwork2Key);
$response->assertSuccessful();

$resource = $response->json();
$this->assertCount(2, $resource['objects']);

$idsInResponse = array_merge(array_keys($resource['objects'][0]), array_keys($resource['objects'][1]));
$this->assertContains($artwork1Key, $idsInResponse, 'The works we added to the database are not in the repsonse');

$artwork1Response = array_pop($resource['objects'][0]);
$artwork2Response = array_pop($resource['objects'][1]);
$this->assertCount(1, $artwork1Response['classified_as'], 'The works do not include expected data');
$this->assertCount(1, $artwork2Response['classified_as'], 'The works do not include expected data');

$classifiedIdsInResponse = [$artwork1Response['classified_as'][0]['id'], $artwork2Response['classified_as'][0]['id']];
$this->assertContains('http://vocab.getty.edu/aat/300033618', $classifiedIdsInResponse);
$this->assertContains('http://vocab.getty.edu/aat/300193015', $classifiedIdsInResponse);
}
}
15 changes: 0 additions & 15 deletions tests/Basic/DigitalPublicationSectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,4 @@ class DigitalPublicationSectionTest extends BasicTestCase
protected $model = DigitalPublicationSection::class;

protected $route = 'digital-publication-sections';

/** @test */
public function it_inserts_long_text_in_the_copy_field(): void
{
$digitalPublictionSection = $this->make(DigitalPublicationSection::class, ['copy' => fake()->text(66000)]); // Longer than a `text` field
$digitalPublictionSectionKey = $digitalPublictionSection->getAttributeValue($digitalPublictionSection->getKeyName());

$response = $this->getJson('api/v1/digital-publication-sections/' . $digitalPublictionSectionKey);
$response->assertSuccessful();

$resource = $response->json()['data'];
$this->assertGreaterThan(65535, strlen($resource['copy']));

DigitalPublicationSection::query()->delete();
}
}
92 changes: 92 additions & 0 deletions tests/Unit/ArtworkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

use App\Models\Collections\Artwork;
use App\Models\Collections\ArtworkType;
use App\Models\Collections\Gallery;
use App\Models\Collections\AgentType;
use App\Models\Collections\Agent;

class ArtworkTest extends TestCase
{
use RefreshDatabase;

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

$agentType = $this->make(AgentType::class, ['title' => 'Individual']);
$agent = $this->make(Agent::class, ['agent_type_id' => $agentType->id]);
}

/** @test */
public function it_fetches_the_gallery_for_an_artwork(): void
{
$gallery = $this->make(Gallery::class, ['is_closed' => false]);
$galleryKey = $gallery->getAttributeValue($gallery->getKeyName());

$artwork = $this->make(Artwork::class, ['gallery_id' => $galleryKey, 'is_on_view' => true]);
$artworkKey = $artwork->getAttributeValue($artwork->getKeyName());

$response = $this->getJson('api/v1/artworks/' . $artworkKey);
$response->assertSuccessful();

$resource = $response->json()['data'];
$this->assertTrue($resource['is_on_view']);
}

/** @test */
public function it_fetches_artwork_linked_art_endpoint(): void
{
$artworkType = $this->make(ArtworkType::class, ['aat_id' => '300033618', 'title' => 'Painting']);
$artworkTypeKey = $artworkType->getAttributeValue($artworkType->getKeyName());

$artwork = $this->make(Artwork::class, ['artwork_type_id' => $artworkTypeKey]);
$artworkKey = $artwork->getAttributeValue($artwork->getKeyName());

$response = $this->getJson('la/v1/objects/' . $artworkKey);
$response->assertSuccessful();

$resource = $response->json();
$this->assertCount(1, $resource['classified_as']);
$this->assertEquals($resource['classified_as'][0]['id'], 'http://vocab.getty.edu/aat/300033618');
}

/** @test */
public function it_fetches_multiple_artwork_linked_art_endpoint(): void
{
$artwork1Type = $this->make(ArtworkType::class, ['aat_id' => '300033618', 'title' => 'Painting']);
$artwork1TypeKey = $artwork1Type->getAttributeValue($artwork1Type->getKeyName());

$artwork1 = $this->make(Artwork::class, ['artwork_type_id' => $artwork1TypeKey]);
$artwork1Key = $artwork1->getAttributeValue($artwork1->getKeyName());

$artwork2Type = $this->make(ArtworkType::class, ['aat_id' => '300193015', 'title' => 'Vessel']);
$artwork2TypeKey = $artwork2Type->getAttributeValue($artwork2Type->getKeyName());

$artwork2 = $this->make(Artwork::class, ['artwork_type_id' => $artwork2TypeKey]);
$artwork2Key = $artwork2->getAttributeValue($artwork2->getKeyName());

$response = $this->getJson('la/v1/objects?ids=' . $artwork1Key . ',' . $artwork2Key);
$response->assertSuccessful();

$resource = $response->json();
$this->assertCount(2, $resource['objects']);

$idsInResponse = array_merge(array_keys($resource['objects'][0]), array_keys($resource['objects'][1]));
$this->assertContains($artwork1Key, $idsInResponse, 'The works we added to the database are not in the repsonse');

$artwork1Response = array_pop($resource['objects'][0]);
$artwork2Response = array_pop($resource['objects'][1]);
$this->assertCount(1, $artwork1Response['classified_as'], 'The works do not include expected data');
$this->assertCount(1, $artwork2Response['classified_as'], 'The works do not include expected data');

$classifiedIdsInResponse = [$artwork1Response['classified_as'][0]['id'], $artwork2Response['classified_as'][0]['id']];
$this->assertContains('http://vocab.getty.edu/aat/300033618', $classifiedIdsInResponse);
$this->assertContains('http://vocab.getty.edu/aat/300193015', $classifiedIdsInResponse);
}
}
26 changes: 26 additions & 0 deletions tests/Unit/DigitalPublicationSectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

use App\Models\Web\DigitalPublicationSection;

class DigitalPublicationSectionTest extends TestCase
{
use RefreshDatabase;

/** @test */
public function it_inserts_long_text_in_the_copy_field(): void
{
$digitalPublictionSection = $this->make(DigitalPublicationSection::class, ['copy' => fake()->text(66000)]); // Longer than a `text` field
$digitalPublictionSectionKey = $digitalPublictionSection->getAttributeValue($digitalPublictionSection->getKeyName());

$response = $this->getJson('api/v1/digital-publication-sections/' . $digitalPublictionSectionKey);
$response->assertSuccessful();

$resource = $response->json()['data'];
$this->assertGreaterThan(65535, strlen($resource['copy']));
}
}

0 comments on commit 6cf7c9c

Please sign in to comment.