Fix tests.

This commit is contained in:
James Cole 2018-04-14 21:21:20 +02:00
parent 15a22f0bfc
commit 62b68c6a21
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 74 additions and 105 deletions

View File

@ -344,29 +344,6 @@ class BillRepository implements BillRepositoryInterface
return $set;
}
/**
* @param Bill $bill
*
* @return Collection
*/
public function getPossiblyRelatedJournals(Bill $bill): Collection
{
$set = new Collection(
DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)
->get(['transaction_journal_id'])
);
$ids = $set->pluck('transaction_journal_id')->toArray();
$journals = new Collection;
if (count($ids) > 0) {
$journals = $this->user->transactionJournals()->transactionTypes([TransactionType::WITHDRAWAL])->whereIn('transaction_journals.id', $ids)->get(
['transaction_journals.*']
);
}
return $journals;
}
/**
* Return all rules for one bill
*

View File

@ -133,13 +133,6 @@ interface BillRepositoryInterface
*/
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection;
/**
* @param Bill $bill
*
* @return Collection
*/
public function getPossiblyRelatedJournals(Bill $bill): Collection;
/**
* Return all rules for one bill
*

View File

@ -118,17 +118,18 @@ $factory->define(
FireflyIII\Models\Bill::class,
function (Faker\Generator $faker) {
return [
'created_at' => new Carbon,
'updated_at' => new Carbon,
'user_id' => 1,
'name' => $faker->words(3, true),
'match' => $faker->words(3, true),
'amount_min' => '100.00',
'amount_max' => '100.00',
'date' => '2017-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 1,
'created_at' => new Carbon,
'updated_at' => new Carbon,
'user_id' => 1,
'transaction_currency_id' => 1,
'name' => $faker->words(3, true),
'match' => $faker->words(3, true),
'amount_min' => '100.00',
'amount_max' => '100.00',
'date' => '2017-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 1,
];
}
);

View File

@ -140,6 +140,7 @@ class BillControllerTest extends TestCase
$repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
$repository->shouldReceive('getRulesForBills')->andReturn([]);
$this->be($this->user());
@ -159,10 +160,8 @@ class BillControllerTest extends TestCase
$journal = factory(TransactionJournal::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection([$journal]));
$repository->shouldReceive('scan')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('bills.rescan', [1]));
$response->assertStatus(302);
@ -199,6 +198,7 @@ class BillControllerTest extends TestCase
$repository->shouldReceive('getYearAverage')->andReturn('0');
$repository->shouldReceive('getOverallAverage')->andReturn('0');
$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
@ -235,15 +235,14 @@ class BillControllerTest extends TestCase
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
$data = [
'name' => 'New Bill ' . random_int(1000, 9999),
'match' => 'some words',
'amount_min' => '100',
'amount_currency_id_amount_min' => 1,
'amount_currency_id_amount_max' => 1,
'skip' => 0,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
'name' => 'New Bill ' . random_int(1000, 9999),
'amount_min' => '100',
'transaction_currency_id' => 1,
'skip' => 0,
'strict' => 1,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
];
$this->session(['bills.create.uri' => 'http://localhost']);
$this->be($this->user());
@ -271,10 +270,8 @@ class BillControllerTest extends TestCase
$data = [
'id' => 1,
'name' => 'Updated Bill ' . random_int(1000, 9999),
'match' => 'some more words',
'amount_min' => '100',
'amount_currency_id_amount_min' => 1,
'amount_currency_id_amount_max' => 1,
'transaction_currency_id' => 1,
'skip' => 0,
'amount_max' => '100',
'date' => '2016-01-01',

View File

@ -42,16 +42,16 @@ class BillFactoryTest extends TestCase
public function testCreateBasic()
{
$data = [
'name' => 'Some new bill #' . random_int(1, 1000),
'match' => 'i,am,word' . random_int(1, 1000),
'amount_min' => '5',
'amount_max' => '10',
'date' => '2018-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => true,
'active' => true,
'notes' => 'Hello!',
'name' => 'Some new bill #' . random_int(1, 1000),
'amount_min' => '5',
'transaction_currency_id' => 1,
'amount_max' => '10',
'date' => '2018-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => true,
'active' => true,
'notes' => 'Hello!',
];
/** @var BillFactory $factory */
@ -60,7 +60,6 @@ class BillFactoryTest extends TestCase
$bill = $factory->create($data);
$this->assertEquals($data['name'], $bill->name);
$this->assertEquals($data['match'], $bill->match);
$this->assertEquals($data['amount_min'], $bill->amount_min);
$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
$note = $bill->notes()->first();
@ -77,16 +76,16 @@ class BillFactoryTest extends TestCase
public function testCreateEmptyNotes()
{
$data = [
'name' => 'Some new bill #' . random_int(1, 1000),
'match' => 'i,am,word' . random_int(1, 1000),
'amount_min' => '5',
'amount_max' => '10',
'date' => '2018-01-01',
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => true,
'active' => true,
'notes' => '',
'name' => 'Some new bill #' . random_int(1, 1000),
'amount_min' => '5',
'amount_max' => '10',
'date' => '2018-01-01',
'repeat_freq' => 'monthly',
'transaction_currency_id' => 1,
'skip' => 0,
'automatch' => true,
'active' => true,
'notes' => '',
];
/** @var BillFactory $factory */
@ -95,7 +94,6 @@ class BillFactoryTest extends TestCase
$bill = $factory->create($data);
$this->assertEquals($data['name'], $bill->name);
$this->assertEquals($data['match'], $bill->match);
$this->assertEquals($data['amount_min'], $bill->amount_min);
$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
$this->assertEquals(0, $bill->notes()->count());

View File

@ -49,15 +49,16 @@ class BillTransformerTest extends TestCase
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'date' => '2018-01-02',
'repeat_freq' => 'weekly',
'skip' => 0,
'active' => 1,
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'transaction_currency_id' => 1,
'date' => '2018-01-02',
'repeat_freq' => 'weekly',
'skip' => 0,
'active' => 1,
]
);
$transformer = new BillTransformer(new ParameterBag);
@ -77,15 +78,16 @@ class BillTransformerTest extends TestCase
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'date' => '2018-01-02',
'repeat_freq' => 'weekly',
'skip' => 0,
'active' => 1,
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'date' => '2018-01-02',
'transaction_currency_id' => 1,
'repeat_freq' => 'weekly',
'skip' => 0,
'active' => 1,
]
);
$noteText = 'I are a note ' . random_int(1, 10000);
@ -121,15 +123,16 @@ class BillTransformerTest extends TestCase
$repository->shouldReceive('getPaidDatesInRange')->andReturn(new Collection([new Carbon('2018-01-02')]));
$bill = Bill::create(
[
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'date' => '2018-01-02',
'repeat_freq' => 'monthly',
'skip' => 0,
'active' => 1,
'user_id' => $this->user()->id,
'name' => 'Some bill ' . random_int(1, 10000),
'match' => 'word,' . random_int(1, 10000),
'amount_min' => 12.34,
'amount_max' => 45.67,
'date' => '2018-01-02',
'transaction_currency_id' => 1,
'repeat_freq' => 'monthly',
'skip' => 0,
'active' => 1,
]
);
$parameters = new ParameterBag();