I am trying to delete a blog post and make a delete post also but facing a error during testing. I found the deleted_at is missing in blog_posts table but i have added soft delete in migration with new migration class The error is:
There was 1 failure:
- Tests\Feature\PostTest::test_delete
Failed asserting that any soft deleted row in the table [blog_posts] matches the attributes {"title":"New title","content":"Content of the blog post","user_id":1,"updated_at":"2023-07-04T14:12:31.000000Z","created_at":"2023-07-04T14:12:31.000000Z","id":1}.
Found: [
{
"id": 1,
"title": "New title",
"content": "Content of the blog post",
"created_at": "2023-07-04 14:12:31",
"updated_at": "2023-07-04 14:12:31",
"user_id": 1,
"deleted_at": "2023-07-04 14:12:31"
}
].
my post test class is postTest.php to delete test:
public function test_delete()
{
$user = $this->user();
$post = $this->createDummyBlogPost($user->id);
$data = $post->toArray();
$this->assertDatabaseHas('blog_posts', [
'title' => $data['title'],
'content' => $data['content']
]);
$this->actingAs($user)
->delete("/posts/{$post->id}")
->assertStatus(302)
->assertSessionHas('status');
$this->assertEquals(session('status'), 'Blog post was deleted!');
$this->assertSoftDeleted('blog_posts', $post->toArray());
}