Allow artworks to have one primary category and extra secondaries.
Keep artwork_category as membership, store a deterministic primary_category_id, and let upload plus studio pick up to five additional same-type categories without changing canonical URLs.
This commit is contained in:
@@ -13,7 +13,6 @@ function createSearchDocumentContentType(string $name, int $sortOrder = 0): int
|
||||
'description' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'sort_order' => $sortOrder,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -48,14 +47,17 @@ it('indexes all attached categories and content types while preserving a primary
|
||||
$mattePaintingId = createSearchDocumentCategory($digitalArtId, 'Matte Painting', 20);
|
||||
|
||||
$artwork->categories()->sync([$mattePaintingId, $fantasyId]);
|
||||
$artwork->forceFill(['primary_category_id' => $fantasyId])->save();
|
||||
|
||||
$payload = $artwork->fresh(['categories.contentType'])->toSearchableArray();
|
||||
$payload = $artwork->fresh(['categories.contentType', 'primaryCategory.contentType'])->toSearchableArray();
|
||||
$fantasySlug = (string) DB::table('categories')->where('id', $fantasyId)->value('slug');
|
||||
$mattePaintingSlug = (string) DB::table('categories')->where('id', $mattePaintingId)->value('slug');
|
||||
$wallpapersSlug = (string) DB::table('content_types')->where('id', $wallpapersId)->value('slug');
|
||||
$digitalArtSlug = (string) DB::table('content_types')->where('id', $digitalArtId)->value('slug');
|
||||
|
||||
expect($payload['category'])->toBe($fantasySlug)
|
||||
->and($payload['primary_category_id'])->toBe($fantasyId)
|
||||
->and($payload['category_ids'])->toEqualCanonicalizing([$fantasyId, $mattePaintingId])
|
||||
->and($payload['content_type'])->toBe($wallpapersSlug)
|
||||
->and($payload['categories'])->toBe([$fantasySlug, $mattePaintingSlug])
|
||||
->and($payload['content_types'])->toBe([$wallpapersSlug, $digitalArtSlug]);
|
||||
|
||||
Reference in New Issue
Block a user