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:
@@ -1,20 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use App\Models\Ecommerce\Product\Favorite\Favorite;
|
||||
use App\Models\User;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create([
|
||||
'password' => 'password',
|
||||
'phone_number' => 61929248,
|
||||
]);
|
||||
|
||||
|
||||
// Helper to create product
|
||||
$this->createProduct = function () {
|
||||
return Product::create([
|
||||
'name' => 'Test Product',
|
||||
'slug' => 'test-product-' . uniqid(),
|
||||
'slug' => 'test-product-'.uniqid(),
|
||||
'stock' => 10,
|
||||
'price_amount' => 100,
|
||||
'is_visible' => true,
|
||||
@@ -43,43 +42,43 @@ test('authenticated user can add item to favorites', function () {
|
||||
$response = $this->actingAs($this->user, 'sanctum')
|
||||
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
|
||||
->postJson('/api/v1/favorites', [
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson([
|
||||
'message' => 'Added'
|
||||
'message' => 'Added',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('favorites', [
|
||||
'user_id' => $this->user->id,
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('authenticated user can remove item from favorites (toggle)', function () {
|
||||
$product = ($this->createProduct)();
|
||||
|
||||
|
||||
// Add first
|
||||
$this->user->favorites()->create([
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
|
||||
// Request to toggle (remove)
|
||||
$response = $this->actingAs($this->user, 'sanctum')
|
||||
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
|
||||
->postJson('/api/v1/favorites', [
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson([
|
||||
'message' => 'Removed'
|
||||
'message' => 'Removed',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('favorites', [
|
||||
'user_id' => $this->user->id,
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -87,7 +86,7 @@ test('favorite toggle validation fails if product does not exist', function () {
|
||||
$response = $this->actingAs($this->user, 'sanctum')
|
||||
->withHeaders(['Api-Token' => config('ecommerce.api.token')])
|
||||
->postJson('/api/v1/favorites', [
|
||||
'product_id' => 99999
|
||||
'product_id' => 99999,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
@@ -116,8 +115,8 @@ test('authenticated user can view favorites list with items', function () {
|
||||
'name',
|
||||
'slug',
|
||||
// Add other product fields as expected by ProductResource
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user