api refactoring

This commit is contained in:
Čarodej
2022-05-11 09:19:55 +02:00
parent d2371e667f
commit 70901a2df5
59 changed files with 861 additions and 578 deletions
+7 -9
View File
@@ -278,13 +278,11 @@ class AdminTest extends TestCase
$file = UploadedFile::fake()
->create("fake-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
});
@@ -295,9 +293,9 @@ class AdminTest extends TestCase
$avatar = UploadedFile::fake()
->image('fake-image.jpg');
$this->patchJson('/api/user/settings', [
$this->postJson('/api/user/avatar', [
'avatar' => $avatar,
])->assertStatus(204);
])->assertStatus(200);
$user = User::whereRole('user')
->first();
+29 -41
View File
@@ -39,13 +39,11 @@ class FileTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => '.jpg',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => '.jpg',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
$file = File::first();
@@ -80,13 +78,11 @@ class FileTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
$disk = Storage::disk('local');
@@ -126,13 +122,11 @@ class FileTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'jpeg',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'jpeg',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(401);
Storage::disk('local')->assertMissing(
@@ -159,12 +153,10 @@ class FileTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'file' => $file,
'extension' => 'pdf',
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'chunk' => $file,
'extension' => 'pdf',
'is_last_chunk' => 1,
])->assertStatus(422);
Storage::disk('local')
@@ -351,13 +343,11 @@ class FileTest extends TestCase
$file = UploadedFile::fake()
->create("fake-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
});
@@ -405,13 +395,11 @@ class FileTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'jpg',
'file' => $file,
'parent_id' => null,
'path' => '/' . $file->name,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'jpg',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
$file = File::first();
+2 -2
View File
@@ -21,7 +21,7 @@ class FavouriteFolderTest extends TestCase
$this
->actingAs($user)
->postJson('/api/folders/favourites', [
->postJson('/api/favourites', [
'ids' => [
$folder->id,
],
@@ -51,7 +51,7 @@ class FavouriteFolderTest extends TestCase
$this
->actingAs($user)
->deleteJson("/api/folders/favourites/$folder->id")
->deleteJson("/api/favourites/$folder->id")
->assertStatus(201);
$this->assertDatabaseMissing('favourite_folder', [
+6 -7
View File
@@ -370,13 +370,12 @@ class FolderTest extends TestCase
$file = UploadedFile::fake()
->create("fake-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
});
+36 -43
View File
@@ -29,13 +29,12 @@ class FolderUploadTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'path' => '/',
'parent_id' => $folder->id,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
$file = File::first();
@@ -59,24 +58,22 @@ class FolderUploadTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'path' => "/level_1/level_2/level_3/$file->name",
'parent_id' => null,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'path' => "/level_1/level_2/level_3/$file->name",
'is_last_chunk' => 1,
])->assertStatus(201);
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'path' => "/level_1/level_2/level_3/$file->name",
'parent_id' => null,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'path' => "/level_1/level_2/level_3/$file->name",
'is_last_chunk' => 1,
])->assertStatus(201);
$file = File::first();
@@ -107,7 +104,6 @@ class FolderUploadTest extends TestCase
->create([
'name' => 'level_1',
'user_id' => $user->id,
'parent_id' => null,
]);
$level_2 = Folder::factory()
@@ -129,13 +125,12 @@ class FolderUploadTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'path' => "/another_folder/level_2/level_3/$file->name",
'parent_id' => null,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'path' => "/another_folder/level_2/level_3/$file->name",
'is_last_chunk' => 1,
])->assertStatus(201);
// Root folders
@@ -166,24 +161,22 @@ class FolderUploadTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $brother->name,
'extension' => 'pdf',
'file' => $brother,
'path' => "/Folder/Brother/$brother->name",
'parent_id' => null,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $brother->name,
'extension' => 'pdf',
'chunk' => $brother,
'path' => "/Folder/Brother/$brother->name",
'is_last_chunk' => 1,
])->assertStatus(201);
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $sister->name,
'extension' => 'pdf',
'file' => $sister,
'path' => "/Folder/Sister/$sister->name",
'parent_id' => null,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $sister->name,
'extension' => 'pdf',
'chunk' => $sister,
'path' => "/Folder/Sister/$sister->name",
'is_last_chunk' => 1,
])->assertStatus(201);
$brotherFile = File::where('name', 'brother.pdf')->first();
@@ -42,7 +42,7 @@ class NotificationsTest extends TestCase
$this
->actingAs($user)
->getJson('/api/user/notifications')
->getJson('/api/notifications')
->assertJsonFragment([
'category' => 'file-request',
])
@@ -83,8 +83,8 @@ class NotificationsTest extends TestCase
$this
->actingAs($user)
->postJson('/api/user/notifications/read')
->assertStatus(204);
->postJson('/api/notifications/read')
->assertStatus(200);
$this->assertDatabaseHas('notifications', [
'read_at' => now(),
@@ -125,8 +125,8 @@ class NotificationsTest extends TestCase
$this
->actingAs($user)
->deleteJson('/api/user/notifications')
->assertStatus(204);
->deleteJson('/api/notifications')
->assertStatus(200);
$this->assertDatabaseCount('notifications', 0);
}
@@ -329,25 +329,23 @@ class VisitorManipulatingTest extends TestCase
$this
->withUnencryptedCookies($cookie)
->post("/api/editor/upload/$share->token", [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
->post("/api/editor/upload/chunks/$share->token", [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
}
// Check public shared item
if (! $is_protected) {
$this->postJson("/api/editor/upload/$share->token", [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson("/api/editor/upload/chunks/$share->token", [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
}
+12 -14
View File
@@ -31,13 +31,12 @@ class TeamFileAccessTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
});
@@ -80,13 +79,12 @@ class TeamFileAccessTest extends TestCase
$this
->actingAs($user)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
});
+9 -5
View File
@@ -86,7 +86,7 @@ class TeamManagementTest extends TestCase
$this
->actingAs($member)
->putJson("/api/teams/invitations/{$invitation->id}")
->assertNoContent();
->assertOk();
// Get notification
$notification = json_decode(DB::table('notifications')->first()->data);
@@ -124,7 +124,7 @@ class TeamManagementTest extends TestCase
$this
->putJson("/api/teams/invitations/{$invitation->id}")
->assertNoContent();
->assertOk();
$this
->assertDatabaseHas('team_folder_invitations', [
@@ -228,7 +228,7 @@ class TeamManagementTest extends TestCase
$this
->actingAs($member)
->deleteJson("/api/teams/invitations/{$invitation->id}")
->assertNoContent();
->assertOk();
// Get notification
$notification = json_decode(DB::table('notifications')->first()->data);
@@ -300,11 +300,13 @@ class TeamManagementTest extends TestCase
],
'invitations' => [
[
'type' => 'invitation',
'id' => null,
'email' => 'existing@member.com',
'permission' => 'can-edit',
],
[
'type' => 'invitation',
'id' => null,
'email' => 'added@member.com',
'permission' => 'can-view',
@@ -385,6 +387,7 @@ class TeamManagementTest extends TestCase
],
'invitations' => [
[
'type' => 'invitation',
'id' => null,
'email' => 'existing@member.com',
'permission' => 'can-view',
@@ -482,6 +485,7 @@ class TeamManagementTest extends TestCase
'members' => [],
'invitations' => [
[
'type' => 'invitation',
'id' => null,
'email' => 'existing@member.com',
'permission' => 'can-edit',
@@ -654,7 +658,7 @@ class TeamManagementTest extends TestCase
$this
->actingAs($user)
->deleteJson("/api/teams/folders/{$folder->id}")
->assertNoContent();
->assertOk();
$this
->assertDatabaseCount('team_folder_members', 0)
@@ -698,7 +702,7 @@ class TeamManagementTest extends TestCase
$this
->actingAs($member)
->deleteJson("/api/teams/folders/{$folder->id}/leave")
->assertNoContent();
->assertOk();
$this
->assertDatabaseMissing('team_folder_members', [
+10 -7
View File
@@ -56,10 +56,12 @@ class TeamsTest extends TestCase
'name' => 'Company Project',
'invitations' => [
[
'type' => 'invitation',
'email' => 'john@internal.com',
'permission' => 'can-edit',
],
[
'type' => 'invitation',
'email' => 'jane@external.com',
'permission' => 'can-view',
],
@@ -139,10 +141,12 @@ class TeamsTest extends TestCase
->post("/api/teams/folders/{$folder->id}/convert", [
'invitations' => [
[
'type' => 'invitation',
'email' => 'john@internal.com',
'permission' => 'can-edit',
],
[
'type' => 'invitation',
'email' => 'jane@external.com',
'permission' => 'can-view',
],
@@ -282,13 +286,12 @@ class TeamsTest extends TestCase
$this
->actingAs($member)
->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
$this->assertDatabaseHas('files', [
+21 -24
View File
@@ -36,12 +36,11 @@ class TrafficTest extends TestCase
{
$this
->actingAs($this->user)
->postJson('/api/upload', [
'name' => $this->file->name,
'file' => $this->file,
'parent_id' => null,
'path' => '/' . $this->file->name,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $this->file->name,
'chunk' => $this->file,
'is_last_chunk' => 1,
'extension' => 'jpg',
])->assertStatus(201);
$this->assertDatabaseHas('traffic', [
@@ -57,12 +56,11 @@ class TrafficTest extends TestCase
{
$this
->actingAs($this->user)
->postJson('/api/upload', [
'name' => $this->file->name,
'file' => $this->file,
'parent_id' => null,
'path' => '/' . $this->file->name,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $this->file->name,
'chunk' => $this->file,
'is_last_chunk' => 1,
'extension' => 'jpg',
])->assertStatus(201);
$this->assertDatabaseHas('traffic', [
@@ -78,12 +76,11 @@ class TrafficTest extends TestCase
$this
->actingAs($this->user)
->postJson('/api/upload', [
'name' => $secondFile->name,
'file' => $secondFile,
'parent_id' => null,
'path' => '/' . $secondFile->name,
'is_last' => 'true',
->postJson('/api/upload/chunks', [
'name' => $secondFile->name,
'chunk' => $secondFile,
'is_last_chunk' => 1,
'extension' => 'jpg',
])->assertStatus(201);
$this->assertDatabaseHas('traffic', [
@@ -116,12 +113,12 @@ class TrafficTest extends TestCase
]);
// Check public shared item
$this->postJson("/api/editor/upload/$share->token", [
'name' => $this->file->name,
'file' => $this->file,
'parent_id' => $folder->id,
'path' => '/' . $this->file->name,
'is_last' => 'true',
$this->postJson("/api/editor/upload/chunks/$share->token", [
'name' => $this->file->name,
'chunk' => $this->file,
'parent_id' => $folder->id,
'extension' => 'jpg',
'is_last_chunk' => 1,
])->assertStatus(201);
$this->assertDatabaseHas('traffic', [
+5 -6
View File
@@ -74,12 +74,11 @@ class TrashTest extends TestCase
$image = UploadedFile::fake()
->image('fake-image.jpg');
$this->postJson('/api/upload', [
'name' => $image->name,
'file' => $image,
'parent_id' => null,
'path' => '/' . $image->name,
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $image->name,
'chunk' => $image,
'is_last_chunk' => 1,
'extension' => 'jpg',
])->assertStatus(201);
$file = File::first();
@@ -6,6 +6,7 @@ use Notification;
use Tests\TestCase;
use App\Users\Models\User;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Illuminate\Http\UploadedFile;
use Domain\UploadRequest\Models\UploadRequest;
use Support\Scheduler\Actions\ExpireUnfilledUploadRequestAction;
@@ -34,17 +35,22 @@ class UploadRequestTest extends TestCase
->hasSettings()
->create();
$folder = Folder::factory()
->create([
'user_id' => $user->id,
]);
$this
->actingAs($user)
->postJson('/api/upload-request', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'email' => 'howdy@hi5ve.digital',
'notes' => 'Please send me your files...',
])
->assertCreated();
$this->assertDatabasehas('upload_requests', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'email' => 'howdy@hi5ve.digital',
'notes' => 'Please send me your files...',
]);
@@ -61,16 +67,21 @@ class UploadRequestTest extends TestCase
->hasSettings()
->create();
$folder = Folder::factory()
->create([
'user_id' => $user->id,
]);
$this
->actingAs($user)
->postJson('/api/upload-request', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'notes' => 'Please send me your files...',
])
->assertCreated();
$this->assertDatabasehas('upload_requests', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'notes' => 'Please send me your files...',
'email' => null,
]);
@@ -87,17 +98,22 @@ class UploadRequestTest extends TestCase
->hasSettings()
->create();
$folder = Folder::factory()
->create([
'user_id' => $user->id,
]);
$this
->actingAs($user)
->postJson('/api/upload-request', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'notes' => 'Please send me your files...',
'name' => 'My name',
])
->assertCreated();
$this->assertDatabasehas('upload_requests', [
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
'folder_id' => $folder->id,
'notes' => 'Please send me your files...',
'email' => null,
'name' => 'My name',
@@ -149,13 +165,11 @@ class UploadRequestTest extends TestCase
->create('fake-file.pdf', 12000000, 'application/pdf');
$this
->postJson("/api/upload-request/$uploadRequest->id/upload", [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson("/api/upload-request/$uploadRequest->id/upload/chunks", [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
$this
@@ -195,13 +209,11 @@ class UploadRequestTest extends TestCase
->create('fake-file.pdf', 12000000, 'application/pdf');
$this
->postJson("/api/upload-request/$uploadRequest->id/upload", [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson("/api/upload-request/$uploadRequest->id/upload/chunks", [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
$this
@@ -240,12 +252,10 @@ class UploadRequestTest extends TestCase
->create('fake-file.pdf', 12000000, 'application/pdf');
$this
->postJson("/api/upload-request/$uploadRequest->id/upload", [
'name' => $file->name,
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson("/api/upload-request/$uploadRequest->id/upload/chunks", [
'name' => $file->name,
'file' => $file,
'is_last_chunk' => 1,
])->assertStatus(410);
}
@@ -313,13 +323,11 @@ class UploadRequestTest extends TestCase
->create('fake-file.pdf', 12000000, 'application/pdf');
$this
->postJson("/api/upload-request/$uploadRequest->id/upload", [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
->postJson("/api/upload-request/$uploadRequest->id/upload/chunks", [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertCreated();
$this->travel(3)->hours();
+17 -21
View File
@@ -31,13 +31,12 @@ class UserZippingTest extends TestCase
$file = UploadedFile::fake()
->create("fake-inner-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
});
@@ -46,13 +45,11 @@ class UserZippingTest extends TestCase
$file = UploadedFile::fake()
->create("fake-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => null,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'is_last_chunk' => 1,
])->assertStatus(201);
});
@@ -88,13 +85,12 @@ class UserZippingTest extends TestCase
$file = UploadedFile::fake()
->create("fake-file-$index.pdf", 1200, 'application/pdf');
$this->postJson('/api/upload', [
'name' => $file->name,
'extension' => 'pdf',
'file' => $file,
'parent_id' => $folder->id,
'path' => "/$file->name",
'is_last' => 'true',
$this->postJson('/api/upload/chunks', [
'name' => $file->name,
'extension' => 'pdf',
'chunk' => $file,
'parent_id' => $folder->id,
'is_last_chunk' => 1,
])->assertStatus(201);
});