. */ namespace Tests\Feature; use App\Account; use Tests\TestCase; class ApiAccountDictionaryTest extends TestCase { protected $route = '/api/accounts'; protected $method = 'POST'; public function testCreate() { $account = Account::factory()->create(); $admin = Account::factory()->admin()->create(); $admin->generateApiKey(); $key = 'foo'; $value = 'bar'; $newValue = 'yop'; $secondKey = 'waza'; // First key $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $key, [ 'value' => $value ])->assertStatus(201); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $value ]); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id) ->assertStatus(200) ->assertJson([ 'dictionary' => [ $key => $value ] ]); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/' . $key) ->assertStatus(200) ->assertJson(['value' => $value]); // Test dictionary accessor $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/' . $key) ->assertStatus(200) ->assertJson(['value' => $account->dictionary->get($key)]); // Update $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $key, [ 'value' => $newValue ])->assertStatus(200); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $newValue ]); // Second key $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $secondKey, [ 'value' => $newValue ])->assertStatus(201); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $key => $newValue, $secondKey => $newValue ]); // Delete $this->keyAuthenticated($admin) ->delete($this->route . '/' . $account->id . '/dictionary/' . $key) ->assertStatus(200); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/') ->assertStatus(200) ->assertJson([ $secondKey => $newValue ]); } }