I'm a beginner in the area of testing and I would like to know why is this not working:
public function testUserDoesntGetDuplicatedKey()
{
$this->withoutMiddleware();
\App\User::truncate();
$users = factory(\App\User::class, 10)->create()->each(function ($user){
$user->country()->save(factory(\App\UsersCountry::class)->create());
});
foreach($users as $user){
$this->actingAs($user)
->visit('giveaway/1b29f33b-4387-32c3-acab-d9e023de4d4c')
->click('btnGetKeyTesting');
}
dd(\App\UserKeys::count());
$this->assertTrue(\App\UserKeys::count() == 10);
}
The steps that I'm trying to reproduce is:
1 - User gets to the page giveaway/1b29f33b-4387-32c3-acab-d9e023de4d4c
2 - Click the button "btnGetKeyTesting"
3 - A call is made to /ajax/keyManagement/getKeyGiveaway
4 - In this call the following happens
4.1 - Get the key
4.2 - Insert into table users_keys the key and the user who got the key
When I make the dd(\App\UserKeys::count()) it returns 0 which should return 10 since I'm creating 10 users. What is missing to me here?