Hi @bobbybouwmann
There were definitely some issues with the expected model. After type hinting the Bid $winning in the constructor of Notification::class I realized it was expecting a Job not a Bid. So, got that straightened out.
Still not able to get the command to process properly. the logic $this->deadlineExpired(); never processes anything.
I found this post: https://github.com/laravel/framework/issues/17778 towards the bottom it shows pulling the latest user - I think I was grabbing the wrong user.
If the notifications are sent manually the test passes...
/** @test */
public function job_bidded_email_was_sent_to_winning_bidder_and_losing_bidders()
{
$this->withoutExceptionHandling();
Notification::fake();
Notification::assertNothingSent();
// Queue::fake();
// Queue::assertNothingPushed();
$user = factory(User::class)->create([
'email' => '[email protected]'
]);
$user2 = factory(User::class)->create([
'email' => '[email protected]'
]);
$user3 = factory(User::class)->create([
'email' => '[email protected]'
]);
$user4 = factory(User::class)->create([
'email' => '[email protected]'
]);
$this->actingAs($user);
$job = factory(SlugJob::class)->create([
'user_id' => $user->id
]);
// dd($user2->id);
$winningBid = factory(Bid::class)->create([
'user_id' => $user2->id,
'job_id' => $job->id,
'bid' => 250000
]);
$losingBid = factory(Bid::class)->create([
'user_id' => $user3->id,
'job_id' => $job->id,
'bid' => 300000
]);
$losingBid2 = factory(Bid::class)->create([
'user_id' => $user4->id,
'job_id' => $job->id,
'bid' => 350000
]);
// dd($losingBid2->job->id);
$this->assertDatabaseHas('jobs', [
'id' => $job->id,
'bidded' => 0
]);
$this->assertDatabaseHas('bids', [
'id' => $winningBid->id,
'bid' => 250000,
'id' => $losingBid->id,
'bid' => 300000,
'id' => $losingBid2->id,
'bid' => 350000,
]);
$this->assertDatabaseHas('users', [
'email' => '[email protected]',
'email' => '[email protected]',
'email' => '[email protected]',
'email' => '[email protected]'
]);
// $this->deadlineExpired();
// dd($losingBid2->user);
$winningBid->user->notify(new SendJobBiddedWinningBidderNotified($winningBid));
$job->user->notify(new SendJobBiddedBuyerNotified($job));
$losingBid->user->notify(new SendJobBiddedLosingBiddersNotified($losingBid));
$losingBid2->user->notify(new SendJobBiddedLosingBiddersNotified($losingBid2));
Notification::assertSentTo(User::latest()->first(), SendJobBiddedBuyerNotified::class);
// also works Notification::assertSentTo(User::find(1), SendJobBiddedBuyerNotified::class);
Notification::assertSentTo(User::find(2), SendJobBiddedWinningBidderNotified::class);
Notification::assertSentTo(User::find(3), SendJobBiddedLosingBiddersNotified::class);
Notification::assertSentTo(User::find(4), SendJobBiddedLosingBiddersNotified::class);
// so the above does yield a passing test
Time: 484 ms, Memory: 32.00 MB
OK (1 test, 8 assertions)
Would you worry about the console command not working in the context of a test?