get("/api/v1/account/"); $this->assertEquals(401, $this->response->getStatusCode()); $this->seeJson(["data" => [], "success" => false, "msg" => "You need to login"]); } public function testGetUserListWithoutAdminAccess(){ $user = new \App\Models\User(); $this->actingAs($user); $this->get("/api/v1/account/"); $this->assertEquals(403, $this->response->getStatusCode()); $this->seeJson(["data" => [], "success" => false, "msg" => "You don't have the permission for this call"]); } public function testGetUserListWithUsers(){ $user1 = $this->getUser(); $user2 = $this->getUser(); $user2->username = "testuser"; $user2->admin = true; $userRepositoryMock = Mockery::mock(\App\Data\Repository\UserRepository::class); $userRepositoryMock->shouldReceive("getAllUsers")->andReturn(collect([$user1, $user2]))->once(); $this->app->instance(\App\Data\Repository\UserRepository::class, $userRepositoryMock); $user = new \App\Models\User(); $user->admin = true; $this->actingAs($user); $this->get("/api/v1/account/"); $this->assertEquals(200, $this->response->getStatusCode()); $this->seeJson(array ( 'data' => array ( 0 => array ( 'id' => 1, 'username' => 'system', 'created_at' => '2019-11-26 15:39:03 UTC', 'updated_at' => '2019-11-26 15:39:03 UTC', 'primaryMail' => NULL, 'status' => 'active', 'inviteCode' => NULL, 'developer' => false, 'admin' => false, ), 1 => array ( 'id' => 1, 'username' => 'testuser', 'created_at' => '2019-11-26 15:39:03 UTC', 'updated_at' => '2019-11-26 15:39:03 UTC', 'primaryMail' => NULL, 'status' => 'active', 'inviteCode' => NULL, 'developer' => false, 'admin' => true, ), ), 'success' => true, 'msg' => NULL, )); } public function testGetSingelUserWithoutLoggedIn() { $this->get("/api/v1/account/2"); $this->assertEquals(401, $this->response->getStatusCode()); $this->seeJson(["data" => [], "success" => false, "msg" => "You need to login"]); } public function testGetSingelUserWithOtherUserAccountAndNoAdmin() { $user = new \App\Models\User(); $user->id = 1; $this->actingAs($user); $this->get("/api/v1/account/2"); $this->assertEquals(403, $this->response->getStatusCode()); $this->seeJson(["data" => [], "success" => false, "msg" => "You don't have the permission for this call"]); } public function testGetSingelUserWithOtherUserAccountAndAdmin() { $user = new \App\Models\User(); $user->id = 1; $user->admin = true; $this->actingAs($user); $user1 = $this->getUser(); $user1->id = 2; $userRepositoryMock = Mockery::mock(\App\Data\Repository\UserRepository::class); $userRepositoryMock->shouldReceive("findById")->with(2)->andReturn($user1)->once(); $this->app->instance(\App\Data\Repository\UserRepository::class, $userRepositoryMock); $this->get("/api/v1/account/2"); $this->assertEquals(200, $this->response->getStatusCode()); $this->seeJson(array ( 'data' => array ( 'id' => 2, 'username' => 'system', 'created_at' => '2019-11-26 15:39:03 UTC', 'updated_at' => '2019-11-26 15:39:03 UTC', 'primaryMail' => NULL, 'status' => 'active', 'inviteCode' => NULL, 'developer' => false, 'admin' => false, ), 'success' => true, 'msg' => NULL, )); } public function testGetSingelUserWithSameUser() { $user = new \App\Models\User(); $user->id = 2; $user->admin = false; $this->actingAs($user); $user1 = $this->getUser(); $user1->id = 2; $userRepositoryMock = Mockery::mock(\App\Data\Repository\UserRepository::class); $userRepositoryMock->shouldReceive("findById")->with(2)->andReturn($user1)->once(); $this->app->instance(\App\Data\Repository\UserRepository::class, $userRepositoryMock); $this->get("/api/v1/account/2"); $this->assertEquals(200, $this->response->getStatusCode()); $this->seeJson(array ( 'data' => array ( 'id' => 2, 'username' => 'system', 'created_at' => '2019-11-26 15:39:03 UTC', 'updated_at' => '2019-11-26 15:39:03 UTC', 'primaryMail' => NULL, 'status' => 'active', 'inviteCode' => NULL, 'developer' => false, 'admin' => false, ), 'success' => true, 'msg' => NULL, )); } private function getUser() { $user = new \App\Data\Entity\User(); $user->id = 1; $user->username = "system"; $user->created_at = "2019-11-26 15:39:03"; $user->updated_at = "2019-11-26 15:39:03"; $user->mail = null; $user->status = "active"; $user->inviteCode = null; $user->developer = false; $user->admin = false; return $user; } }