Add new tests for transformers.

This commit is contained in:
James Cole
2018-12-20 05:46:05 +01:00
parent c1ae0ab57d
commit 6f54f41946
8 changed files with 255 additions and 408 deletions

View File

@@ -308,6 +308,24 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return (int)$this->user->piggyBanks()->max('order');
}
/**
* Return note for piggy bank.
*
* @param PiggyBank $piggyBank
*
* @return string
*/
public function getNoteText(PiggyBank $piggyBank): string
{
/** @var Note $note */
$note = $piggyBank->notes()->first();
if (null === $note) {
return '';
}
return $note->text;
}
/**
* @return Collection
*/
@@ -381,6 +399,31 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $savePerMonth;
}
/**
* @param PiggyBankEvent $event
*
* @return int|null
*/
public function getTransactionWithEvent(PiggyBankEvent $event): ?int
{
$journal = $event->transactionJournal;
if (null === $journal) {
return null;
}
if ((float)$event->amount < 0) {
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
return $transaction->id ?? null;
}
if ((float)$event->amount > 0) {
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
return $transaction->id ?? null;
}
return null;
}
/**
* Get for piggy account what is left to put in piggies.
*