feat: nhắc gia hạn QR theo dịch vụ, failover server hosting, CCCD admin, log cấp phát dịch vụ
- Mail campaign: mẫu nhắc gia hạn thanh toán QR, chọn dịch vụ + chu kỳ từng dòng (renewal_services) - Hosting: nhiều server Plesk cho một gói (service_plan_servers), chuyển server khi server chết - Admin xem/sửa giấy tờ định danh khách, tuỳ chọn gia hạn cho khách, nhật ký cấp phát dịch vụ - Đánh dấu mẫu email dịch vụ là non-marketing Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
047c23beff
commit
55a834a2f8
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Admin;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\Product;
|
||||
use App\Models\Service;
|
||||
use App\Models\Template;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MailCampaignRenewalServicesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function admin(): User
|
||||
{
|
||||
$role = Role::create(['name' => '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' => '<p>Hello</p>', '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);
|
||||
}
|
||||
}
|
||||
@@ -116,12 +116,33 @@ class ClientTwoFactorTest extends TestCase
|
||||
$this->assertTrue($device->expires_at->between(now()->addDays(89), now()->addDays(91)));
|
||||
|
||||
$this->login($customer, $deviceToken)->assertOk()->assertJsonStructure(['data' => ['token']]);
|
||||
$this->login($customer, str_repeat('x', 64))->assertOk()->assertJsonPath('data.two_factor.resend_in', 60);
|
||||
$this->login($customer, str_repeat('x', 64))->assertOk()->assertJsonPath('data.two_factor.resend_in', 300);
|
||||
|
||||
$this->travel(91)->days();
|
||||
$this->login($customer, $deviceToken)->assertOk()->assertJsonStructure(['data' => ['two_factor']]);
|
||||
}
|
||||
|
||||
public function test_repeated_logins_from_same_client_reuse_code_until_it_expires(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$customer = $this->customer(twoFactor: true);
|
||||
|
||||
$first = $this->login($customer)->json('data.two_factor.challenge');
|
||||
$this->travel(2)->minutes();
|
||||
$second = $this->login($customer)->assertJsonPath('data.two_factor.resend_in', 180)->json('data.two_factor.challenge');
|
||||
|
||||
$this->assertSame($first, $second);
|
||||
Mail::assertQueuedCount(1);
|
||||
|
||||
$this->withServerVariables(['REMOTE_ADDR' => '203.0.113.9'])->login($customer);
|
||||
Mail::assertQueuedCount(2);
|
||||
|
||||
$this->travel(301)->seconds();
|
||||
$third = $this->login($customer)->json('data.two_factor.challenge');
|
||||
$this->assertNotSame($first, $third);
|
||||
Mail::assertQueuedCount(3);
|
||||
}
|
||||
|
||||
public function test_challenge_is_destroyed_after_five_wrong_codes(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
Reference in New Issue
Block a user