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:
Mekan1206
2026-02-08 02:24:43 +05:00
parent 2dfa3747b5
commit c46eccb24f
38 changed files with 257 additions and 257 deletions

View File

@@ -38,7 +38,7 @@ class OrderController extends Controller
*/ */
public function store(CheckoutOrderRequest $request, CreateOrderService $service): JsonResponse public function store(CheckoutOrderRequest $request, CreateOrderService $service): JsonResponse
{ {
$order = $service->execute(auth()->user(), $request->validated()); $order = $service->execute(auth()->user(), $request->all());
$url = null; $url = null;
if ($request->payment_type_id == 3) { if ($request->payment_type_id == 3) {
@@ -81,7 +81,6 @@ class OrderController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
* @param Order $order
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function destroy(Order $order) public function destroy(Order $order)

View File

@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Api\V1\Product\Resources;
use App\Http\Resources\MediaResource; use App\Http\Resources\MediaResource;
use App\Repositories\Ecommerce\Product\Property\PropertyRepository; use App\Repositories\Ecommerce\Product\Property\PropertyRepository;
use App\Http\Controllers\Api\V1\Product\Resources\Variant\ProductVariantResource;
use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\JsonResource;
class ProductIndexResource extends JsonResource class ProductIndexResource extends JsonResource

View File

@@ -2,7 +2,6 @@
namespace App\Http\Requests\Api\V1\Auth; namespace App\Http\Requests\Api\V1\Auth;
use App\Rules\VerificationRule;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;

View File

@@ -27,16 +27,16 @@ class Product extends Model implements HasMedia, Viewable
*/ */
use HasFactory; use HasFactory;
/**
* Has Schemaless Attributes (spatie/laravel-schemaless-attributes)
*/
use HasSchemalessAttributes;
/** /**
* Has Properties Json * Has Properties Json
*/ */
use HasPropertiesJson; use HasPropertiesJson;
/**
* Has Schemaless Attributes (spatie/laravel-schemaless-attributes)
*/
use HasSchemalessAttributes;
/** /**
* Has Slug (spatie/laravel-sluggable) * Has Slug (spatie/laravel-sluggable)
*/ */

View File

@@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id * @property int $id
* @property string $version * @property string $version
* @property string $os * @property string $os
* @property bool $important * @property bool $important
* @property string $notes * @property string $notes
* @property \Carbon\Carbon|null $created_at * @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at * @property \Carbon\Carbon|null $updated_at

View File

@@ -38,7 +38,6 @@ class Warning extends Resource
/** /**
* Get the fields displayed by the resource. * Get the fields displayed by the resource.
* *
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array * @return array
*/ */
public function fields(NovaRequest $request) public function fields(NovaRequest $request)
@@ -68,7 +67,6 @@ class Warning extends Resource
/** /**
* Get the cards available for the request. * Get the cards available for the request.
* *
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array * @return array
*/ */
public function cards(NovaRequest $request) public function cards(NovaRequest $request)
@@ -79,7 +77,6 @@ class Warning extends Resource
/** /**
* Get the filters available for the resource. * Get the filters available for the resource.
* *
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array * @return array
*/ */
public function filters(NovaRequest $request) public function filters(NovaRequest $request)
@@ -90,7 +87,6 @@ class Warning extends Resource
/** /**
* Get the lenses available for the resource. * Get the lenses available for the resource.
* *
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array * @return array
*/ */
public function lenses(NovaRequest $request) public function lenses(NovaRequest $request)
@@ -101,7 +97,6 @@ class Warning extends Resource
/** /**
* Get the actions available for the resource. * Get the actions available for the resource.
* *
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array * @return array
*/ */
public function actions(NovaRequest $request) public function actions(NovaRequest $request)

View File

@@ -2,11 +2,11 @@
namespace App\Providers; namespace App\Providers;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\ServiceProvider;
use Dedoc\Scramble\Scramble; use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi; use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityRequirement; use Dedoc\Scramble\Support\Generator\SecurityRequirement;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\ServiceProvider;
class DocumentationServiceProvider extends ServiceProvider class DocumentationServiceProvider extends ServiceProvider
{ {
@@ -24,14 +24,14 @@ class DocumentationServiceProvider extends ServiceProvider
public function boot(): void public function boot(): void
{ {
Scramble::configure() Scramble::configure()
->withDocumentTransformers(function (OpenApi $openApi) { ->withDocumentTransformers(function (OpenApi $openApi) {
$openApi->components->securitySchemes['api-token'] = SecurityScheme::apiKey('header', 'Api-token'); $openApi->components->securitySchemes['api-token'] = SecurityScheme::apiKey('header', 'Api-token');
$openApi->components->securitySchemes['bearer'] = SecurityScheme::http('bearer'); $openApi->components->securitySchemes['bearer'] = SecurityScheme::http('bearer');
$openApi->security[] = new SecurityRequirement([ $openApi->security[] = new SecurityRequirement([
'api-token' => [], 'api-token' => [],
'bearer' => [], 'bearer' => [],
]); ]);
}); });
} }
} }

View File

@@ -59,7 +59,7 @@ class ProductRepository
/** /**
* Update query builder with resource relationship * Update query builder with resource relationship
* *
* @param mixed $resource * @param mixed $resource
*/ */
public function queryAsFromResource($resource): self public function queryAsFromResource($resource): self
{ {
@@ -278,7 +278,7 @@ class ProductRepository
/** /**
* Ajax paginate * Ajax paginate
* *
* @param mixed $products * @param mixed $products
*/ */
public static function ajaxPaginate($products): JsonResponse public static function ajaxPaginate($products): JsonResponse
{ {

View File

@@ -13,15 +13,12 @@ class CreateOrderService
{ {
/** /**
* Create a new order for the user * Create a new order for the user
*
* @param User $user
* @param array $data
* @return Order
*/ */
public function execute(User $user, array $data): Order public function execute(User $user, array $data): Order
{ {
return DB::transaction(function () use ($user, $data) { return DB::transaction(function () use ($user, $data) {
// 1. Create the order // 1. Create the order
info(['service' => $data]);
$order = Order::create($data); $order = Order::create($data);
// 2. Process Cart Items // 2. Process Cart Items

View File

@@ -13,6 +13,9 @@ return new class extends Migration
{ {
Schema::table('orders', function (Blueprint $table) { Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('source_app'); $table->dropColumn('source_app');
});
Schema::table('orders', function (Blueprint $table) {
$table->string('source')->nullable(); $table->string('source')->nullable();
}); });
} }
@@ -26,6 +29,9 @@ return new class extends Migration
if (Schema::hasColumn('source')) { if (Schema::hasColumn('source')) {
$table->dropColumn('source')->nullable(); $table->dropColumn('source')->nullable();
} }
});
Schema::table('orders', function (Blueprint $table) {
if (! Schema::hasColumn('source_app')) { if (! Schema::hasColumn('source_app')) {
$table->string('source_app')->nullable(); $table->string('source_app')->nullable();
} }

View File

@@ -15,29 +15,29 @@ class DatabaseSeeder extends Seeder
public function run(): void public function run(): void
{ {
// $this->call([ // $this->call([
// SettingsSeeder::class, // SettingsSeeder::class,
// RolesTableSeeder::class, // RolesTableSeeder::class,
// BannerTableSeeder::class, // BannerTableSeeder::class,
// CarouselTableSeeder::class, // CarouselTableSeeder::class,
// UserTableSeeder::class, // UserTableSeeder::class,
// ChannelTableSeeder::class, // ChannelTableSeeder::class,
// PaymentTypeTableSeeder::class, // PaymentTypeTableSeeder::class,
// ProvinceTableSeeder::class, // ProvinceTableSeeder::class,
// BrandTableSeeder::class, // BrandTableSeeder::class,
// ProductTableSeeder::class, // ProductTableSeeder::class,
// PostBranchTableSeeder::class, // PostBranchTableSeeder::class,
// InventoriesTableSeeder::class, // InventoriesTableSeeder::class,
// CategoryTableSeeder::class, // CategoryTableSeeder::class,
// CollectionTableSeeder::class, // CollectionTableSeeder::class,
// AttributeTableSeeder::class, // AttributeTableSeeder::class,
// ContactUsTableSeeder::class, // ContactUsTableSeeder::class,
// LegalPageTableSeeder::class, // LegalPageTableSeeder::class,
// ReviewTableSeeder::class, // ReviewTableSeeder::class,
// NewsletterTableSeeder::class, // NewsletterTableSeeder::class,
// CartItemTableSeeder::class, // CartItemTableSeeder::class,
// FavouriteTableSeeder::class, // FavouriteTableSeeder::class,
// MediaTableSeeder::class, // MediaTableSeeder::class,
// ProductHasRelationsTable::class, // ProductHasRelationsTable::class,
// ]); // ]);
$this->call([ $this->call([

View File

@@ -26,7 +26,6 @@ use App\Http\Controllers\Api\V1\Profile\ProfileController;
use App\Http\Controllers\Api\V1\Province\ProvinceController; use App\Http\Controllers\Api\V1\Province\ProvinceController;
use App\Http\Controllers\Api\V1\ReviewController; use App\Http\Controllers\Api\V1\ReviewController;
use App\Modules\GlobalOrder\Controllers\GlobalOrderController; use App\Modules\GlobalOrder\Controllers\GlobalOrderController;
use Dedoc\Scramble\Attributes\HeaderParameter;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
// Auth... // Auth...

View File

@@ -1,8 +1,8 @@
<?php <?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Cart\CartItem; use App\Models\Ecommerce\Product\Cart\CartItem;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\User;
beforeEach(function () { beforeEach(function () {
$this->user = User::factory()->create([ $this->user = User::factory()->create([
@@ -20,7 +20,7 @@ beforeEach(function () {
return Product::create([ return Product::create([
'name' => 'Test Product', 'name' => 'Test Product',
'slug' => 'test-product-' . uniqid(), 'slug' => 'test-product-'.uniqid(),
'stock' => $stock, 'stock' => $stock,
'price_amount' => 100, 'price_amount' => 100,
'is_visible' => true, 'is_visible' => true,
@@ -50,7 +50,7 @@ test('authenticated user can store item in cart', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [ ->postJson('/api/v1/carts', [
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 2 'product_quantity' => 2,
]); ]);
$response->assertStatus(201); $response->assertStatus(201);
@@ -58,7 +58,7 @@ test('authenticated user can store item in cart', function () {
$this->assertDatabaseHas('cart_items', [ $this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 2 'product_quantity' => 2,
]); ]);
}); });
@@ -69,7 +69,7 @@ test('storing item updates quantity if already in cart', function () {
CartItem::create([ CartItem::create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 1 'product_quantity' => 1,
]); ]);
// Update quantity // Update quantity
@@ -77,7 +77,7 @@ test('storing item updates quantity if already in cart', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [ ->postJson('/api/v1/carts', [
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 5 'product_quantity' => 5,
]); ]);
$response->assertStatus(201); $response->assertStatus(201);
@@ -85,7 +85,7 @@ test('storing item updates quantity if already in cart', function () {
$this->assertDatabaseHas('cart_items', [ $this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 5 // Should update to new quantity, not add 'product_quantity' => 5, // Should update to new quantity, not add
]); ]);
}); });
@@ -94,7 +94,7 @@ test('cart validation fails if product does not exist', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [ ->postJson('/api/v1/carts', [
'product_id' => 99999, 'product_id' => 99999,
'product_quantity' => 1 'product_quantity' => 1,
]); ]);
// Expecting validation error. // Expecting validation error.
@@ -111,7 +111,7 @@ test('cart validation fails if quantity is invalid', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [ ->postJson('/api/v1/carts', [
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 0 // Min is 1 'product_quantity' => 0, // Min is 1
]); ]);
$response->assertStatus(422) $response->assertStatus(422)
@@ -125,7 +125,7 @@ test('cart validation fails if stock is insufficient', function () {
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/carts', [ ->postJson('/api/v1/carts', [
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 10 'product_quantity' => 10,
]); ]);
$response->assertStatus(422) $response->assertStatus(422)
@@ -153,8 +153,8 @@ test('authenticated user can list cart items', function () {
'product_id', 'product_id',
'product_quantity', 'product_quantity',
'product', 'product',
] ],
] ],
]); ]);
}); });
@@ -175,7 +175,7 @@ test('index adjusts quantity if stock decreased', function () {
$this->assertDatabaseHas('cart_items', [ $this->assertDatabaseHas('cart_items', [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id, 'product_id' => $product->id,
'product_quantity' => 5 'product_quantity' => 5,
]); ]);
}); });
@@ -207,14 +207,14 @@ test('authenticated user can remove specific item from cart', function () {
$response = $this->actingAs($this->user, 'sanctum') $response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->patchJson('/api/v1/carts', [ ->patchJson('/api/v1/carts', [
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
$response->assertStatus(200); $response->assertStatus(200);
$this->assertDatabaseMissing('cart_items', [ $this->assertDatabaseMissing('cart_items', [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
}); });

View File

@@ -14,7 +14,7 @@ beforeEach(function () {
function createCategory(array $attributes = []): Category function createCategory(array $attributes = []): Category
{ {
$name = $attributes['name'] ?? 'Test Category ' . Str::random(5); $name = $attributes['name'] ?? 'Test Category '.Str::random(5);
// Handle name translation if it's not an array // Handle name translation if it's not an array
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -30,7 +30,8 @@ function createCategory(array $attributes = []): Category
function createProduct(array $attributes = []): Product function createProduct(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -61,8 +62,8 @@ test('can list categories', function () {
'id', 'id',
'name', 'name',
'slug', 'slug',
] ],
] ],
]); ]);
$this->assertCount(3, $response->json('data')); $this->assertCount(3, $response->json('data'));
@@ -152,7 +153,7 @@ test('can show a specific category', function () {
'data' => [ 'data' => [
'id' => $category->id, 'id' => $category->id,
'name' => 'Test Category', 'name' => 'Test Category',
] ],
]); ]);
}); });
@@ -181,7 +182,7 @@ test('returns 404 for invalid category id format', function () {
test('can list products for a category', function () { test('can list products for a category', function () {
// Arrange // Arrange
$category = createCategory(); $category = createCategory();
$products = collect(range(1, 5))->map(fn() => createProduct()); $products = collect(range(1, 5))->map(fn () => createProduct());
// Attach products to category // Attach products to category
$category->products()->attach($products->pluck('id')); $category->products()->attach($products->pluck('id'));
@@ -199,7 +200,7 @@ test('can list products for a category', function () {
'*' => [ '*' => [
'id', 'id',
'name', 'name',
] ],
], ],
]); ]);

View File

@@ -14,7 +14,7 @@ beforeEach(function () {
function createCollection(array $attributes = []): Collection 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 // Handle name translation if it's not an array
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -29,7 +29,8 @@ function createCollection(array $attributes = []): Collection
function createProductForCollection(array $attributes = []): Product 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([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -60,8 +61,8 @@ test('can list collections', function () {
'id', 'id',
'name', 'name',
'slug', 'slug',
] ],
] ],
]); ]);
$this->assertCount(3, $response->json('data')); $this->assertCount(3, $response->json('data'));
@@ -86,7 +87,7 @@ test('does not list invisible collections', function () {
test('can list paginated collections', function () { test('can list paginated collections', function () {
// Arrange // Arrange
$collections = collect(range(1, 10))->map(fn() => createCollection()); $collections = collect(range(1, 10))->map(fn () => createCollection());
// Act // Act
$response = $this->withHeaders([ $response = $this->withHeaders([
@@ -119,7 +120,7 @@ test('can show a specific collection', function () {
'data' => [ 'data' => [
'id' => $collection->id, 'id' => $collection->id,
'name' => 'Test Collection', 'name' => 'Test Collection',
] ],
]); ]);
}); });
@@ -148,7 +149,7 @@ test('returns 404 for invalid collection id format', function () {
test('can list products for a collection', function () { test('can list products for a collection', function () {
// Arrange // Arrange
$collection = createCollection(); $collection = createCollection();
$products = collect(range(1, 5))->map(fn() => createProductForCollection()); $products = collect(range(1, 5))->map(fn () => createProductForCollection());
// Attach products to collection // Attach products to collection
$collection->products()->attach($products->pluck('id')); $collection->products()->attach($products->pluck('id'));
@@ -166,7 +167,7 @@ test('can list products for a collection', function () {
'*' => [ '*' => [
'id', 'id',
'name', 'name',
] ],
], ],
]); ]);

View File

@@ -1,8 +1,7 @@
<?php <?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product; use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Favorite\Favorite; use App\Models\User;
beforeEach(function () { beforeEach(function () {
$this->user = User::factory()->create([ $this->user = User::factory()->create([
@@ -14,7 +13,7 @@ beforeEach(function () {
$this->createProduct = function () { $this->createProduct = function () {
return Product::create([ return Product::create([
'name' => 'Test Product', 'name' => 'Test Product',
'slug' => 'test-product-' . uniqid(), 'slug' => 'test-product-'.uniqid(),
'stock' => 10, 'stock' => 10,
'price_amount' => 100, 'price_amount' => 100,
'is_visible' => true, 'is_visible' => true,
@@ -43,17 +42,17 @@ test('authenticated user can add item to favorites', function () {
$response = $this->actingAs($this->user, 'sanctum') $response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [ ->postJson('/api/v1/favorites', [
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
$response->assertStatus(200) $response->assertStatus(200)
->assertJson([ ->assertJson([
'message' => 'Added' 'message' => 'Added',
]); ]);
$this->assertDatabaseHas('favorites', [ $this->assertDatabaseHas('favorites', [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
}); });
@@ -62,24 +61,24 @@ test('authenticated user can remove item from favorites (toggle)', function () {
// Add first // Add first
$this->user->favorites()->create([ $this->user->favorites()->create([
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
// Request to toggle (remove) // Request to toggle (remove)
$response = $this->actingAs($this->user, 'sanctum') $response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [ ->postJson('/api/v1/favorites', [
'product_id' => $product->id 'product_id' => $product->id,
]); ]);
$response->assertStatus(200) $response->assertStatus(200)
->assertJson([ ->assertJson([
'message' => 'Removed' 'message' => 'Removed',
]); ]);
$this->assertDatabaseMissing('favorites', [ $this->assertDatabaseMissing('favorites', [
'user_id' => $this->user->id, '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') $response = $this->actingAs($this->user, 'sanctum')
->withHeaders(['Api-Token' => config('ecommerce.api.token')]) ->withHeaders(['Api-Token' => config('ecommerce.api.token')])
->postJson('/api/v1/favorites', [ ->postJson('/api/v1/favorites', [
'product_id' => 99999 'product_id' => 99999,
]); ]);
$response->assertStatus(422) $response->assertStatus(422)
@@ -116,8 +115,8 @@ test('authenticated user can view favorites list with items', function () {
'name', 'name',
'slug', 'slug',
// Add other product fields as expected by ProductResource // Add other product fields as expected by ProductResource
] ],
] ],
] ],
]); ]);
}); });

View File

@@ -16,7 +16,7 @@ beforeEach(function () {
function createFilterCategory(array $attributes = []): Category function createFilterCategory(array $attributes = []): Category
{ {
$name = $attributes['name'] ?? 'Test Category ' . Str::random(5); $name = $attributes['name'] ?? 'Test Category '.Str::random(5);
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -31,7 +31,8 @@ function createFilterCategory(array $attributes = []): Category
function createFilterBrand(array $attributes = []): Brand function createFilterBrand(array $attributes = []): Brand
{ {
$name = $attributes['name'] ?? 'Test Brand ' . Str::random(5); $name = $attributes['name'] ?? 'Test Brand '.Str::random(5);
return Brand::create(array_merge([ return Brand::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -42,7 +43,7 @@ function createFilterBrand(array $attributes = []): Brand
function createFilterCollection(array $attributes = []): Collection function createFilterCollection(array $attributes = []): Collection
{ {
$name = $attributes['name'] ?? 'Test Collection ' . Str::random(5); $name = $attributes['name'] ?? 'Test Collection '.Str::random(5);
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -56,7 +57,8 @@ function createFilterCollection(array $attributes = []): Collection
function createFilterProduct(array $attributes = []): Product function createFilterProduct(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -84,7 +86,7 @@ test('can get filters', function () {
'data' => [ 'data' => [
'categories', 'categories',
'brands', 'brands',
] ],
]); ]);
$this->assertCount(1, $response->json('data.categories')); $this->assertCount(1, $response->json('data.categories'));

View File

@@ -1,7 +1,5 @@
<?php <?php
use App\Models\CMS\Forms\ContactUS;
use App\Models\CMS\Marketing\NewsletterUser;
use App\Models\System\Settings\OS; use App\Models\System\Settings\OS;
use App\Models\User; use App\Models\User;

View File

@@ -32,8 +32,8 @@ test('can list provinces', function () {
'id', 'id',
'name', 'name',
'region', 'region',
] ],
] ],
]); ]);
$this->assertCount(2, $response->json('data')); $this->assertCount(2, $response->json('data'));
@@ -73,8 +73,8 @@ test('can list post branches', function () {
'name', 'name',
'address', 'address',
'description', 'description',
] ],
] ],
]); ]);
$this->assertCount(2, $response->json('data')); $this->assertCount(2, $response->json('data'));

View File

@@ -42,8 +42,8 @@ test('can list order payment types', function () {
'*' => [ '*' => [
'id', 'id',
'name', 'name',
] ],
] ],
]); ]);
$this->assertCount(2, $response->json('data')); $this->assertCount(2, $response->json('data'));

View File

@@ -31,7 +31,7 @@ beforeEach(function () {
// Mock default payment type for OrderPayment::default() // Mock default payment type for OrderPayment::default()
if (PaymentType::count() === 0) { if (PaymentType::count() === 0) {
$paymentType = new PaymentType(); $paymentType = new PaymentType;
$paymentType->forceFill([ $paymentType->forceFill([
'id' => 1, 'id' => 1,
'code' => 'cash', 'code' => 'cash',
@@ -44,7 +44,7 @@ beforeEach(function () {
}); });
test('authenticated user can list their orders', function () { test('authenticated user can list their orders', function () {
$order = new Order(); $order = new Order;
$order->forceFill([ $order->forceFill([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'number' => 'ORD-123', 'number' => 'ORD-123',
@@ -71,8 +71,8 @@ test('authenticated user can list their orders', function () {
'id', 'id',
'number', 'number',
// Add other fields from OrderIndexResource // Add other fields from OrderIndexResource
] ],
] ],
]); ]);
}); });
@@ -186,7 +186,7 @@ test('order validation fails with invalid data', function () {
}); });
test('can show specific order', function () { test('can show specific order', function () {
$order = new Order(); $order = new Order;
$order->forceFill([ $order->forceFill([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'number' => 'ORD-SHOW', 'number' => 'ORD-SHOW',
@@ -215,7 +215,7 @@ test('can delete order (if allowed)', function () {
// Note: The controller destroy method is basically empty: return response()->rest(); // Note: The controller destroy method is basically empty: return response()->rest();
// But the route exists. Let's test it returns 200 at least. // But the route exists. Let's test it returns 200 at least.
$order = new Order(); $order = new Order;
$order->forceFill([ $order->forceFill([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'number' => 'ORD-DEL', 'number' => 'ORD-DEL',

View File

@@ -15,7 +15,8 @@ beforeEach(function () {
function createProductForFilterTest(array $attributes = []): Product function createProductForFilterTest(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -28,7 +29,7 @@ function createProductForFilterTest(array $attributes = []): Product
function createCategoryForFilterTest(array $attributes = []): Category function createCategoryForFilterTest(array $attributes = []): Category
{ {
$name = $attributes['name'] ?? 'Test Category ' . Str::random(5); $name = $attributes['name'] ?? 'Test Category '.Str::random(5);
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -43,7 +44,8 @@ function createCategoryForFilterTest(array $attributes = []): Category
function createBrandForFilterTest(array $attributes = []): Brand function createBrandForFilterTest(array $attributes = []): Brand
{ {
$name = $attributes['name'] ?? 'Test Brand ' . Str::random(5); $name = $attributes['name'] ?? 'Test Brand '.Str::random(5);
return Brand::create(array_merge([ return Brand::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),

View File

@@ -16,7 +16,8 @@ beforeEach(function () {
function createProductForReview(array $attributes = []): Product function createProductForReview(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -62,8 +63,8 @@ test('can list product reviews', function () {
'id', 'id',
'rating', 'rating',
'content', 'content',
] ],
] ],
]); ]);
$this->assertCount(2, $response->json('data')); $this->assertCount(2, $response->json('data'));

View File

@@ -13,7 +13,8 @@ beforeEach(function () {
function createProductForSearch(array $attributes = []): Product function createProductForSearch(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -28,7 +29,7 @@ test('can search product by barcode', function () {
// Arrange // Arrange
$product = createProductForSearch([ $product = createProductForSearch([
'name' => 'Barcode Product', 'name' => 'Barcode Product',
'barcode' => '1234567890123' 'barcode' => '1234567890123',
]); ]);
// Act // Act
@@ -44,7 +45,7 @@ test('can search product by barcode', function () {
'id' => $product->id, 'id' => $product->id,
'name' => 'Barcode Product', 'name' => 'Barcode Product',
'stock' => 10, 'stock' => 10,
] ],
]); ]);
}); });

View File

@@ -16,7 +16,7 @@ function createProductForSortTest(array $attributes = []): Product
$createdAt = $attributes['created_at'] ?? null; $createdAt = $attributes['created_at'] ?? null;
unset($attributes['created_at']); unset($attributes['created_at']);
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
$product = Product::create(array_merge([ $product = Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),

View File

@@ -1,8 +1,8 @@
<?php <?php
use App\Models\User;
use App\Models\Ecommerce\Product\Product\Product; use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\ProductView\ProductView; use App\Models\Ecommerce\Product\ProductView\ProductView;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@@ -18,7 +18,8 @@ beforeEach(function () {
]); ]);
$this->createProduct = function (array $attributes = []) { $this->createProduct = function (array $attributes = []) {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -111,8 +112,8 @@ test('authenticated user can list viewed products', function () {
'name', 'name',
'slug', 'slug',
'price_amount', 'price_amount',
] ],
] ],
]); ]);
$this->assertCount(2, $response->json('data')); $this->assertCount(2, $response->json('data'));

View File

@@ -14,7 +14,8 @@ beforeEach(function () {
function createProductForTest(array $attributes = []): Product function createProductForTest(array $attributes = []): Product
{ {
$name = $attributes['name'] ?? 'Test Product ' . Str::random(5); $name = $attributes['name'] ?? 'Test Product '.Str::random(5);
return Product::create(array_merge([ return Product::create(array_merge([
'name' => $name, 'name' => $name,
'slug' => Str::slug($name), 'slug' => Str::slug($name),
@@ -27,7 +28,7 @@ function createProductForTest(array $attributes = []): Product
function createCategoryForTest(array $attributes = []): Category function createCategoryForTest(array $attributes = []): Category
{ {
$name = $attributes['name'] ?? 'Test Category ' . Str::random(5); $name = $attributes['name'] ?? 'Test Category '.Str::random(5);
$nameValue = is_array($name) ? $name : ['en' => $name]; $nameValue = is_array($name) ? $name : ['en' => $name];
$slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name); $slug = Str::slug(is_array($name) ? ($name['en'] ?? reset($name)) : $name);
@@ -61,8 +62,8 @@ test('can list products', function () {
'name', 'name',
'slug', 'slug',
'price_amount', 'price_amount',
] ],
] ],
]); ]);
$this->assertCount(3, $response->json('data')); $this->assertCount(3, $response->json('data'));
@@ -70,7 +71,7 @@ test('can list products', function () {
test('can paginate products', function () { test('can paginate products', function () {
// Arrange // Arrange
collect(range(1, 10))->each(fn() => createProductForTest()); collect(range(1, 10))->each(fn () => createProductForTest());
// Act // Act
$response = $this->withHeaders([ $response = $this->withHeaders([
@@ -150,7 +151,7 @@ test('can show a specific product', function () {
'data' => [ 'data' => [
'id' => $product->id, 'id' => $product->id,
'name' => 'Test Product', 'name' => 'Test Product',
] ],
]); ]);
}); });
@@ -190,7 +191,7 @@ test('can list related products', function () {
$category->products()->attach([ $category->products()->attach([
$mainProduct->id, $mainProduct->id,
$relatedProduct1->id, $relatedProduct1->id,
$relatedProduct2->id $relatedProduct2->id,
]); ]);
// Act // Act
@@ -206,8 +207,8 @@ test('can list related products', function () {
'*' => [ '*' => [
'id', 'id',
'name', 'name',
] ],
] ],
]); ]);
// Should contain related products but not the main product itself (usually) // Should contain related products but not the main product itself (usually)

View File

@@ -2,11 +2,10 @@
use App\Models\Ecommerce\Product\Product\Product; use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Review\Review; use App\Models\Ecommerce\Product\Review\Review;
use App\Models\User;
use App\Models\System\Settings\OS; use App\Models\System\Settings\OS;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
uses(RefreshDatabase::class); uses(RefreshDatabase::class);
@@ -20,7 +19,7 @@ beforeEach(function () {
$this->product = Product::create([ $this->product = Product::create([
'name' => 'Test Product', 'name' => 'Test Product',
'slug' => 'test-product-' . uniqid(), 'slug' => 'test-product-'.uniqid(),
'price_amount' => 100, 'price_amount' => 100,
'stock' => 10, 'stock' => 10,
'is_visible' => true, 'is_visible' => true,
@@ -53,9 +52,9 @@ test('authenticated user can view their reviews', function () {
'product' => [ 'product' => [
'id', 'id',
'name', 'name',
] ],
] ],
] ],
]); ]);
}); });

View File

@@ -13,7 +13,7 @@
uses( uses(
Tests\TestCase::class, Tests\TestCase::class,
Illuminate\Foundation\Testing\RefreshDatabase::class, Illuminate\Foundation\Testing\RefreshDatabase::class,
)->in('Feature'); )->in('Feature');
/* /*