From 9c967ed5bbaf3c52e61a656f71edfb7cd048c8cd Mon Sep 17 00:00:00 2001 From: artosepyan Date: Fri, 25 Jul 2025 15:38:39 +0300 Subject: [PATCH 1/3] task: Update routes. Closes #130 --- routes/api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/api.php b/routes/api.php index e848ec3..b75517e 100755 --- a/routes/api.php +++ b/routes/api.php @@ -14,9 +14,9 @@ Route::controller(UserController::class)->group(function () { Route::post('users', 'create'); - Route::put('users/{id}', 'update'); - Route::delete('users/{id}', 'delete'); - Route::get('users/{id}', 'get'); + Route::put('users/{id}', 'update')->whereNumber('id'); + Route::delete('users/{id}', 'delete')->whereNumber('id'); + Route::get('users/{id}', 'get')->whereNumber('id'); Route::get('users', 'search'); Route::get('profile', 'profile'); Route::put('profile', 'updateProfile'); From 45711d9ec1c33572f469d0169c6b97729f80d6f3 Mon Sep 17 00:00:00 2001 From: artosepyan Date: Mon, 28 Jul 2025 09:39:26 +0300 Subject: [PATCH 2/3] Updated UserTest.php --- tests/UserTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/UserTest.php b/tests/UserTest.php index 7f494dc..3877990 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -260,6 +260,15 @@ public function testGet() $this->assertEqualsFixture('get_user', $response->json()); } + public function testGetWrongUrl() + { + $response = $this->actingAs(self::$admin)->json('get', '/users/test'); + + $response->assertNotFound(); + + $response->assertJson(['error' => 'The route v0.1/users/test could not be found.']); + } + public function testGetNotExists() { $response = $this->actingAs(self::$admin)->json('get', '/users/0'); From 285735d0596bec2074498b4a50f7827faa085c91 Mon Sep 17 00:00:00 2001 From: artosepyan Date: Mon, 4 Aug 2025 07:59:40 +0300 Subject: [PATCH 3/3] Add tests for non-numeric ID in GET/PUT/DELETE for user --- tests/UserTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/UserTest.php b/tests/UserTest.php index 3877990..b973a4d 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -260,13 +260,25 @@ public function testGet() $this->assertEqualsFixture('get_user', $response->json()); } - public function testGetWrongUrl() + public function testGetIdParamAsString() { $response = $this->actingAs(self::$admin)->json('get', '/users/test'); $response->assertNotFound(); + } + + public function testPutIdParamAsString() + { + $response = $this->actingAs(self::$admin)->json('put', '/users/test'); - $response->assertJson(['error' => 'The route v0.1/users/test could not be found.']); + $response->assertNotFound(); + } + + public function testDeleteIdParamAsString() + { + $response = $this->actingAs(self::$admin)->json('delete', '/users/test'); + + $response->assertNotFound(); } public function testGetNotExists()