createUserWithPermission([ ]); Passport::actingAs($data->user); // Act $response = $this->getJson(route('api.v1.organizations.show', [$data->organization->getKey()])); // Assert $response->assertStatus(403); } public function test_show_endpoint_returns_organization(): void { // Arrange $data = $this->createUserWithPermission([ 'organizations:view', ]); Passport::actingAs($data->user); // Act $response = $this->getJson(route('api.v1.organizations.show', [$data->organization->getKey()])); // Assert $response->assertStatus(200); $response->assertJsonPath('data.id', $data->organization->getKey()); } public function test_update_endpoint_fails_if_user_has_no_permission_to_update_organizations(): void { // Arrange $data = $this->createUserWithPermission([ ]); $organizationFake = Organization::factory()->make(); Passport::actingAs($data->user); // Act $response = $this->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [ 'name' => $organizationFake->name, ]); // Assert $response->assertStatus(403); } public function test_update_endpoint_updates_project(): void { // Arrange $data = $this->createUserWithPermission([ 'organizations:update', ]); $organizationFake = Organization::factory()->make(); Passport::actingAs($data->user); // Act $response = $this->putJson(route('api.v1.organizations.update', [$data->organization->getKey()]), [ 'name' => $organizationFake->name, ]); // Assert $response->assertStatus(200); $this->assertDatabaseHas(Organization::class, [ 'name' => $organizationFake->name, ]); } }