Files
InvoiceShelf/tests/Feature/Admin/CompanyTest.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

73 lines
1.6 KiB
PHP

<?php
use App\Http\Controllers\Company\Company\CompaniesController;
use App\Http\Requests\CompaniesRequest;
use App\Models\Company;
use App\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
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('store user using a form request', function () {
$this->assertActionUsesFormRequest(
CompaniesController::class,
'store',
CompaniesRequest::class
);
});
test('store company', function () {
$company = Company::factory()->raw([
'currency' => 12,
'address' => [
'country_id' => 12,
],
]);
postJson('/api/v1/companies', $company)
->assertStatus(201);
$company = collect($company)
->only([
'name',
])
->toArray();
$this->assertDatabaseHas('companies', $company);
});
test('delete company', function () {
postJson('/api/v1/companies/delete', ['xyz'])
->assertStatus(422);
});
test('transfer ownership', function () {
$company = Company::factory()->create();
$user = User::factory()->create();
postJson('/api/v1/transfer/ownership/'.$user->id)
->assertOk();
});
test('get companies', function () {
getJson('/api/v1/companies')
->assertOk();
});