From 5fcbc61651e1f27eba4969dd50c22d677aa98cc5 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Wed, 31 May 2023 12:31:07 +0200 Subject: [PATCH 01/11] Apps list --- app/Http/Controllers/api/AppController.php | 50 ++++++++++++++++++++++ app/Models/App.php | 13 ++++++ database/factories/AppFactory.php | 28 ++++++++++++ database/seeders/DatabaseSeeder.php | 8 ++-- routes/api.php | 3 ++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/api/AppController.php create mode 100644 app/Models/App.php create mode 100644 database/factories/AppFactory.php diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php new file mode 100644 index 0000000..7a538fa --- /dev/null +++ b/app/Http/Controllers/api/AppController.php @@ -0,0 +1,50 @@ +json(App::all()); + } + + /** + * Store a newly created App in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified App. + */ + public function show($id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + // + } +} diff --git a/app/Models/App.php b/app/Models/App.php new file mode 100644 index 0000000..25f288b --- /dev/null +++ b/app/Models/App.php @@ -0,0 +1,13 @@ + + */ +class AppFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + + 'title' => fake()->title(), + 'description' => fake()->text(), + 'url' => fake()->url(), + 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']), + + ]; + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 9ca0f5a..82c5d8a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -12,11 +12,13 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // \App\Models\User::factory(10)->create(); + \App\Models\App::factory(10)->create(); - \App\Models\User::factory()->create([ + /*\App\Models\User::factory()->create([ 'name' => 'Test User', 'email' => 'test@example.com', - ]); + ]);*/ + + } } diff --git a/routes/api.php b/routes/api.php index 09200be..e2ffa23 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\api\UserController; use App\Http\Controllers\api\AuthController; +use App\Http\Controllers\api\AppController; /* |-------------------------------------------------------------------------- @@ -22,3 +23,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); }); + +Route::get('/apps', [AppController::class, 'index']); \ No newline at end of file From 5290486f19e5358c12203c0b16548ab73095b2a1 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Wed, 31 May 2023 12:56:21 +0200 Subject: [PATCH 02/11] Show the specified App --- app/Http/Controllers/api/AppController.php | 7 ++++--- routes/api.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index 7a538fa..5f19d3e 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -19,9 +19,9 @@ public function index() /** * Store a newly created App in storage. */ - public function store(Request $request) + public function store(Request $request, ) { - // + } /** @@ -29,7 +29,8 @@ public function store(Request $request) */ public function show($id) { - // + $app = App::find($id); + return response()->json($app); } /** diff --git a/routes/api.php b/routes/api.php index e2ffa23..9a9ac13 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,4 +24,5 @@ return $request->user(); }); -Route::get('/apps', [AppController::class, 'index']); \ No newline at end of file +Route::get('/apps', [AppController::class, 'index']); +Route::get('/apps/{id}', [AppController::class, 'show']); \ No newline at end of file From fcedfbf6ea6527403c04e71ba5259ae26fcff66b Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Wed, 31 May 2023 13:19:40 +0200 Subject: [PATCH 03/11] Store new app --- app/Http/Controllers/api/AppController.php | 10 +++++++++- routes/api.php | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index 5f19d3e..516be7f 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -19,9 +19,17 @@ public function index() /** * Store a newly created App in storage. */ - public function store(Request $request, ) + public function store(Request $request) { + $validatedData = $request->validate([ + 'title' => 'required|max:255', + 'description' => 'required', + 'url' => 'required|url', + 'state' => 'required|in:COMPLETED,IN PROGRESS,SOON', + ]); + $app = App::create($validatedData); + return response()->json($app, 201); } /** diff --git a/routes/api.php b/routes/api.php index 9a9ac13..b7417c7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -25,4 +25,5 @@ }); Route::get('/apps', [AppController::class, 'index']); -Route::get('/apps/{id}', [AppController::class, 'show']); \ No newline at end of file +Route::get('/apps/{id}', [AppController::class, 'show']); +Route::post('/apps', [AppController::class, 'store']); \ No newline at end of file From 96227d565a616a59fd3419131eaa7466de116904 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Wed, 31 May 2023 13:28:22 +0200 Subject: [PATCH 04/11] Updated App --- app/Http/Controllers/api/AppController.php | 15 +++++++++++++-- routes/api.php | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index 516be7f..e6d468f 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -37,7 +37,7 @@ public function store(Request $request) */ public function show($id) { - $app = App::find($id); + $app = App::findOrFail($id); return response()->json($app); } @@ -46,7 +46,18 @@ public function show($id) */ public function update(Request $request, $id) { - // + $app = App::findOrFail($id); + + $validatedData = $request->validate([ + 'title' => 'required|max:255', + 'description' => 'required', + 'url' => 'required|url', + 'state' => 'required|in:COMPLETED,IN PROGRESS,SOON', + ]); + + $app->update($validatedData); + + return response()->json($app, 200); } /** diff --git a/routes/api.php b/routes/api.php index b7417c7..85409fc 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,4 +26,5 @@ Route::get('/apps', [AppController::class, 'index']); Route::get('/apps/{id}', [AppController::class, 'show']); -Route::post('/apps', [AppController::class, 'store']); \ No newline at end of file +Route::post('/apps', [AppController::class, 'store']); +Route::post('/apps/{id}', [AppController::class, 'update']); From 44c971767902009ec9f2491ad167883ad5558d5a Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Wed, 31 May 2023 13:32:58 +0200 Subject: [PATCH 05/11] Deleted App --- app/Http/Controllers/api/AppController.php | 4 ++-- routes/api.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index e6d468f..9c041bd 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -56,7 +56,6 @@ public function update(Request $request, $id) ]); $app->update($validatedData); - return response()->json($app, 200); } @@ -65,6 +64,7 @@ public function update(Request $request, $id) */ public function destroy($id) { - // + $app = App::findOrFail($id)->delete(); + return response()->json(null, 204); } } diff --git a/routes/api.php b/routes/api.php index 85409fc..6642cd6 100644 --- a/routes/api.php +++ b/routes/api.php @@ -28,3 +28,4 @@ Route::get('/apps/{id}', [AppController::class, 'show']); Route::post('/apps', [AppController::class, 'store']); Route::post('/apps/{id}', [AppController::class, 'update']); +Route::delete('/apps/{id}', [AppController::class, 'destroy']); \ No newline at end of file From ae575680c56be6b1856f3978c0e8d744e7bfe4e3 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Thu, 1 Jun 2023 11:29:27 +0200 Subject: [PATCH 06/11] Message to deleted app --- app/Http/Controllers/api/AppController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index 9c041bd..b15e1a9 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -65,6 +65,6 @@ public function update(Request $request, $id) public function destroy($id) { $app = App::findOrFail($id)->delete(); - return response()->json(null, 204); + return response()->json(['message' => 'Deleted successfully']); } } From ebb1bf4b76a407ca146472f3eefec26690319dc6 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Fri, 2 Jun 2023 00:32:06 +0200 Subject: [PATCH 07/11] CRUD simple tests --- app/Http/Controllers/api/AppController.php | 4 +- routes/api.php | 12 +- tests/Feature/AppTest.php | 155 +++++++++++++++++++++ 3 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/AppTest.php diff --git a/app/Http/Controllers/api/AppController.php b/app/Http/Controllers/api/AppController.php index b15e1a9..6b09554 100644 --- a/app/Http/Controllers/api/AppController.php +++ b/app/Http/Controllers/api/AppController.php @@ -42,7 +42,7 @@ public function show($id) } /** - * Update the specified resource in storage. + * Update the specified App in storage. */ public function update(Request $request, $id) { @@ -60,7 +60,7 @@ public function update(Request $request, $id) } /** - * Remove the specified resource from storage. + * Remove the specified App from storage. */ public function destroy($id) { diff --git a/routes/api.php b/routes/api.php index 6642cd6..be0413d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,8 +24,10 @@ return $request->user(); }); -Route::get('/apps', [AppController::class, 'index']); -Route::get('/apps/{id}', [AppController::class, 'show']); -Route::post('/apps', [AppController::class, 'store']); -Route::post('/apps/{id}', [AppController::class, 'update']); -Route::delete('/apps/{id}', [AppController::class, 'destroy']); \ No newline at end of file +//Route::middleware(['auth:api'])->group(function () { + Route::get('/apps', [AppController::class, 'index'])->name('app.index'); + Route::get('/apps/{id}', [AppController::class, 'show'])->name('app.show'); + Route::post('/apps', [AppController::class, 'store'])->name('app.store'); + Route::put('/apps/{id}', [AppController::class, 'update'])->name('app.update'); + Route::delete('/apps/{id}', [AppController::class, 'destroy'])->name('app.destroy'); +//}); \ No newline at end of file diff --git a/tests/Feature/AppTest.php b/tests/Feature/AppTest.php new file mode 100644 index 0000000..41785d0 --- /dev/null +++ b/tests/Feature/AppTest.php @@ -0,0 +1,155 @@ +create(); + + $response = $this->getJson(route('app.index')); + + $response->assertStatus(200); + $response->json(); + } + + public function test_can_store_an_app_with_valid_data(): void + { + $app = [ + 'title' => fake()->title(), + 'description' => fake()->text(), + 'url' => fake()->url(), + 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) + ]; + + $this->postJson(route('app.store'), $app); + + $this->assertDatabaseHas('apps', $app); + } + + public function test_can_not_store_an_app_with_a_missing_field(): void + { + $app = [ + 'title' => '', + 'description' => fake()->text(), + 'url' => fake()->url(), + 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) + ]; + + $response = $this->postJson(route('app.store'), $app); + + $response->assertStatus(422); + } + + public function test_can_not_store_an_app_with_wrong_data(): void + { + $app = [ + 'title' => fake()->title(), + 'description' => fake()->text(), + 'url' => 123355, // must be text + 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) + ]; + + $response = $this->postJson(route('app.store'), $app); + + $response->assertJsonValidationErrorFor('url'); + + } + + public function test_can_not_store_an_app_with_empty_fields(): void + { + $app = [ + 'title' => '', + 'description' => '', + 'url' => '', + 'state' => [], + ]; + + $response = $this->postJson(route('app.store'), $app); + + $response->assertStatus(422); + } + + public function test_can_show_an_app(): void + { + $app = App::factory()->create(); + + $response = $this->getJson(route('app.show', $app)); + + $response->assertJson([ + 'title' => $app->title, + 'description' => $app->description, + 'url' => $app->url, + 'state' => $app->state, + ]); + } + + public function test_can_not_show_an_app_that_it_doesnt_exists(): void + { + App::factory()->create(); + + $response = $this->getJson(route('app.show', ['id' => '2'])); + + $response->assertStatus(404); + } + + public function test_can_update_an_app_with_valid_data(): void + { + $app = App::factory()->create(); + + $newData = [ + 'title' => 'Title updated', + 'description' => $app->description, + 'url' => $app->url, + 'state' => $app->state, + ]; + + $this->postJson(route('app.store'), $newData); + + $this->assertDatabaseHas('apps', $newData); + } + + public function test_can_not_update_an_app_with_missing_field(): void + { + $app = App::factory()->create(); + + $newData = [ + 'title' => '', + 'description' => $app->description, + 'url' => $app->url, + 'state' => $app->state, + ]; + + $response = $this->postJson(route('app.store'), $newData); + + $response->assertStatus(422); + } + + public function test_can_delete_an_app(): void + { + $app = App::factory()->create(); + + $this->deleteJson(route('app.destroy', $app)); + + $this->assertDatabaseCount('apps', 0); + } + + public function test_can_not_delete_an_app_that_it_doesnt_exists(): void + { + App::factory()->create(); + + $response = $this->deleteJson(route('app.destroy', ['id' => '2'])); + + $response->assertStatus(404); + } + +} From a6249dadf7d23b90abccd5ab7b4fee68262ce187 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Fri, 2 Jun 2023 01:17:25 +0200 Subject: [PATCH 08/11] Tests with auth implemented --- routes/api.php | 6 ++++-- tests/Feature/AppTest.php | 43 +++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/routes/api.php b/routes/api.php index be0413d..1e05960 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,10 +24,12 @@ return $request->user(); }); -//Route::middleware(['auth:api'])->group(function () { +Route::middleware(['auth:api'])->group(function () { Route::get('/apps', [AppController::class, 'index'])->name('app.index'); Route::get('/apps/{id}', [AppController::class, 'show'])->name('app.show'); Route::post('/apps', [AppController::class, 'store'])->name('app.store'); Route::put('/apps/{id}', [AppController::class, 'update'])->name('app.update'); Route::delete('/apps/{id}', [AppController::class, 'destroy'])->name('app.destroy'); -//}); \ No newline at end of file +}); + + diff --git a/tests/Feature/AppTest.php b/tests/Feature/AppTest.php index 41785d0..fd4f407 100644 --- a/tests/Feature/AppTest.php +++ b/tests/Feature/AppTest.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; use App\Models\App; +use App\Models\User; class AppTest extends TestCase { @@ -16,8 +17,8 @@ public function test_can_get_all_apps(): void { App::factory(3)->create(); - $response = $this->getJson(route('app.index')); - + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->getJson(route('app.index')); + $response->assertStatus(200); $response->json(); } @@ -31,7 +32,7 @@ public function test_can_store_an_app_with_valid_data(): void 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) ]; - $this->postJson(route('app.store'), $app); + $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $app); $this->assertDatabaseHas('apps', $app); } @@ -45,7 +46,7 @@ public function test_can_not_store_an_app_with_a_missing_field(): void 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) ]; - $response = $this->postJson(route('app.store'), $app); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $app); $response->assertStatus(422); } @@ -59,7 +60,7 @@ public function test_can_not_store_an_app_with_wrong_data(): void 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) ]; - $response = $this->postJson(route('app.store'), $app); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $app); $response->assertJsonValidationErrorFor('url'); @@ -74,7 +75,7 @@ public function test_can_not_store_an_app_with_empty_fields(): void 'state' => [], ]; - $response = $this->postJson(route('app.store'), $app); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $app); $response->assertStatus(422); } @@ -83,7 +84,7 @@ public function test_can_show_an_app(): void { $app = App::factory()->create(); - $response = $this->getJson(route('app.show', $app)); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->getJson(route('app.show', $app)); $response->assertJson([ 'title' => $app->title, @@ -97,7 +98,7 @@ public function test_can_not_show_an_app_that_it_doesnt_exists(): void { App::factory()->create(); - $response = $this->getJson(route('app.show', ['id' => '2'])); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->getJson(route('app.show', ['id' => '2'])); $response->assertStatus(404); } @@ -113,13 +114,13 @@ public function test_can_update_an_app_with_valid_data(): void 'state' => $app->state, ]; - $this->postJson(route('app.store'), $newData); + $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $newData); $this->assertDatabaseHas('apps', $newData); } public function test_can_not_update_an_app_with_missing_field(): void - { + { $app = App::factory()->create(); $newData = [ @@ -129,7 +130,7 @@ public function test_can_not_update_an_app_with_missing_field(): void 'state' => $app->state, ]; - $response = $this->postJson(route('app.store'), $newData); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $newData); $response->assertStatus(422); } @@ -138,7 +139,7 @@ public function test_can_delete_an_app(): void { $app = App::factory()->create(); - $this->deleteJson(route('app.destroy', $app)); + $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->deleteJson(route('app.destroy', $app)); $this->assertDatabaseCount('apps', 0); } @@ -147,9 +148,25 @@ public function test_can_not_delete_an_app_that_it_doesnt_exists(): void { App::factory()->create(); - $response = $this->deleteJson(route('app.destroy', ['id' => '2'])); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->deleteJson(route('app.destroy', ['id' => '2'])); $response->assertStatus(404); } + private function authCreated() + { + \Artisan::call('passport:install'); + + $user = User::create([ + 'name' => 'Gabriela', + 'email' => 'gaby@gmail.com', + 'dni' => '39986946S', + 'password' => bcrypt('password'), + 'status' => 'ACTIVE', + 'role' => 'ADMIN', + ]); + return $token = $user->createToken('auth_token')->accessToken; + + } + } From 0bbb685cd424ccde08fe5cb7cab53c8e7de9f9f4 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Fri, 2 Jun 2023 01:46:06 +0200 Subject: [PATCH 09/11] Added tests without token cases --- tests/Feature/AppTest.php | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/Feature/AppTest.php b/tests/Feature/AppTest.php index fd4f407..b819060 100644 --- a/tests/Feature/AppTest.php +++ b/tests/Feature/AppTest.php @@ -37,6 +37,20 @@ public function test_can_store_an_app_with_valid_data(): void $this->assertDatabaseHas('apps', $app); } + public function test_can_not_store_an_app_without_token(): void + { + $app = [ + 'title' => fake()->title(), + 'description' => fake()->text(), + 'url' => fake()->url(), + 'state' => fake()->randomElement(['COMPLETED', 'IN PROGRESS', 'SOON']) + ]; + + $response = $this->postJson(route('app.store'), $app); + + $response->assertStatus(401); + } + public function test_can_not_store_an_app_with_a_missing_field(): void { $app = [ @@ -94,6 +108,15 @@ public function test_can_show_an_app(): void ]); } + public function test_can_not_show_an_app_without_token(): void + { + $app = App::factory()->create(); + + $response = $this->getJson(route('app.show', $app)); + + $response->assertStatus(401); + } + public function test_can_not_show_an_app_that_it_doesnt_exists(): void { App::factory()->create(); @@ -119,6 +142,22 @@ public function test_can_update_an_app_with_valid_data(): void $this->assertDatabaseHas('apps', $newData); } + public function test_can_not_update_an_app_without_token(): void + { + $app = App::factory()->create(); + + $newData = [ + 'title' => 'Title updated', + 'description' => $app->description, + 'url' => $app->url, + 'state' => $app->state, + ]; + + $response = $this->postJson(route('app.store'), $newData); + + $response->assertStatus(401); + } + public function test_can_not_update_an_app_with_missing_field(): void { $app = App::factory()->create(); @@ -153,6 +192,15 @@ public function test_can_not_delete_an_app_that_it_doesnt_exists(): void $response->assertStatus(404); } + public function test_can_not_delete_an_app_without_token(): void + { + $app = App::factory()->create(); + + $response = $this->deleteJson(route('app.destroy', $app)); + + $response->assertStatus(401); + } + private function authCreated() { \Artisan::call('passport:install'); From 90ad190a2d6fc7a63e6241dc53f27904a5c11066 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Sun, 4 Jun 2023 01:08:17 +0200 Subject: [PATCH 10/11] Fixed error on update test method --- tests/Feature/AppTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/AppTest.php b/tests/Feature/AppTest.php index b819060..c2fea4e 100644 --- a/tests/Feature/AppTest.php +++ b/tests/Feature/AppTest.php @@ -137,7 +137,7 @@ public function test_can_update_an_app_with_valid_data(): void 'state' => $app->state, ]; - $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $newData); + $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', ['id' => $app->id]), $newData); $this->assertDatabaseHas('apps', $newData); } @@ -153,7 +153,7 @@ public function test_can_not_update_an_app_without_token(): void 'state' => $app->state, ]; - $response = $this->postJson(route('app.store'), $newData); + $response = $this->putJson(route('app.update', ['id' => $app->id]), $newData); $response->assertStatus(401); } @@ -169,7 +169,7 @@ public function test_can_not_update_an_app_with_missing_field(): void 'state' => $app->state, ]; - $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->postJson(route('app.store'), $newData); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', ['id' => $app->id]), $newData); $response->assertStatus(422); } From e689017ee500657f8c0e06c4fa0cd3542b818f20 Mon Sep 17 00:00:00 2001 From: Gabriela Maureira Date: Sun, 4 Jun 2023 01:11:04 +0200 Subject: [PATCH 11/11] Simplify parameter sintax --- tests/Feature/AppTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/AppTest.php b/tests/Feature/AppTest.php index c2fea4e..d6e73b1 100644 --- a/tests/Feature/AppTest.php +++ b/tests/Feature/AppTest.php @@ -137,7 +137,7 @@ public function test_can_update_an_app_with_valid_data(): void 'state' => $app->state, ]; - $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', ['id' => $app->id]), $newData); + $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', $app->id), $newData); $this->assertDatabaseHas('apps', $newData); } @@ -153,7 +153,7 @@ public function test_can_not_update_an_app_without_token(): void 'state' => $app->state, ]; - $response = $this->putJson(route('app.update', ['id' => $app->id]), $newData); + $response = $this->putJson(route('app.update', $app->id), $newData); $response->assertStatus(401); } @@ -169,7 +169,7 @@ public function test_can_not_update_an_app_with_missing_field(): void 'state' => $app->state, ]; - $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', ['id' => $app->id]), $newData); + $response = $this->withHeaders(['Authorization' => 'Bearer ' . $this->authCreated()])->putJson(route('app.update', $app->id), $newData); $response->assertStatus(422); }