87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Artwork;
|
|
use App\Models\Category;
|
|
use App\Models\ContentType;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
class BrowseApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_api_browse_returns_public_artworks(): void
|
|
{
|
|
$user = User::factory()->create(['name' => 'Author One']);
|
|
$contentType = ContentType::create([
|
|
'name' => 'Wallpapers',
|
|
'slug' => 'wallpapers',
|
|
'description' => 'Wallpapers content type',
|
|
]);
|
|
|
|
$category = Category::create([
|
|
'content_type_id' => $contentType->id,
|
|
'name' => 'Abstract',
|
|
'slug' => 'abstract',
|
|
'description' => 'Abstract wallpapers',
|
|
'is_active' => true,
|
|
'sort_order' => 1,
|
|
]);
|
|
|
|
$artwork = Artwork::factory()
|
|
->for($user)
|
|
->create([
|
|
'slug' => 'neon-city',
|
|
'published_at' => now()->subDay(),
|
|
]);
|
|
|
|
$artwork->categories()->attach($category->id);
|
|
|
|
$response = $this->getJson('/api/v1/browse');
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.0.slug', 'neon-city')
|
|
->assertJsonPath('data.0.category.slug', 'abstract')
|
|
->assertJsonPath('data.0.author.name', 'Author One');
|
|
}
|
|
|
|
public function test_web_browse_shows_artworks(): void
|
|
{
|
|
$user = User::factory()->create(['name' => 'Author Two']);
|
|
$contentType = ContentType::create([
|
|
'name' => 'Photography',
|
|
'slug' => 'photography',
|
|
'description' => 'Photos',
|
|
]);
|
|
|
|
$category = Category::create([
|
|
'content_type_id' => $contentType->id,
|
|
'name' => 'Nature',
|
|
'slug' => 'nature',
|
|
'description' => 'Nature photos',
|
|
'is_active' => true,
|
|
'sort_order' => 1,
|
|
]);
|
|
|
|
$artwork = Artwork::factory()
|
|
->for($user)
|
|
->create([
|
|
'title' => 'Forest Light',
|
|
'slug' => 'forest-light',
|
|
'published_at' => now()->subDay(),
|
|
]);
|
|
|
|
$artwork->categories()->attach($category->id);
|
|
|
|
$response = $this->get('/browse');
|
|
|
|
$response->assertOk();
|
|
$response->assertSee('Forest Light');
|
|
$response->assertSee('Author Two');
|
|
}
|
|
}
|