'role-' . uniqid(), 'guard_name' => 'admin']); $role->givePermissionTo(Permission::firstOrCreate(['name' => 'mail-campaign.create', 'guard_name' => 'admin'])); $admin = User::factory()->create(); $admin->assignRole($role); return $admin; } public function test_renewal_services_listing_only_contains_due_services_of_selected_customers(): void { $customer = Customer::factory()->create(); $this->actingAs($this->admin(), 'admin') ->getJson('/api/v1/administrator/mail-campaigns/renewal-services?' . http_build_query(['uuids' => [$customer->uuid], 'days' => 30])) ->assertOk() ->assertExactJson(['error' => false, 'data' => []]); } public function test_renewal_services_are_rejected_for_a_template_that_is_not_a_renewal_reminder(): void { Queue::fake(); $customer = Customer::factory()->create(); $template = Template::create([ 'type_id' => 0, 'name' => 'T ' . uniqid(), 'format' => 'html', 'subject' => 'Ưu đãi', 'message' => '
Hello
', 'status' => 1, ]); $service = Service::query()->forceCreate([ 'uuid' => (string) \Illuminate\Support\Str::uuid(), 'customer_id' => $customer->id, 'product_id' => Product::factory()->create()->id, 'type' => 'vps', 'status' => 'active', ]); $this->actingAs($this->admin(), 'admin') ->postJson('/api/v1/administrator/mail-campaigns', [ 'template_id' => $template->id, 'recipient_type' => 'selected', 'uuids' => [$customer->uuid], 'renewal_services' => [['service_id' => $service->id, 'months' => 1]], ]) ->assertStatus(422); } }