96 lines
2.2 KiB
PHP
96 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\Coa;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class CoaApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected $user;
|
|
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->user = User::factory()->create(); // ✅ Create test user
|
|
}
|
|
|
|
|
|
public function test_can_get_all_coas()
|
|
{
|
|
Coa::factory()->count(3)->create();
|
|
|
|
$response = $this->actingAs($this->user)->getJson('/api/coas'); // ✅ Authenticate request
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonCount(3);
|
|
}
|
|
|
|
|
|
public function test_can_create_coa()
|
|
{
|
|
$coaData = [
|
|
'code' => '105',
|
|
'name' => 'Bank BRI'
|
|
];
|
|
|
|
$response = $this->actingAs($this->user)->postJson('/api/coas', $coaData);
|
|
|
|
$response->assertStatus(201)
|
|
->assertJson($coaData);
|
|
|
|
$this->assertDatabaseHas('coas', $coaData);
|
|
}
|
|
|
|
|
|
public function test_can_get_single_coa()
|
|
{
|
|
$coa = Coa::factory()->create();
|
|
|
|
$response = $this->actingAs($this->user)->getJson("/api/coas/{$coa->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson([
|
|
'id' => $coa->id,
|
|
'code' => $coa->code,
|
|
'name' => $coa->name
|
|
]);
|
|
}
|
|
|
|
|
|
public function test_can_update_coa()
|
|
{
|
|
$coa = Coa::factory()->create();
|
|
|
|
$updatedData = [
|
|
'code' => '106',
|
|
'name' => 'Bank Permata'
|
|
];
|
|
|
|
$response = $this->actingAs($this->user)->putJson("/api/coas/{$coa->id}", $updatedData);
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson($updatedData);
|
|
|
|
$this->assertDatabaseHas('coas', $updatedData);
|
|
}
|
|
|
|
|
|
public function test_can_delete_coa()
|
|
{
|
|
$coa = Coa::factory()->create();
|
|
|
|
$response = $this->actingAs($this->user)->deleteJson("/api/coas/{$coa->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson(['message' => 'Akun bank berhasil dihapus']);
|
|
|
|
$this->assertDatabaseMissing('coas', ['id' => $coa->id]);
|
|
}
|
|
}
|