feat-add-unit-test-for-kasmasukapi
WMS API/ERP-API/pipeline/head This commit looks good
Details
WMS API/ERP-API/pipeline/head This commit looks good
Details
This commit is contained in:
parent
4a07440683
commit
970d28bf52
|
|
@ -3,18 +3,22 @@
|
|||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\User;
|
||||
use App\Models\Coa;
|
||||
use App\Models\KasMasuk;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\KasMasuk>
|
||||
*/
|
||||
class KasMasukFactory extends Factory
|
||||
{
|
||||
protected $model = KasMasuk::class;
|
||||
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'coa_id' => Coa::factory(),
|
||||
'tanggal' => $this->faker->date(),
|
||||
'deskripsi' => $this->faker->sentence(),
|
||||
'jumlah' => $this->faker->randomNumber(6),
|
||||
'jumlah' => $this->faker->randomFloat(2, 100000, 1000000),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,74 +2,91 @@
|
|||
|
||||
namespace Tests\Unit;
|
||||
|
||||
|
||||
use App\Models\KasMasuk;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\KasMasuk;
|
||||
use App\Models\User;
|
||||
use App\Models\Coa;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class KasMasukTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase; // Menggunakan database testing
|
||||
use RefreshDatabase; // Reset the database after each test
|
||||
|
||||
protected $user;
|
||||
protected $coa;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->user = User::factory()->create();
|
||||
$this->coa = Coa::factory()->create();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_list_all_kas_masuk()
|
||||
public function test_can_list_all_kas_masuk()
|
||||
{
|
||||
KasMasuk::factory()->count(3)->create();
|
||||
KasMasuk::factory()->count(3)->create(['user_id' => $this->user->id, 'coa_id' => $this->coa->id]);
|
||||
|
||||
$response = $this->getJson('/api/kas-masuk');
|
||||
$response = $this->actingAs($this->user)->getJson('/api/kas-masuk');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonCount(3);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_create_a_kas_masuk_entry()
|
||||
public function test_can_create_a_kas_masuk_entry()
|
||||
{
|
||||
$data = [
|
||||
'tanggal' => now()->toDateString(),
|
||||
'deskripsi' => 'Pemasukan dari pelanggan',
|
||||
'jumlah' => 1000000,
|
||||
'coa_id' => $this->coa->id,
|
||||
];
|
||||
|
||||
$response = $this->postJson('/api/kas-masuk', $data);
|
||||
$response = $this->actingAs($this->user)->postJson('/api/kas-masuk', $data);
|
||||
|
||||
$response->assertStatus(201)
|
||||
->assertJsonFragment(['deskripsi' => 'Pemasukan dari pelanggan']);
|
||||
|
||||
$this->assertDatabaseHas('kas_masuks', $data);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_get_a_specific_kas_masuk_entry()
|
||||
public function test_can_get_a_specific_kas_masuk_entry()
|
||||
{
|
||||
$kasMasuk = KasMasuk::factory()->create();
|
||||
$kasMasuk = KasMasuk::factory()->create(['user_id' => $this->user->id, 'coa_id' => $this->coa->id]);
|
||||
|
||||
$response = $this->getJson("/api/kas-masuk/{$kasMasuk->id}");
|
||||
$response = $this->actingAs($this->user)->getJson("/api/kas-masuk/{$kasMasuk->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['deskripsi' => $kasMasuk->deskripsi]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_a_kas_masuk_entry()
|
||||
public function test_can_update_a_kas_masuk_entry()
|
||||
{
|
||||
$kasMasuk = KasMasuk::factory()->create();
|
||||
$kasMasuk = KasMasuk::factory()->create(['user_id' => $this->user->id, 'coa_id' => $this->coa->id]);
|
||||
|
||||
$updateData = [
|
||||
'deskripsi' => 'Pemasukan dari investasi',
|
||||
'jumlah' => 2000000
|
||||
'jumlah' => 2000000,
|
||||
'coa_id' => $this->coa->id,
|
||||
];
|
||||
|
||||
$response = $this->putJson("/api/kas-masuk/{$kasMasuk->id}", $updateData);
|
||||
$response = $this->actingAs($this->user)->putJson("/api/kas-masuk/{$kasMasuk->id}", $updateData);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['deskripsi' => 'Pemasukan dari investasi']);
|
||||
|
||||
$this->assertDatabaseHas('kas_masuks', $updateData);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_delete_a_kas_masuk_entry()
|
||||
public function test_can_delete_a_kas_masuk_entry()
|
||||
{
|
||||
$kasMasuk = KasMasuk::factory()->create();
|
||||
$kasMasuk = KasMasuk::factory()->create(['user_id' => $this->user->id, 'coa_id' => $this->coa->id]);
|
||||
|
||||
$response = $this->deleteJson("/api/kas-masuk/{$kasMasuk->id}");
|
||||
$response = $this->actingAs($this->user)->deleteJson("/api/kas-masuk/{$kasMasuk->id}");
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseMissing('kas_masuks', ['id' => $kasMasuk->id]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue