cod consolidation and style updates

This commit is contained in:
Mark Gregory
2026-09-10 09:41:59 +01:00
parent 2648a8f5b5
commit 8dd7d76b8e
35 changed files with 500 additions and 148 deletions
+10 -8
View File
@@ -1,8 +1,9 @@
<?php
namespace Tests\Feature;
use App\Models\LicenseProduct;
use App\Models\LicenseActivation;
use App\Models\LicenseProduct;
use App\Services\Licensing\LicenseIssuer;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -10,15 +11,17 @@ use Tests\TestCase;
class LicenseActivationTest extends TestCase
{
use RefreshDatabase;
public function test_activation_is_idempotent_and_enforces_machine_limit(): void
{
$product=LicenseProduct::create(['code'=>'test','name'=>'Test','edition'=>'Professional','activation_limit'=>1,'max_major_version'=>1,'active'=>true]);
[, $key]=app(LicenseIssuer::class)->issue($product,'Test','test@example.com');
$one=['licenseKey'=>$key,'installationID'=>'11111111-1111-4111-8111-111111111111','appVersion'=>'1.0.0','platform'=>'macOS'];
$this->postJson('/api/v1/activate',$one)->assertOk()->assertJsonStructure(['licenseToken']);
$this->postJson('/api/v1/activate',$one)->assertOk();
$this->postJson('/api/v1/activate',array_merge($one,['installationID'=>'22222222-2222-4222-8222-222222222222']))->assertStatus(409);
$product = LicenseProduct::create(['code' => 'test', 'name' => 'Test', 'edition' => 'Professional', 'activation_limit' => 1, 'max_major_version' => 1, 'active' => true]);
[, $key] = app(LicenseIssuer::class)->issue($product, 'Test', 'test@example.com');
$one = ['licenseKey' => $key, 'installationID' => '11111111-1111-4111-8111-111111111111', 'appVersion' => '1.0.0', 'platform' => 'macOS'];
$this->postJson('/api/v1/activate', $one)->assertOk()->assertJsonStructure(['licenseToken']);
$this->postJson('/api/v1/activate', $one)->assertOk();
$this->postJson('/api/v1/activate', array_merge($one, ['installationID' => '22222222-2222-4222-8222-222222222222']))->assertStatus(409);
}
public function test_validation_refreshes_an_active_installation_without_calling_paddle(): void
{
$product = LicenseProduct::create([
@@ -79,5 +82,4 @@ class LicenseActivationTest extends TestCase
'message' => 'This Mac has been deactivated from the licence portal.',
]);
}
}
@@ -36,12 +36,12 @@ class PaddleSubscriptionProvisioningTest extends TestCase
'status' => $status,
'customer_id' => 'ctm_test',
'transaction_id' => 'txn_test',
'custom_data' => ['customer_name'=>'Mark','customer_email'=>'mark@example.com'],
'current_billing_period' => ['starts_at'=>'2026-09-09T00:00:00Z','ends_at'=>'2026-10-09T00:00:00Z'],
'custom_data' => ['customer_name' => 'Mark', 'customer_email' => 'mark@example.com'],
'current_billing_period' => ['starts_at' => '2026-09-09T00:00:00Z', 'ends_at' => '2026-10-09T00:00:00Z'],
'scheduled_change' => null,
'items' => [[
'recurring' => true,
'price' => ['id'=>$price,'product_id'=>$product],
'price' => ['id' => $price, 'product_id' => $product],
]],
], $extra),
];
@@ -83,7 +83,7 @@ class PaddleSubscriptionProvisioningTest extends TestCase
$this->product('pri_personal_monthly', 'Personal', 1);
app(PurchaseProvisioner::class)->provision('paddle', $this->subscription(
'subscription.updated', 'active', 'pri_personal_monthly', 'pro_personal',
['data'=>['scheduled_change'=>['action'=>'cancel','effective_at'=>'2026-10-09T00:00:00Z']]]
['data' => ['scheduled_change' => ['action' => 'cancel', 'effective_at' => '2026-10-09T00:00:00Z']]]
));
$license = License::firstOrFail();
@@ -96,7 +96,7 @@ class PaddleSubscriptionProvisioningTest extends TestCase
$this->product('pri_personal_monthly', 'Personal', 1);
$service = app(PurchaseProvisioner::class);
$service->provision('paddle', $this->subscription('subscription.created', 'active', 'pri_personal_monthly', 'pro_personal'));
$service->provision('paddle', $this->subscription('subscription.canceled', 'canceled', 'pri_personal_monthly', 'pro_personal', ['data'=>['current_billing_period'=>null]]));
$service->provision('paddle', $this->subscription('subscription.canceled', 'canceled', 'pri_personal_monthly', 'pro_personal', ['data' => ['current_billing_period' => null]]));
$license = License::firstOrFail();
$this->assertNotNull($license->revoked_at);