- Added SupplierController for handling supplier operations. - Created SupplierRequest for validation of supplier data. - Introduced SupplierService for business logic related to suppliers. - Developed UI components for supplier management, including a data table and dialogs for creating and editing suppliers. - Updated routes to include resourceful routes for suppliers. - Added SupplierSeeder for populating initial supplier data. - Implemented tests for supplier functionality, including creation, updating, and deletion.
182 lines
5.1 KiB
PHP
182 lines
5.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Supplier;
|
|
use App\Models\User;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
|
|
test('guests are redirected to the login page', function () {
|
|
$response = $this->get(route('admin.master.suppliers.index'));
|
|
$response->assertRedirect(route('login'));
|
|
});
|
|
|
|
test('authenticated users can visit the supplier index page', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->get(route('admin.master.suppliers.index'));
|
|
$response->assertOk();
|
|
});
|
|
|
|
test('supplier index page displays suppliers', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$suppliers = Supplier::factory()->count(3)->create();
|
|
|
|
$response = $this->get(route('admin.master.suppliers.index'));
|
|
$response->assertOk();
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->component('admin/master/supplier/index')
|
|
->has('suppliers', 3)
|
|
);
|
|
});
|
|
|
|
test('supplier can be created', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => 'Supplier Test',
|
|
'phone_number' => '08123456789',
|
|
'address' => 'Jl. Test No. 1',
|
|
]);
|
|
|
|
$response
|
|
->assertSessionHasNoErrors()
|
|
->assertRedirect(route('admin.master.suppliers.index'));
|
|
|
|
$this->assertDatabaseHas('suppliers', [
|
|
'name' => 'Supplier Test',
|
|
'phone_number' => '08123456789',
|
|
'address' => 'Jl. Test No. 1',
|
|
]);
|
|
});
|
|
|
|
test('supplier can be created without optional fields', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => 'Supplier Minimal',
|
|
]);
|
|
|
|
$response
|
|
->assertSessionHasNoErrors()
|
|
->assertRedirect(route('admin.master.suppliers.index'));
|
|
|
|
$this->assertDatabaseHas('suppliers', [
|
|
'name' => 'Supplier Minimal',
|
|
]);
|
|
});
|
|
|
|
test('supplier phone_number must be numeric', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => 'Supplier With Letters',
|
|
'phone_number' => 'abc123',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('phone_number');
|
|
});
|
|
|
|
test('supplier name is required', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => '',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('name');
|
|
});
|
|
|
|
test('supplier name must not exceed 200 characters', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => str_repeat('a', 201),
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('name');
|
|
});
|
|
|
|
test('supplier name must be unique', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
Supplier::factory()->create(['name' => 'Existing Supplier']);
|
|
|
|
$response = $this->post(route('admin.master.suppliers.store'), [
|
|
'name' => 'Existing Supplier',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('name');
|
|
});
|
|
|
|
test('supplier can be updated', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$supplier = Supplier::factory()->create();
|
|
|
|
$response = $this->put(route('admin.master.suppliers.update', $supplier), [
|
|
'name' => 'Supplier Updated',
|
|
'phone_number' => '0987654321',
|
|
'address' => 'Jl. Updated No. 2',
|
|
]);
|
|
|
|
$response
|
|
->assertSessionHasNoErrors()
|
|
->assertRedirect(route('admin.master.suppliers.index'));
|
|
|
|
$supplier->refresh();
|
|
expect($supplier->name)->toBe('Supplier Updated');
|
|
expect($supplier->phone_number)->toBe('0987654321');
|
|
expect($supplier->address)->toBe('Jl. Updated No. 2');
|
|
});
|
|
|
|
test('supplier name can be updated to itself', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$supplier = Supplier::factory()->create(['name' => 'My Supplier']);
|
|
|
|
$response = $this->put(route('admin.master.suppliers.update', $supplier), [
|
|
'name' => 'My Supplier',
|
|
]);
|
|
|
|
$response->assertSessionHasNoErrors();
|
|
});
|
|
|
|
test('supplier update name must be unique excluding itself', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$supplier = Supplier::factory()->create(['name' => 'First']);
|
|
Supplier::factory()->create(['name' => 'Second']);
|
|
|
|
$response = $this->put(route('admin.master.suppliers.update', $supplier), [
|
|
'name' => 'Second',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors('name');
|
|
});
|
|
|
|
test('supplier can be deleted', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$supplier = Supplier::factory()->create();
|
|
|
|
$response = $this->delete(route('admin.master.suppliers.destroy', $supplier));
|
|
|
|
$response
|
|
->assertSessionHasNoErrors()
|
|
->assertRedirect(route('admin.master.suppliers.index'));
|
|
|
|
$this->assertSoftDeleted('suppliers', ['id' => $supplier->id]);
|
|
});
|