mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-19 16:10:00 +00:00
Improve test coverage and fix test code.
This commit is contained in:
@@ -1628,4 +1628,83 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a basic test because the store() tests cover everything.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$factory = $this->mock(CategoryFactory::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$factory->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('update')->once()->andReturn($recurrence);
|
||||
|
||||
|
||||
// used by the validator to find the source_id:
|
||||
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()->andReturn(new Collection([$assetAccount]));
|
||||
|
||||
|
||||
// entries used by the transformer
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Note text');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
// entries used by the transformer (the fake entry has a category + a budget):
|
||||
$factory->shouldReceive('findOrCreate')->andReturn(null);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
|
||||
// data to submit
|
||||
$firstDate = new Carbon;
|
||||
$firstDate->addDays(2);
|
||||
$data = [
|
||||
'type' => 'deposit',
|
||||
'title' => 'Hello',
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'apply_rules' => 1,
|
||||
'active' => 1,
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '100',
|
||||
'currency_id' => '1',
|
||||
'description' => 'Test description deposit',
|
||||
'source_name' => 'Some expense account',
|
||||
'destination_id' => '1',
|
||||
],
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => 'daily',
|
||||
'moment' => '',
|
||||
'skip' => '0',
|
||||
'weekend' => '1',
|
||||
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// test API
|
||||
$response = $this->put('/api/v1/recurrences/' . $recurrence->id, $data, ['Accept' => 'application/json']);
|
||||
$response->assertSee($recurrence->title);
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user