mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-29 20:51:09 -04:00
v5.0.0 update
This commit is contained in:
69
tests/Feature/Admin/CompanyTest.php
Normal file
69
tests/Feature/Admin/CompanyTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Company\CompaniesController;
|
||||
use Crater\Http\Requests\CompaniesRequest;
|
||||
use Crater\Models\Company;
|
||||
use Crater\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;
|
||||
|
||||
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();
|
||||
|
||||
postJson('/api/v1/companies', $company)
|
||||
->assertStatus(201);
|
||||
|
||||
$company = collect($company)
|
||||
->only([
|
||||
'name'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$this->assertDatabaseHas('companies', $company);
|
||||
});
|
||||
|
||||
test('delete company', function () {
|
||||
$company = Company::factory()->create();
|
||||
|
||||
deleteJson('/api/v1/companies/delete')
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user