feat(service): huỷ dịch vụ, SSL, đổi mật khẩu hosting, lịch sử thanh toán theo hình thức
- Lịch sử thanh toán hoá đơn trả thêm `method` (tự động gia hạn / số dư / admin / chuyển khoản / hoàn tiền), bỏ đuôi `(method)` khỏi ghi chú - `DnsServer::panelUrl()` = https://<domain>/ dùng cho email cấp hosting và nút Plesk của khách - Order item trả thêm `uuid`/`type` của dịch vụ để FE dẫn tới trang quản lý - Yêu cầu huỷ dịch vụ, chứng chỉ SSL, lịch sử gia hạn, đổi mật khẩu hosting cho khách Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a6b641015e
commit
b44a88bb52
@@ -12,7 +12,13 @@ use App\Models\OrderItem;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductPricings;
|
||||
use App\Models\Service;
|
||||
use App\Mail\ServiceRenewedMail;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RenewServiceTest extends TestCase
|
||||
@@ -108,4 +114,51 @@ class RenewServiceTest extends TestCase
|
||||
$this->renew(2)->assertStatus(422);
|
||||
$this->assertSame(0, Invoice::where('invoice_type', 2)->count());
|
||||
}
|
||||
|
||||
public function test_customer_renewal_notifies_admins_by_notification_and_email(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
||||
User::factory()->create()->assignRole('Full Administrator');
|
||||
Setting::updateOrCreate(['key' => 'setting'], ['value' => json_encode(['admin_email' => 'admin@example.com'])]);
|
||||
|
||||
$this->renew(3)->assertOk();
|
||||
|
||||
$notification = Notification::where('type', 'service_renewed_by_customer')->where('recipient_type', 'admin')->sole();
|
||||
$this->assertSame('/services/' . $this->service->id, $notification->link);
|
||||
Mail::assertQueued(ServiceRenewedMail::class, fn ($mail) => $mail->hasTo('admin@example.com'));
|
||||
}
|
||||
|
||||
public function test_customer_reads_own_renewal_history_only(): void
|
||||
{
|
||||
$this->renew(3)->assertOk();
|
||||
$path = "/v1/client/client-service/{$this->service->uuid}/renewals";
|
||||
$headers = ['x-access-token' => $this->buildClientAccessToken()];
|
||||
|
||||
$this->actingAs($this->customer, 'client')->withHeaders($headers)->getJson($path)
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.months', 3)
|
||||
->assertJsonPath('data.0.by', 'Bạn')
|
||||
->assertJsonPath('data.0.amount', 40000);
|
||||
|
||||
$this->actingAs(Customer::factory()->create(), 'client')->withHeaders($headers)->getJson($path)->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_renewal_invoice_detail_reports_renewal_term_and_next_date(): void
|
||||
{
|
||||
$expiresAt = $this->service->expires_at->copy();
|
||||
$this->renew(3)->assertOk();
|
||||
$invoice = Invoice::where('invoice_type', 2)->sole();
|
||||
|
||||
$this->actingAs($this->customer, 'client')
|
||||
->withHeaders(['x-access-token' => $this->buildClientAccessToken()])
|
||||
->getJson("/v1/client/invoices/order/ORD-RENEW-TEST?invoice={$invoice->invoice_number}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.service.months', 3)
|
||||
->assertJsonPath('data.items.0.months', 3)
|
||||
->assertJsonPath('data.items.0.price', 40000)
|
||||
->assertJsonPath('data.billing_period_end', $expiresAt->copy()->addMonths(3)->toDateString())
|
||||
->assertJsonPath('data.next_renewal_date', $expiresAt->copy()->addMonths(3)->toDateString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user