Files
InvoiceShelf/tests/Feature/Admin/UnitTest.php
Darko Gjorgjijoski 64c481e963 Rename controller namespaces: drop V1 prefix, clarify roles
V1/Admin     -> Company       (company-scoped controllers)
V1/SuperAdmin -> Admin        (platform-wide admin controllers)
V1/Customer  -> CustomerPortal (customer-facing portal)
V1/Installation -> Setup      (installation wizard)
V1/PDF       -> Pdf           (consistent casing)
V1/Modules   -> Modules       (drop V1 prefix)
V1/Webhook   -> Webhook       (drop V1 prefix)

The V1 prefix served no purpose - API versioning is in the route prefix
(/api/v1/), not the controller namespace. "Admin" was misleading for
company-scoped controllers. "SuperAdmin" is now simply "Admin" for
platform administration.
2026-04-03 19:15:20 +02:00

103 lines
2.3 KiB
PHP

<?php
use App\Http\Controllers\Company\Item\UnitsController;
use App\Http\Requests\UnitRequest;
use App\Models\Unit;
use App\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\deleteJson;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
use function Pest\Laravel\putJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get units', function () {
$response = getJson('api/v1/units?page=1');
$response->assertOk();
});
test('create unit', function () {
$data = [
'name' => 'unit name',
'company_id' => User::find(1)->companies()->first()->id,
];
$response = postJson('api/v1/units', $data);
$response->assertStatus(201);
$this->assertDatabaseHas('units', $data);
});
test('store validates using a form request', function () {
$this->assertActionUsesFormRequest(
UnitsController::class,
'store',
UnitRequest::class
);
});
test('get unit', function () {
$unit = Unit::factory()->create();
$response = getJson("api/v1/units/{$unit->id}");
$response->assertOk();
$this->assertDatabaseHas('units', [
'id' => $unit->id,
'name' => $unit['name'],
]);
});
test('update unit', function () {
$unit = Unit::factory()->create();
$update_unit = [
'name' => 'new name',
];
$response = putJson("api/v1/units/{$unit->id}", $update_unit);
$response->assertOk();
$this->assertDatabaseHas('units', [
'id' => $unit->id,
'name' => $update_unit['name'],
]);
});
test('update validates using a form request', function () {
$this->assertActionUsesFormRequest(
UnitsController::class,
'update',
UnitRequest::class
);
});
test('delete unit', function () {
$unit = Unit::factory()->create();
$response = deleteJson("api/v1/units/{$unit->id}");
$response->assertOk();
$this->assertModelMissing($unit);
});