diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 180f6d870a..81fadc59dc 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -137,7 +137,7 @@ class JournalRepository implements JournalRepositoryInterface */ public function getWithDate($id, Carbon $date) { - return Auth::user()->transactionjournals()->where('id', $id)->where('date', $date->format('Y-m-d'))->first(); + return Auth::user()->transactionjournals()->where('id', $id)->where('date', $date->format('Y-m-d 00:00:00'))->first(); } /** diff --git a/tests/repositories/JournalRepositoryTest.php b/tests/repositories/JournalRepositoryTest.php index 69840beaef..6b99313a2b 100644 --- a/tests/repositories/JournalRepositoryTest.php +++ b/tests/repositories/JournalRepositoryTest.php @@ -1,5 +1,10 @@ markTestIncomplete( - 'This test has not been implemented yet.' - ); + $reminder = FactoryMuffin::create('FireflyIII\Models\Reminder'); + $reminder->active = 1; + $reminder->save(); + $this->be($reminder->user); + + $this->object->deactivateReminder($reminder->id); + + $this->assertEquals(1, Reminder::where('id', $reminder->id)->where('active', 0)->count()); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::delete - * @todo Implement testDelete(). */ public function testDelete() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $transaction = Transaction::create( + [ + 'account_id' => $account->id, + 'transaction_journal_id' => $journal->id, + 'amount' => 100, + ] ); + + $this->object->delete($journal); + + $this->assertEquals(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->count()); + $this->assertEquals(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->count()); + } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::first - * @todo Implement testFirst(). */ public function testFirst() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $this->be($journal->user); + + $first = $this->object->first(); + + $this->assertEquals($journal->id, $first->id); + } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::getAmountBefore - * @todo Implement testGetAmountBefore(). */ public function testGetAmountBefore() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $transaction = FactoryMuffin::create('FireflyIII\Models\Transaction'); + $before = $this->object->getAmountBefore($transaction->transactionjournal, $transaction); + + $this->assertEquals(0, $before); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfType - * @todo Implement testGetJournalsOfType(). */ public function testGetJournalsOfType() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $user = FactoryMuffin::create('FireflyIII\User'); + $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $this->be($user); + $result = $this->object->getJournalsOfType($type); + $this->assertCount(0, $result); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfTypes - * @todo Implement testGetJournalsOfTypes(). */ public function testGetJournalsOfTypes() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + $types = ['Withdrawal', 'Expense']; + $set = $this->object->getJournalsOfTypes($types, 0, 1); + + $this->assertTrue($set instanceof LengthAwarePaginator); + $this->assertEquals(1, $set->currentPage()); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::getTransactionType - * @todo Implement testGetTransactionType(). */ public function testGetTransactionType() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $otherType = $this->object->getTransactionType($type->type); + $this->assertEquals($type->id, $otherType->id); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::getWithDate - * @todo Implement testGetWithDate(). */ public function testGetWithDate() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $this->be($journal->user); + + $found = $this->object->getWithDate($journal->id, $journal->date); + + $this->assertEquals($journal->id, $found->id); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::saveTags - * @todo Implement testSaveTags(). */ public function testSaveTags() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); + $tags = ['one', 'two', 'three']; + $this->be($journal->user); + + $this->object->saveTags($journal, $tags); + + $this->assertCount(3, $journal->tags()->get()); } /** * @covers FireflyIII\Repositories\Journal\JournalRepository::store - * @todo Implement testStore(). + * @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts */ public function testStore() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + FactoryMuffin::create('FireflyIII\Models\TransactionType'); + $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + $budget = FactoryMuffin::create('FireflyIII\Models\Budget'); + $account1 = FactoryMuffin::create('FireflyIII\Models\Account'); + $user = FactoryMuffin::create('FireflyIII\User'); + $data = [ + 'description' => 'Some journal ' . rand(1, 100), + 'user' => $user->id, + 'what' => 'withdrawal', + 'amount_currency_id' => $currency->id, + 'account_id' => $account1->id, + 'expense_account' => 'Some expense account', + 'date' => '2014-01-01', + 'category' => 'Some category', + 'budget_id' => $budget->id, + 'amount' => 100, + 'tags' => ['one', 'two', 'three'] + + + ]; + + $journal = $this->object->store($data); + + $this->assertEquals($data['description'], $journal->description); } /**