Have you ever read a documentation? Obviously not.
Jul 11, 2021
5
Level 2
Getting my test to work
I'm trying to create a test that will add a state to the database. The problem I'm getting is I get this error when running the test
Failed asserting that false is true.
Which is kind of correct in a sense that whatever I did isn't inserting the data to the table, but what I really want is for it to save to the database and pass.
Here is my code for my test
public function testAddNewState()
{
$country = Country::all()->first();
$response = $this->post('/api/admin/country/'.$country->id.'/new-state', [
'state' => 'Texas'
]);
$response->assertStatus(302);
$this->assertTrue(count(State::all()) > 1);
}
this is the controller that the api points to
public function addNewState(Country $country)
{
$new = $country->states()->create([
'state' => request('state');
]);
return [
'new' => $new
]
}
Please or to participate in this conversation.