prepareDatabase([ 'users' => [ $this->adminUser(), $this->normalUser(), ], 'groups' => [ $this->adminGroup(), $this->hiddenGroup() ], 'group_user' => [ ['user_id' => 1, 'group_id' => 1], ], ]); } /** * @test */ public function shows_limited_index_for_guest() { $response = $this->send( $this->request('GET', '/api/groups') ); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getBody()->getContents(), true); $this->assertEquals(['1'], Arr::pluck($data['data'], 'id')); } /** * @test */ public function shows_index_for_admin() { $response = $this->send( $this->request('GET', '/api/groups', [ 'authenticatedAs' => 1, ]) ); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getBody()->getContents(), true); $this->assertEquals(['1', '10'], Arr::pluck($data['data'], 'id')); } protected function hiddenGroup(): array { return [ 'id' => 10, 'name_singular' => 'Hidden', 'name_plural' => 'Ninjas', 'color' => null, 'icon' => 'fas fa-wrench', 'is_hidden' => 1 ]; } }