From fa0a88289aac5720edc091d6c5cafc760e235e81 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 17 Jul 2023 11:29:22 -0700 Subject: [PATCH 1/2] Add tests around user search Follow up to #13311 --- tests/Feature/Api/Users/UsersSearchTest.php | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/Feature/Api/Users/UsersSearchTest.php b/tests/Feature/Api/Users/UsersSearchTest.php index 33f77196f3..f14d704b0f 100644 --- a/tests/Feature/Api/Users/UsersSearchTest.php +++ b/tests/Feature/Api/Users/UsersSearchTest.php @@ -25,4 +25,62 @@ class UsersSearchTest extends TestCase $this->assertTrue($results->pluck('name')->contains(fn($text) => str_contains($text, 'Luke'))); $this->assertFalse($results->pluck('name')->contains(fn($text) => str_contains($text, 'Darth'))); } + + public function testResultsWhenSearchingForActiveUsers() + { + User::factory()->create(['first_name' => 'Active', 'last_name' => 'User']); + User::factory()->create(['first_name' => 'Deleted', 'last_name' => 'User'])->delete(); + + $response = $this->actingAsForApi(User::factory()->viewUsers()->create()) + ->getJson(route('api.users.index', [ + 'deleted' => 'false', + 'company_id' => '', + 'search' => 'user', + 'order' => 'asc', + 'offset' => '0', + 'limit' => '20', + ])) + ->assertOk(); + + $firstNames = collect($response->json('rows'))->pluck('first_name'); + + $this->assertTrue( + $firstNames->contains('Active'), + 'Expected user does not appear in results' + ); + + $this->assertFalse( + $firstNames->contains('Deleted'), + 'Unexpected deleted user appears in results' + ); + } + + public function testResultsWhenSearchingForDeletedUsers() + { + User::factory()->create(['first_name' => 'Active', 'last_name' => 'User']); + User::factory()->create(['first_name' => 'Deleted', 'last_name' => 'User'])->delete(); + + $response = $this->actingAsForApi(User::factory()->viewUsers()->create()) + ->getJson(route('api.users.index', [ + 'deleted' => 'true', + 'company_id' => '', + 'search' => 'user', + 'order' => 'asc', + 'offset' => '0', + 'limit' => '20', + ])) + ->assertOk(); + + $firstNames = collect($response->json('rows'))->pluck('first_name'); + + $this->assertFalse( + $firstNames->contains('Active'), + 'Unexpected active user appears in results' + ); + + $this->assertTrue( + $firstNames->contains('Deleted'), + 'Expected deleted user does not appear in results' + ); + } } From a0a5ca1f403eb149ef1b600ec9bb101175aee955 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 19 Jul 2023 08:56:17 +0100 Subject: [PATCH 2/2] Added strtolower for category type Signed-off-by: snipe --- app/Helpers/Helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index e46f168bda..f0f2f5e13e 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -553,8 +553,8 @@ class Helper 'license' => trans('general.license'), ]; - if($selection != null){ - return $category_types[$selection]; + if ($selection != null){ + return $category_types[strtolower($selection)]; } else return $category_types;