Fix finding expenses call #130
This commit is contained in:
18
app/Database/factories/ExpenseFactory.php
Normal file
18
app/Database/factories/ExpenseFactory.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Enums\ExpenseType;
|
||||||
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
|
$factory->define(App\Models\Expense::class, function (Faker $faker) {
|
||||||
|
return [
|
||||||
|
'id' => null,
|
||||||
|
'airline_id' => function () {
|
||||||
|
return factory(App\Models\Airline::class)->create()->id;
|
||||||
|
},
|
||||||
|
'name' => $faker->text(20),
|
||||||
|
'amount' => $faker->randomFloat(2, 100, 1000),
|
||||||
|
'type' => ExpenseType::FLIGHT,
|
||||||
|
'multiplier' => false,
|
||||||
|
'active' => true,
|
||||||
|
];
|
||||||
|
});
|
||||||
@@ -30,6 +30,7 @@ class ExpenseRepository extends BaseRepository implements CacheableInterface
|
|||||||
{
|
{
|
||||||
$expenses = $this->findWhere([
|
$expenses = $this->findWhere([
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
|
['airline_id', '=', null]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if($airline_id) {
|
if($airline_id) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Enums\ExpenseType;
|
||||||
|
use App\Repositories\ExpenseRepository;
|
||||||
use App\Services\PIREPService;
|
use App\Services\PIREPService;
|
||||||
use App\Repositories\JournalRepository;
|
use App\Repositories\JournalRepository;
|
||||||
use App\Services\FareService;
|
use App\Services\FareService;
|
||||||
@@ -10,7 +12,8 @@ use App\Support\Money;
|
|||||||
|
|
||||||
class FinanceTest extends TestCase
|
class FinanceTest extends TestCase
|
||||||
{
|
{
|
||||||
private $fareSvc,
|
private $expenseRepo,
|
||||||
|
$fareSvc,
|
||||||
$financeSvc,
|
$financeSvc,
|
||||||
$fleetSvc,
|
$fleetSvc,
|
||||||
$pirepSvc;
|
$pirepSvc;
|
||||||
@@ -23,6 +26,7 @@ class FinanceTest extends TestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->addData('base');
|
$this->addData('base');
|
||||||
|
|
||||||
|
$this->expenseRepo = app(ExpenseRepository::class);
|
||||||
$this->fareSvc = app(FareService::class);
|
$this->fareSvc = app(FareService::class);
|
||||||
$this->financeSvc = app(FinanceService::class);
|
$this->financeSvc = app(FinanceService::class);
|
||||||
$this->fleetSvc = app(FleetService::class);
|
$this->fleetSvc = app(FleetService::class);
|
||||||
@@ -546,6 +550,41 @@ class FinanceTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that all expenses are pulled properly
|
||||||
|
*/
|
||||||
|
public function testPirepExpenses()
|
||||||
|
{
|
||||||
|
$airline = factory(App\Models\Airline::class)->create();
|
||||||
|
$airline2 = factory(App\Models\Airline::class)->create();
|
||||||
|
|
||||||
|
factory(App\Models\Expense::class)->create([
|
||||||
|
'airline_id' => $airline->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
factory(App\Models\Expense::class)->create([
|
||||||
|
'airline_id' => $airline2->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
factory(App\Models\Expense::class)->create([
|
||||||
|
'airline_id' => null
|
||||||
|
]);
|
||||||
|
|
||||||
|
$expenses = $this->expenseRepo
|
||||||
|
->getAllForType(ExpenseType::FLIGHT, $airline->id);
|
||||||
|
|
||||||
|
$this->assertCount(2, $expenses);
|
||||||
|
|
||||||
|
$found = $expenses->where('airline_id', null);
|
||||||
|
$this->assertCount(1, $found);
|
||||||
|
|
||||||
|
$found = $expenses->where('airline_id', $airline->id);
|
||||||
|
$this->assertCount(1, $found);
|
||||||
|
|
||||||
|
$found = $expenses->where('airline_id', $airline2->id);
|
||||||
|
$this->assertCount(0, $found);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
Reference in New Issue
Block a user