Skip to content

Commit

Permalink
Test jobs responsible for fetching conversion rates
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Dec 26, 2023
1 parent 4744ca7 commit 827c878
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/Unit/Jobs/FetchConversionRateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Tests\Unit\Jobs;

use App\Jobs\FetchConversionRate;
use App\Models\ConversionRate;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;

class FetchConversionRateTest extends TestCase
{
public function testWhetherIndividualJobsGetDispatched(): void
{
Queue::fake();

$this->assertDatabaseEmpty(ConversionRate::class);

app()->call([new FetchConversionRate(1), 'handle']);

$this->assertDatabaseHas(
ConversionRate::class,
[
'base_currency_id' => 1,
'target_currency_id' => 2,
],
);

$this->assertDatabaseHas(
ConversionRate::class,
[
'base_currency_id' => 1,
'target_currency_id' => 3,
],
);

// etc.
}
}
23 changes: 23 additions & 0 deletions tests/Unit/Jobs/FetchConversionRatesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Unit\Jobs;

use App\Jobs\FetchConversionRate;
use App\Jobs\FetchConversionRates;
use App\Models\Currency;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;

class FetchConversionRatesTest extends TestCase
{
public function testWhetherIndividualJobsGetDispatched(): void
{
Queue::fake();

Queue::assertNothingPushed();

app()->call([new FetchConversionRates(), 'handle']);

Queue::assertPushed(FetchConversionRate::class);
}
}

0 comments on commit 827c878

Please sign in to comment.