Is it okay to add database assertions when using feature/functional testing?
Here I am trying to create user at /signup end point. In the Controller I am creating a user using User Model and returning the response values created from that model object. But I want to make sure the record is inserted in the database after signing up the user.
Can I use assertDatabaseHas here or I have to use it with factory methods only?
/** @test **/
public function user_can_signup_for_an_account()
{
$this->withoutExceptionHandling();
$response = $this->postJson('/signup', [
'name' => 'User',
'email' => '[email protected]',
'password' => 'password',
'confirm_password' => 'password'
]);
$response->assertStatus(HttpStatuses::HTTP_CREATED);
$response->assertExactJson([
'success' => false,
'message' => 'User created successfully',
'user' => [
'name' => 'User',
'email' => '[email protected]',
]
]);
$this->assertDatabaseHas('users', [
'email' => '[email protected]',
]);
}