File tree Expand file tree Collapse file tree 9 files changed +255
-46
lines changed
Expand file tree Collapse file tree 9 files changed +255
-46
lines changed Original file line number Diff line number Diff line change 77use Illuminate \Support \Facades \Route ;
88use Illuminate \Support \ServiceProvider ;
99use Luezoid \Http \Controllers \MinionController ;
10+ use Luezoid \Laravelcore \Http \Controllers \FileController ;
11+
1012require_once __DIR__ .'/../Controllers/MinionController.php ' ;
1113require_once __DIR__ .'/../Repositories/MinionRepository.php ' ;
1214require_once __DIR__ .'/../Requests/MinionCreateRequest.php ' ;
@@ -42,6 +44,7 @@ public function defineEnvironment($app)
4244 protected function defineRoutes ($ router )
4345 {
4446 Route::resource ('api/minions ' , MinionController::class, ['parameters ' => ['minions ' => 'id ' ]]);
47+ Route::post ('api/files ' ,FileController::class.'@store ' );
4548 }
4649
4750 protected function defineDatabaseMigrations ()
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Suite ;
4+
5+ use Luezoid \Models \Minion ;
6+ use Tests \TestCase ;
7+ require_once __DIR__ . '/../TestCase.php ' ;
8+ require_once __DIR__ . '/../../Models/Minion.php ' ;
9+ require_once __DIR__ . '/../../Requests/MinionDeleteRequest.php ' ;
10+
11+ class DeleteAPISuccessTest extends TestCase
12+ {
13+ /**
14+ * A basic feature test example.
15+ */
16+ public function test_delete_minion ()
17+ {
18+ $ payload = [
19+ 'name ' => 'Stuart ' ,
20+ 'totalEyes ' => 2 ,
21+ 'favouriteSound ' => 'Grrrrrrrrrrr ' ,
22+ 'hasHairs ' => true ,
23+ ];
24+ // Create a minion.
25+ $ minion = $ this ->postJson ('/api/minions ' , $ payload );
26+ $ minion = Minion::where ('id ' , 1 )->first ();
27+ // Make the request.
28+ $ response = $ this ->deleteJson ('/api/minions/1 ' );
29+ // Assert that the response is successful.
30+ $ response ->assertOk ();
31+ // Assert that the minion is deleted.
32+ $ response ->assertJson ([
33+ 'message ' =>"Resource deleted successfully " ,
34+ 'data ' => [
35+ 'id ' => $ minion ->id ,
36+ 'name ' => $ minion ->name ,
37+ 'totalEyes ' => $ minion ->total_eyes ,
38+ 'favouriteSound ' => $ minion ->favourite_sound ,
39+ 'hasHairs ' => $ minion ->has_hairs
40+ ],
41+ 'type ' => null ,
42+ ]);
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Suite ;
4+
5+ use Illuminate \Http \UploadedFile ;
6+ use Illuminate \Support \Facades \Storage ;
7+ use Tests \TestCase ;
8+ require_once __DIR__ .'/../TestCase.php ' ;
9+ require_once __DIR__ .'/../../../src/Models/File.php ' ;
10+ require_once __DIR__ .'/../../../src/config/file.php ' ;
11+ require_once __DIR__ .'/../../../src/Contracts/IFile.php ' ;
12+ require_once __DIR__ .'/../../../src/Files/Services/LocalFileUploadService.php ' ;
13+ require_once __DIR__ .'/../../../src/Files/Services/SaveFileToS3Service.php ' ;
14+
15+ class FileAPISuccessTest extends TestCase
16+ {
17+ /**
18+ * A basic feature test example.
19+ */
20+ public function testFileUpload ()
21+ {
22+ Storage::fake ('local ' ); // Use a fake disk for testing file uploads
23+
24+ $ file = UploadedFile::fake ()->image ('test-image.jpg ' ); // Create a fake test file
25+
26+ $ this ->app ->bind (\Luezoid \Laravelcore \Contracts \IFile::class, function ($ app ) {
27+ if (config ('file.is_local ' )) {
28+ return $ app ->make (\Luezoid \Laravelcore \Files \Services \LocalFileUploadService::class);
29+ }
30+ return $ app ->make (\Luezoid \Laravelcore \Files \Services \SaveFileToS3Service::class);
31+ });
32+
33+ $ response = $ this ->post ('/api/files ' , [
34+ 'file ' => $ file ,
35+ 'type ' => 'EXAMPLE ' ,
36+ ]);
37+
38+ $ response ->assertStatus (200 ); // Assert that the response has a status code of 200
39+ // Assert the JSON structure of the response
40+ $ response ->assertJsonStructure ([
41+ 'message ' ,
42+ 'data ' => [
43+ 'type ' ,
44+ 'name ' ,
45+ 'localPath ' ,
46+ 's3Key ' ,
47+ 'updatedAt ' ,
48+ 'createdAt ' ,
49+ 'id ' ,
50+ 'url ' ,
51+ ],
52+ 'type ' ,
53+ ]);
54+ }
55+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Suite ;
4+
5+ use Luezoid \Models \Minion ;
6+ use Tests \TestCase ;
7+ require_once __DIR__ . '/../TestCase.php ' ;
8+ require_once __DIR__ . '/../../Models/Minion.php ' ;
9+
10+ class GetAPISuccessTest extends TestCase
11+ {
12+ /**
13+ * A basic feature test example.
14+ */
15+ public function test_get_minion ()
16+ {
17+ $ payload = [
18+ 'name ' => 'Stuart ' ,
19+ 'totalEyes ' => 2 ,
20+ 'favouriteSound ' => 'Grrrrrrrrrrr ' ,
21+ 'hasHairs ' => true ,
22+ ];
23+ // Create a minion.
24+ $ minion = $ this ->postJson ('/api/minions ' , $ payload );
25+ $ minion = Minion::where ('id ' , 1 )->first ();
26+ // Make the request.
27+ $ response = $ this ->getJson ('/api/minions/1 ' );
28+
29+ // Assert that the response is successful.
30+ $ response ->assertOk ();
31+
32+ // Assert that the response data is correct.
33+ $ response ->assertJson ([
34+ 'message ' => null ,
35+ 'data ' => [
36+ 'id ' => $ minion ->id ,
37+ 'name ' => $ minion ->name ,
38+ 'totalEyes ' => $ minion ->total_eyes ,
39+ 'favouriteSound ' => $ minion ->favourite_sound ,
40+ 'hasHairs ' => $ minion ->has_hairs
41+ ],
42+ 'type ' => null ,
43+ ]);
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Suite ;
4+ use Luezoid \Models \Minion ;
5+ use Tests \TestCase ;
6+
7+ require_once __DIR__ . '/../TestCase.php ' ;
8+ require_once __DIR__ . '/../../Models/Minion.php ' ;
9+
10+ class IndexAPISuccessTest extends TestCase
11+ {
12+ /**
13+ * A basic feature test example.
14+ */
15+ public function test_index_minion (): void
16+ {
17+ $ payload = [
18+ 'name ' => 'Stuart ' ,
19+ 'totalEyes ' => 2 ,
20+ 'favouriteSound ' => 'Grrrrrrrrrrr ' ,
21+ 'hasHairs ' => true ,
22+ ];
23+ // Create a minion.
24+ $ minion = $ this ->postJson ('/api/minions ' , $ payload );
25+ $ minion = Minion::where ('id ' , 1 )->first ();
26+
27+ // Make the request.
28+ $ response = $ this ->getJson ('/api/minions ' );
29+
30+ $ response ->assertOk ();
31+
32+ // Assert that the response data is correct.
33+ $ response ->assertJson ([
34+ 'message ' => null ,
35+ 'data ' => [
36+ 'items ' => [
37+ [
38+ 'id ' => $ minion ->id ,
39+ 'name ' => $ minion ->name ,
40+ 'totalEyes ' => $ minion ->total_eyes ,
41+ 'favouriteSound ' => $ minion ->favourite_sound ,
42+ 'hasHairs ' => $ minion ->has_hairs
43+ ]
44+ ],
45+ 'page ' => 1 ,
46+ 'total ' => 1 ,
47+ 'pages ' => 1 ,
48+ 'perpage ' => 15 ,
49+ ],
50+ 'type ' => null ,
51+ ]);
52+ }
53+ }
Original file line number Diff line number Diff line change 66
77require_once __DIR__ . '/../TestCase.php ' ;
88require_once __DIR__ . '/../../Models/Minion.php ' ;
9+ require_once __DIR__ . '/../../Requests/MinionCreateRequest.php ' ;
910
1011class PostAPISuccessTest extends TestCase
1112{
@@ -32,50 +33,4 @@ public function test_post_api()
3233 'type ' => null ,
3334 ]);
3435 }
35-
36- /*public function test_list_api()
37- {
38- $response = $this->get('/api/minions');
39- $response->assertStatus(200);
40- $response->assertJson([
41- "message" => null,
42- "data" => [
43- "items" => [
44- [
45- "id" => 1,
46- "name" => "Lucifer",
47- "totalEyes" => 0,
48- "favouriteSound" => "Luuuuuuu",
49- "hasHairs" => true,
50- "missions" => [],
51- "leadingMission" => null
52- ]
53- ],
54- "page" => 1,
55- "total" => 1,
56- "pages" => 1,
57- "perpage" => 15
58- ],
59- "type" => null
60- ]);
61- }*/
62-
63- /*public function test_show_api()
64- {
65- $response = $this->get('/api/minions/1');
66- $response->assertStatus(200);
67- $response->assertJson([
68- "message" => null,
69- "data" => [
70- "id" => 1,
71- "name" => "Lucifer",
72- "totalEyes" => 0,
73- "favouriteSound" => "Luuuuuuu",
74- "hasHairs" => true,
75- "missions" => [],
76- "leadingMission" => null
77- ],
78- "type" => null
79- ]);
80- }*/
8136}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Suite ;
4+
5+ use Luezoid \Models \Minion ;
6+ use Tests \TestCase ;
7+ require_once __DIR__ . '/../TestCase.php ' ;
8+ require_once __DIR__ . '/../../Models/Minion.php ' ;
9+ require_once __DIR__ . '/../../Requests/MinionUpdateRequest.php ' ;
10+
11+ class PutAPISuccessTest extends TestCase
12+ {
13+ /**
14+ * A basic feature test example.
15+ */
16+ public function test_update_minion ()
17+ {
18+ // Create a minion.
19+ $ minion = $ this ->postJson ('/api/minions ' , [
20+ 'name ' => 'Stuart ' ,
21+ 'totalEyes ' => 2 ,
22+ 'favouriteSound ' => 'Grrrrrrrrrrr ' ,
23+ 'hasHairs ' => true ,
24+ ]);
25+ // Get the minion.
26+ $ minion = Minion::where ('id ' , 1 )->first ();
27+ // Prepare the request payload.
28+ $ payload = [
29+ 'name ' => 'Stuart ' ,
30+ 'totalEyes ' => 2 ,
31+ 'favouriteSound ' => 'Hrrrrrrrrrrr ' ,
32+ 'hasHairs ' => true ,
33+ ];
34+
35+ // Make the request.
36+ $ response = $ this ->putJson ('/api/minions/1 ' , $ payload );
37+
38+ // Assert that the response is successful.
39+ $ response ->assertOk ();
40+
41+ // Assert that the response data is correct.
42+ $ response ->assertJson ([
43+ 'message ' => 'Resource Updated successfully ' ,
44+ 'data ' => [
45+ 'id ' => $ minion ->id ,
46+ 'name ' => $ payload ['name ' ],
47+ 'totalEyes ' => $ payload ['totalEyes ' ],
48+ 'favouriteSound ' => $ payload ['favouriteSound ' ],
49+ 'hasHairs ' => $ payload ['hasHairs ' ],
50+ ],
51+ 'type ' => null ,
52+ ]);
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments