XiaTesting's avatar

How to test I get the same number of categories as same as the database

Here is my test, I use factory first to create some categories, then hit the endpoint /categories , but I don't know how to test if I get the same number of categories, and also in my test I am not approaching my $response from the endpoint.

public function test_it_can_retrive_list_of_categories()
{

    Category::factory()->count(5)->create();

    $response = $this->get('/categories');
    
    $this->assertDatabaseCount($this->table, 5); // Don't know how to test.

}

Any help would be appreciated

0 likes
2 replies
SilenceBringer's avatar

@xiatesting at least we need to know what '/categories' url returns. It's view with displayed categories? It's json object? How it's structured? Please, provide more details about endpoint response

Please or to participate in this conversation.