Refactor code for improved readability and consistency
- Removed unnecessary blank lines in various files to enhance code clarity. - Updated comments for consistency and clarity across multiple classes and methods. - Adjusted spacing in test files for better formatting and readability.
This commit is contained in:
@@ -14,11 +14,11 @@ beforeEach(function () {
|
||||
|
||||
function createCollection(array $attributes = []): Collection
|
||||
{
|
||||
$name = $attributes['name'] ?? 'Test Collection ' . Str::random(5);
|
||||
$name = $attributes['name'] ?? 'Test Collection '.Str::random(5);
|
||||
// Handle name translation if it's not an array
|
||||
$nameValue = is_array($name) ? $name : ['en' => $name];
|
||||
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
|
||||
|
||||
|
||||
return Collection::create(array_merge([
|
||||
'name' => $nameValue,
|
||||
'slug' => $slug,
|
||||
@@ -29,7 +29,8 @@ function createCollection(array $attributes = []): Collection
|
||||
|
||||
function createProductForCollection(array $attributes = []): Product
|
||||
{
|
||||
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5);
|
||||
$name = $attributes['name'] ?? 'Test Product '.Str::random(5);
|
||||
|
||||
return Product::create(array_merge([
|
||||
'name' => $name,
|
||||
'slug' => Str::slug($name),
|
||||
@@ -60,10 +61,10 @@ test('can list collections', function () {
|
||||
'id',
|
||||
'name',
|
||||
'slug',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
$this->assertCount(3, $response->json('data'));
|
||||
});
|
||||
|
||||
@@ -86,7 +87,7 @@ test('does not list invisible collections', function () {
|
||||
|
||||
test('can list paginated collections', function () {
|
||||
// Arrange
|
||||
$collections = collect(range(1, 10))->map(fn() => createCollection());
|
||||
$collections = collect(range(1, 10))->map(fn () => createCollection());
|
||||
|
||||
// Act
|
||||
$response = $this->withHeaders([
|
||||
@@ -99,7 +100,7 @@ test('can list paginated collections', function () {
|
||||
->assertJsonStructure([
|
||||
'data',
|
||||
]);
|
||||
|
||||
|
||||
$this->assertCount(5, $response->json('data'));
|
||||
});
|
||||
|
||||
@@ -119,7 +120,7 @@ test('can show a specific collection', function () {
|
||||
'data' => [
|
||||
'id' => $collection->id,
|
||||
'name' => 'Test Collection',
|
||||
]
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -148,8 +149,8 @@ test('returns 404 for invalid collection id format', function () {
|
||||
test('can list products for a collection', function () {
|
||||
// Arrange
|
||||
$collection = createCollection();
|
||||
$products = collect(range(1, 5))->map(fn() => createProductForCollection());
|
||||
|
||||
$products = collect(range(1, 5))->map(fn () => createProductForCollection());
|
||||
|
||||
// Attach products to collection
|
||||
$collection->products()->attach($products->pluck('id'));
|
||||
|
||||
@@ -166,10 +167,10 @@ test('can list products for a collection', function () {
|
||||
'*' => [
|
||||
'id',
|
||||
'name',
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
$this->assertCount(5, $response->json('data'));
|
||||
});
|
||||
|
||||
@@ -178,7 +179,7 @@ test('does not list invisible products for a collection', function () {
|
||||
$collection = createCollection();
|
||||
$visibleProduct = createProductForCollection(['is_visible' => true]);
|
||||
$invisibleProduct = createProductForCollection(['is_visible' => false]);
|
||||
|
||||
|
||||
// Attach products to collection
|
||||
$collection->products()->attach([$visibleProduct->id, $invisibleProduct->id]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user