. */ namespace Tests\Feature; use App\Password; use App\PhoneChangeCode; use Tests\TestCase; class ApiAccountPhoneChangeTest extends TestCase { protected $route = '/api/accounts/me/phone'; protected $method = 'POST'; public function testRequest() { $password = Password::factory()->create(); $password->account->generateApiKey(); $this->keyAuthenticated($password->account) ->json($this->method, $this->route.'/request', [ 'phone' => 'blabla' ]) ->assertStatus(422); // Send a SMS /*$this->keyAuthenticated($password->account) ->json($this->method, $this->route.'/request', [ 'phone' => '+3312345678' ]) ->assertStatus(200);*/ } public function testConfirmLongCode() { $phoneChange = PhoneChangeCode::factory()->create(); $this->keyAuthenticated($phoneChange->account) ->json($this->method, $this->route, [ 'code' => 'wrong' ]) ->assertStatus(422); } public function testConfirmGoodCode() { $phoneChange = PhoneChangeCode::factory()->create(); $phone = $phoneChange->phone; $this->keyAuthenticated($phoneChange->account) ->get('/api/accounts/me') ->assertStatus(200) ->assertJson([ 'phone' => null ]); $this->keyAuthenticated($phoneChange->account) ->json($this->method, $this->route, [ 'code' => $phoneChange->code ]) ->assertStatus(200) ->assertJson([ 'phone' => $phone, ]); $this->keyAuthenticated($phoneChange->account) ->get('/api/accounts/me') ->assertStatus(200) ->assertJson([ 'phone' => $phone ]); } }