mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-25 10:20:29 -06:00
Improve code coverage for rules.
This commit is contained in:
parent
c02ab6f6d8
commit
d95544d588
@ -269,6 +269,64 @@ class RuleControllerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testMoveRuleDown(): void
|
||||
{
|
||||
/** @var Rule $rule */
|
||||
$rule = $this->user()->rules()->first();
|
||||
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('find')->once()->andReturn($rule);
|
||||
$ruleRepos->shouldReceive('moveDown')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.rules.down', [$rule->id]), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testMoveRuleUp(): void
|
||||
{
|
||||
/** @var Rule $rule */
|
||||
$rule = $this->user()->rules()->first();
|
||||
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('find')->once()->andReturn($rule);
|
||||
$ruleRepos->shouldReceive('moveUp')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.rules.up', [$rule->id]), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RuleRequest
|
||||
@ -317,7 +375,7 @@ class RuleControllerTest extends TestCase
|
||||
$ruleRepos->shouldReceive('update')->once()->andReturn($rule);
|
||||
|
||||
// test API
|
||||
$response = $this->put('/api/v1/rules/' . $rule->id, $data, ['Accept' => 'application/json']);
|
||||
$response = $this->put(route('api.v1.rules.update', [$rule->id]), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
@ -26,11 +26,15 @@ namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||
use FireflyIII\Jobs\Job;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\TransactionMatcher;
|
||||
use FireflyIII\Transformers\RuleGroupTransformer;
|
||||
use FireflyIII\Transformers\RuleTransformer;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
@ -218,9 +222,69 @@ class RuleGroupControllerTest extends TestCase
|
||||
$ruleGroupRepos->shouldReceive('update')->once()->andReturn($ruleGroup);
|
||||
|
||||
// test API
|
||||
$response = $this->put('/api/v1/rule_groups/' . $ruleGroup->id, $data, ['Accept' => 'application/json']);
|
||||
$response = $this->put(route('api.v1.rule_groups.update', [$ruleGroup->id]), $data, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testMoveRuleGroupDown(): void
|
||||
{
|
||||
/** @var RuleGroup $group */
|
||||
$group = $this->user()->ruleGroups()->first();
|
||||
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('find')->once()->andReturn($group);
|
||||
$ruleGroupRepos->shouldReceive('moveDown')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.rule_groups.down', [$group->id]), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testMoveRuleGroupUp(): void
|
||||
{
|
||||
/** @var RuleGroup $group */
|
||||
$group = $this->user()->ruleGroups()->first();
|
||||
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('find')->once()->andReturn($group);
|
||||
$ruleGroupRepos->shouldReceive('moveUp')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.rule_groups.up', [$group->id]), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user