Add Woo Manager Pro with multi-store switching and free-tier limits.
Deploy Ladill Woo Manager / deploy (push) Successful in 51s
Deploy Ladill Woo Manager / deploy (push) Successful in 51s
Free: 1 store and 20 products. Pro/Business mirrors Invoice pricing (GHS 49/149) with wallet renewals, Paystack prepay, session-based store switcher, and scoped UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\WooProduct;
|
||||
use App\Models\WooStore;
|
||||
use App\Services\Woo\SubscriptionService;
|
||||
use App\Support\CurrentWooStore;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WooProTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_free_plan_limits_stores_and_products(): void
|
||||
{
|
||||
config(['woo.pro.enabled' => true, 'billing.api_url' => '', 'billing.api_key' => '']);
|
||||
$user = User::factory()->create();
|
||||
|
||||
$service = app(SubscriptionService::class);
|
||||
$this->assertFalse($service->gatingActive());
|
||||
$this->assertTrue($service->isPro($user));
|
||||
|
||||
config(['billing.api_url' => 'https://example.test/billing', 'billing.api_key' => 'test']);
|
||||
|
||||
$service = app(SubscriptionService::class);
|
||||
$this->assertTrue($service->gatingActive());
|
||||
$this->assertTrue($service->canConnectStore($user));
|
||||
|
||||
WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://shop-one.example.com',
|
||||
'status' => WooStore::STATUS_ACTIVE,
|
||||
]);
|
||||
|
||||
$this->assertFalse($service->canConnectStore($user));
|
||||
|
||||
$storeId = WooStore::query()->where('user_id', $user->id)->value('id');
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
WooProduct::create([
|
||||
'woo_store_id' => $storeId,
|
||||
'external_id' => $i + 1,
|
||||
'name' => 'Product '.$i,
|
||||
'slug' => 'product-'.$i,
|
||||
'status' => 'publish',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertFalse($service->canCreateProduct($user));
|
||||
}
|
||||
|
||||
public function test_store_switcher_persists_in_session(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$first = WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://first.example.com',
|
||||
'site_name' => 'First',
|
||||
'status' => WooStore::STATUS_ACTIVE,
|
||||
]);
|
||||
$second = WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://second.example.com',
|
||||
'site_name' => 'Second',
|
||||
'status' => WooStore::STATUS_ACTIVE,
|
||||
]);
|
||||
|
||||
$stores = app(CurrentWooStore::class);
|
||||
$this->assertSame($first->id, $stores->resolve($user)?->id);
|
||||
|
||||
$stores->switch($user, $second->id);
|
||||
$this->assertSame($second->id, $stores->resolve($user)?->id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user