Files
crater/tests/Feature/FileDiskTest.php
Mwikala Kangwa 9e98a96d61 Implement PHP CS Fixer and a coding standard to follow (#471)
* Create PHP CS Fixer config and add to CI workflow

* Run php cs fixer on project

* Add newline at end of file

* Update to use PHP CS Fixer v3

* Run v3 config on project

* Run seperate config in CI
2021-05-21 17:27:51 +05:30

67 lines
1.5 KiB
PHP

<?php
use Crater\Models\FileDisk;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
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->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get file disks', function () {
$response = getJson('/api/v1/disks');
$response->assertOk();
});
test('create file disk', function () {
$disk = FileDisk::factory()->raw();
$response = postJson('/api/v1/disks', $disk);
$disk['credentials'] = json_encode($disk['credentials']);
$this->assertDatabaseHas('file_disks', $disk);
});
test('update file disk', function () {
$disk = FileDisk::factory()->create();
$disk2 = FileDisk::factory()->raw();
$response = putJson("/api/v1/disks/{$disk->id}", $disk2)->assertStatus(200);
$disk2['credentials'] = json_encode($disk2['credentials']);
$this->assertDatabaseHas('file_disks', $disk2);
});
test('get disk', function () {
$disk = FileDisk::factory()->create();
$response = getJson("/api/v1/disks/{$disk->driver}");
$response->assertStatus(200);
});
test('get drivers', function () {
$response = getJson("/api/v1/disk/drivers");
$response->assertStatus(200);
});