Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
94
tests/Feature/LemonSqueezySyncPackagesCommandTest.php
Normal file
94
tests/Feature/LemonSqueezySyncPackagesCommandTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\SyncPackageToLemonSqueezy;
|
||||
use App\Models\Package;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus as BusFacade;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LemonSqueezySyncPackagesCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_command_dispatches_jobs_for_packages(): void
|
||||
{
|
||||
Package::factory()->count(2)->create([
|
||||
'lemonsqueezy_product_id' => 'pro_test',
|
||||
'lemonsqueezy_variant_id' => 'pri_test',
|
||||
]);
|
||||
|
||||
BusFacade::fake();
|
||||
|
||||
$this->artisan('lemonsqueezy:sync-packages', [
|
||||
'--dry-run' => true,
|
||||
'--queue' => true,
|
||||
])->assertExitCode(0);
|
||||
|
||||
BusFacade::assertDispatched(SyncPackageToLemonSqueezy::class, 2);
|
||||
}
|
||||
|
||||
public function test_command_filters_packages_by_id(): void
|
||||
{
|
||||
$package = Package::factory()->create();
|
||||
Package::factory()->create();
|
||||
|
||||
BusFacade::fake();
|
||||
|
||||
$this->artisan('lemonsqueezy:sync-packages', [
|
||||
'--dry-run' => true,
|
||||
'--queue' => true,
|
||||
'--package' => [$package->id],
|
||||
])->assertExitCode(0);
|
||||
|
||||
BusFacade::assertDispatched(SyncPackageToLemonSqueezy::class, function (SyncPackageToLemonSqueezy $job) use ($package) {
|
||||
return $this->getJobPackageId($job) === $package->id;
|
||||
});
|
||||
}
|
||||
|
||||
public function test_command_blocks_bulk_sync_with_unmapped_packages(): void
|
||||
{
|
||||
Package::factory()->create([
|
||||
'lemonsqueezy_product_id' => null,
|
||||
'lemonsqueezy_variant_id' => null,
|
||||
]);
|
||||
|
||||
BusFacade::fake();
|
||||
|
||||
$this->artisan('lemonsqueezy:sync-packages', [
|
||||
'--dry-run' => true,
|
||||
'--queue' => true,
|
||||
])->assertExitCode(Command::FAILURE);
|
||||
|
||||
BusFacade::assertNotDispatched(SyncPackageToLemonSqueezy::class);
|
||||
}
|
||||
|
||||
public function test_command_allows_unmapped_packages_when_overridden(): void
|
||||
{
|
||||
Package::factory()->create([
|
||||
'lemonsqueezy_product_id' => null,
|
||||
'lemonsqueezy_variant_id' => null,
|
||||
]);
|
||||
|
||||
BusFacade::fake();
|
||||
|
||||
$this->artisan('lemonsqueezy:sync-packages', [
|
||||
'--dry-run' => true,
|
||||
'--queue' => true,
|
||||
'--allow-unmapped' => true,
|
||||
])->assertExitCode(Command::SUCCESS);
|
||||
|
||||
BusFacade::assertDispatched(SyncPackageToLemonSqueezy::class, 1);
|
||||
}
|
||||
|
||||
protected function getJobPackageId(SyncPackageToLemonSqueezy $job): int
|
||||
{
|
||||
$reflection = new \ReflectionClass($job);
|
||||
$property = $reflection->getProperty('packageId');
|
||||
$property->setAccessible(true);
|
||||
|
||||
return (int) $property->getValue($job);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user