diff --git a/app/Jobs/CreateAnystackLicenseJob.php b/app/Jobs/CreateAnystackLicenseJob.php index 27c3818a..2b9bb47b 100644 --- a/app/Jobs/CreateAnystackLicenseJob.php +++ b/app/Jobs/CreateAnystackLicenseJob.php @@ -38,6 +38,7 @@ public function handle(): void $licenseData = $this->createLicense($this->user->anystack_contact_id); $license = License::create([ + 'anystack_id' => $licenseData['id'], 'user_id' => $this->user->id, 'subscription_item_id' => $this->subscriptionItemId, 'policy_name' => $this->subscription->value, diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index a0f0950e..9a1bd63f 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -19,6 +19,7 @@ class LicenseFactory extends Factory public function definition(): array { return [ + 'anystack_id' => fake()->uuid(), 'user_id' => User::factory(), 'subscription_item_id' => SubscriptionItem::factory(), 'policy_name' => fake()->randomElement(Subscription::cases())->value, diff --git a/database/migrations/2025_05_15_190315_alter_licenses_table.php b/database/migrations/2025_05_15_190315_alter_licenses_table.php new file mode 100644 index 00000000..f11c1b90 --- /dev/null +++ b/database/migrations/2025_05_15_190315_alter_licenses_table.php @@ -0,0 +1,36 @@ +uuid('anystack_id')->nullable()->after('id'); + $table->uuid('key')->change(); + + $table->unique('anystack_id'); + $table->unique('key'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('licenses', function (Blueprint $table) { + $table->dropUnique(['anystack_id']); + $table->dropUnique(['key']); + + $table->dropColumn(['anystack_id']); + $table->string('key')->change(); + }); + } +}; diff --git a/tests/Feature/Jobs/CreateAnystackLicenseJobTest.php b/tests/Feature/Jobs/CreateAnystackLicenseJobTest.php index 9ad84dca..6fad58d9 100644 --- a/tests/Feature/Jobs/CreateAnystackLicenseJobTest.php +++ b/tests/Feature/Jobs/CreateAnystackLicenseJobTest.php @@ -140,6 +140,7 @@ public function it_stores_the_license_key_in_database() $job->handle(); $this->assertDatabaseHas('licenses', [ + 'anystack_id' => 'license-123', 'user_id' => $user->id, 'subscription_item_id' => null, 'policy_name' => 'max',