diff --git a/app/Http/Controllers/GroupSettingController.php b/app/Http/Controllers/GroupSettingController.php index 115d9c69912d..85d141d1d735 100644 --- a/app/Http/Controllers/GroupSettingController.php +++ b/app/Http/Controllers/GroupSettingController.php @@ -179,9 +179,9 @@ class GroupSettingController extends BaseController $ids = request()->input('ids'); - $group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get(); + $group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company(); - if (! $group_settings) { + if ($group_settings->count() == 0) { return response()->json(['message' => ctrans('texts.no_group_settings_found')]); } @@ -191,7 +191,7 @@ class GroupSettingController extends BaseController /* * Send the other actions to the switch */ - $group_settings->each(function ($group, $key) use ($action, $user) { + $group_settings->cursor()->each(function ($group, $key) use ($action, $user) { if ($user->can('edit', $group)) { $this->group_setting_repo->{$action}($group); } diff --git a/tests/Feature/GroupSettingTest.php b/tests/Feature/GroupSettingTest.php index 944edbe2bf5c..da637d39506c 100644 --- a/tests/Feature/GroupSettingTest.php +++ b/tests/Feature/GroupSettingTest.php @@ -116,10 +116,13 @@ class GroupSettingTest extends TestCase $response->assertStatus(200); $arr = $response->json(); + $id = $arr['data']['id']; + + $this->assertEquals(0, $arr['data']['archived_at']); $data = [ 'action' => 'archive', - 'ids' => [$arr['data']['id']], + 'ids' => [$id], ]; $response = $this->withHeaders([ @@ -132,5 +135,41 @@ class GroupSettingTest extends TestCase $arr = $response->json(); $this->assertNotNull($arr['data'][0]['archived_at']); + + $data = [ + 'action' => 'restore', + 'ids' => [$id], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/group_settings/bulk', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals(0, $arr['data'][0]['archived_at']); + + $data = [ + 'action' => 'delete', + 'ids' => [$id], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/group_settings/bulk', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertNotNull($arr['data'][0]['archived_at']); + $this->assertTrue($arr['data'][0]['is_deleted']); + + } + }