55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\Client;
|
|
|
|
use App\Models\Customer;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class BillingProfileTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function as(Customer $customer)
|
|
{
|
|
return $this->actingAs($customer, 'client')->withHeaders(['x-access-token' => $this->buildClientAccessToken()]);
|
|
}
|
|
|
|
public function test_customer_saves_and_reads_own_billing_profile(): void
|
|
{
|
|
$customer = Customer::factory()->create(['status' => 1]);
|
|
|
|
$this->as($customer)->putJson('/v1/client/billing-profile', [
|
|
'invoice_company' => 'Cong ty ABC',
|
|
'tax_code' => '0312345678-001',
|
|
'invoice_address' => '99 Nguyen Hue',
|
|
'invoice_email' => 'ketoan@abc.vn',
|
|
])->assertOk();
|
|
|
|
$this->as($customer)->getJson('/v1/client/billing-profile')
|
|
->assertOk()
|
|
->assertJsonPath('data.tax_code', '0312345678-001');
|
|
}
|
|
|
|
public function test_invalid_tax_code_and_missing_company_are_rejected(): void
|
|
{
|
|
$customer = Customer::factory()->create(['status' => 1]);
|
|
|
|
$this->as($customer)->putJson('/v1/client/billing-profile', ['invoice_company' => 'X', 'tax_code' => '123'])
|
|
->assertStatus(422)->assertJsonValidationErrors('tax_code');
|
|
$this->as($customer)->putJson('/v1/client/billing-profile', ['tax_code' => '0312345678'])
|
|
->assertStatus(422)->assertJsonValidationErrors('invoice_company');
|
|
}
|
|
|
|
public function test_empty_payload_clears_profile(): void
|
|
{
|
|
$customer = Customer::factory()->create(['status' => 1, 'tax_code' => '0312345678', 'invoice_company' => 'ABC']);
|
|
|
|
$this->as($customer)->putJson('/v1/client/billing-profile', [])->assertOk();
|
|
|
|
$this->assertNull($customer->fresh()->tax_code);
|
|
}
|
|
}
|