admin = User::factory()->create([ 'user_type' => 'admin', ]); } public function test_can_view_equipments_index_page(): void { $spec = EquipmentSpecification::create([ 'name' => 'Hydraulic Power', 'description' => 'High pressure hydraulic system', ]); $equipment = Equipment::create([ 'name' => 'CAT 320 Hydraulic Excavator', 'owner_name' => 'Company Owned', 'hourly_rate' => 1500.00, 'status' => 'active', ]); $equipment->specifications()->attach($spec->id); $response = $this->actingAs($this->admin)->get(route('equipments.index')); $response->assertStatus(200); $response->assertInertia(fn ($page) => $page ->component('Equipments::Index', false) ->has('equipments', 1) ->has('specifications', 1) ); } public function test_can_store_update_and_destroy_equipment(): void { $spec = EquipmentSpecification::create([ 'name' => 'Diesel Turbo', ]); // Store $response = $this->actingAs($this->admin)->post(route('equipments.store'), [ 'name' => 'Komatsu D85 Bulldozer', 'owner_name' => 'Prime Equipment Rentals', 'hourly_rate' => 2800.00, 'status' => 'active', 'specifications' => [$spec->id], ]); $response->assertRedirect(); $this->assertDatabaseHas('equipments', [ 'name' => 'Komatsu D85 Bulldozer', 'owner_name' => 'Prime Equipment Rentals', 'hourly_rate' => 2800.00, ]); $equipment = Equipment::where('name', 'Komatsu D85 Bulldozer')->firstOrFail(); $this->assertTrue($equipment->specifications->contains('id', $spec->id)); // Update $response = $this->actingAs($this->admin)->put(route('equipments.update', $equipment), [ 'name' => 'Komatsu D85-EX Bulldozer', 'owner_name' => 'Company Owned', 'hourly_rate' => 3000.00, 'status' => 'active', 'specifications' => [], ]); $response->assertRedirect(); $this->assertDatabaseHas('equipments', [ 'name' => 'Komatsu D85-EX Bulldozer', 'owner_name' => 'Company Owned', 'hourly_rate' => 3000.00, ]); // Destroy $response = $this->actingAs($this->admin)->delete(route('equipments.destroy', $equipment)); $response->assertRedirect(); $this->assertDatabaseMissing('equipments', [ 'id' => $equipment->id, ]); } public function test_can_store_update_and_destroy_specification(): void { // Store $response = $this->actingAs($this->admin)->post(route('equipment-specifications.store'), [ 'name' => '4x4 All-Wheel Drive', 'description' => 'Off-road terrain capabilities', ]); $response->assertRedirect(); $this->assertDatabaseHas('equipment_specifications', [ 'name' => '4x4 All-Wheel Drive', ]); $spec = EquipmentSpecification::where('name', '4x4 All-Wheel Drive')->firstOrFail(); // Update $response = $this->actingAs($this->admin)->put(route('equipment-specifications.update', $spec), [ 'name' => 'AWD 4x4 Heavy Duty', 'description' => 'Updated terrain specifications', ]); $response->assertRedirect(); $this->assertDatabaseHas('equipment_specifications', [ 'name' => 'AWD 4x4 Heavy Duty', ]); // Destroy $response = $this->actingAs($this->admin)->delete(route('equipment-specifications.destroy', $spec)); $response->assertRedirect(); $this->assertDatabaseMissing('equipment_specifications', [ 'id' => $spec->id, ]); } }