. */ namespace Tests\Feature; use App\Account; use Tests\TestCase; class ApiAccountExternalAccountTest extends TestCase { protected $route = '/api/accounts'; protected $method = 'POST'; public function testCreate() { $account = Account::factory()->create(); $admin = Account::factory()->admin()->create(); $admin->generateApiKey(); $username = 'foo'; $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/external/') ->assertStatus(404); $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/external/', [ 'username' => $username, 'domain' => 'bar', 'password' => 'password', 'protocol' => 'UDP' ])->assertStatus(201); $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/external/', [ 'username' => $username, 'domain' => 'bar', 'registrar' => 'bar', 'password' => 'password', 'protocol' => 'UDP' ])->assertJsonValidationErrors(['registrar']); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/external/') ->assertStatus(200) ->assertJson([ 'username' => $username, ]); $this->keyAuthenticated($admin) ->get($this->route . '/123/external/') ->assertStatus(404); $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/external/', [ 'username' => $username . '2', 'domain' => 'bar', 'protocol' => 'UDP' ])->assertStatus(200); $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/external/', [ 'username' => $username . '2', 'domain' => 'bar', 'realm' => 'newrealm', 'protocol' => 'UDP' ])->assertJsonValidationErrors(['password']); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/external/') ->assertStatus(200) ->assertJson([ 'username' => $username . '2', ]); $this->keyAuthenticated($admin) ->delete($this->route . '/' . $account->id . '/external') ->assertStatus(200); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/external/') ->assertStatus(404); } }