Fix tests

This commit is contained in:
James Cole
2019-08-04 11:12:24 +02:00
parent 62b5cf04ad
commit 2147caf3ef
5 changed files with 33 additions and 10 deletions

View File

@@ -438,7 +438,9 @@ class ProfileController extends Controller
app('preferences')->mark();
// make sure MFA is logged out.
Google2FA::logout();
if ('testing' !== config('app.env')) {
Google2FA::logout();
}
return redirect(route('profile.index'));
}

View File

@@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers;
use Amount;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Google2FA;
@@ -97,6 +98,8 @@ class ProfileControllerTest extends TestCase
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
// set recovery codes.
Preferences::shouldReceive('set')->withArgs(['mfa_recovery', Mockery::any()])->atLeast()->once();
Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');
Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');
@@ -168,6 +171,9 @@ class ProfileControllerTest extends TestCase
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), null])->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('profile.delete-code'));
$response->assertStatus(302);
@@ -199,12 +205,14 @@ class ProfileControllerTest extends TestCase
//$this->mockDefaultSession(); // DISABLED ON PURPOSE
$this->mockDefaultConfiguration();
$repository = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->andReturnNull();
$euro = $this->getEuro();
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
Preferences::shouldReceive('set')->once()->withArgs(['twoFactorAuthEnabled', 1]);
$view = new Preference;
$view->data = '1M';
Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view)->atLeast()->once();
@@ -224,7 +232,7 @@ class ProfileControllerTest extends TestCase
$this->be($this->user());
$response = $this->post(route('profile.enable2FA'));
$response->assertStatus(302);
$response->assertRedirect(route('profile.index'));
$response->assertRedirect(route('profile.code'));
}
/**
@@ -241,8 +249,14 @@ class ProfileControllerTest extends TestCase
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturn($pref);
$arrayPref = new Preference;
$arrayPref->data = [];
Preferences::shouldReceive('get')->withArgs(['mfa_recovery', []])->atLeast()->once()->andReturn($arrayPref);
Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
$this->be($this->user());
@@ -268,6 +282,10 @@ class ProfileControllerTest extends TestCase
Preferences::shouldReceive('get')->withArgs(['access_token', null])->atLeast()->once()->andReturnNull();
Preferences::shouldReceive('set')->withArgs(['access_token', Mockery::any()])->atLeast()->once()->andReturn($pref);
$arrayPref = new Preference;
$arrayPref->data = [];
Preferences::shouldReceive('get')->withArgs(['mfa_recovery', []])->atLeast()->once()->andReturn($arrayPref);
Preferences::shouldReceive('getForUser')->withArgs(['xxx'])->andReturn($pref);
$this->be($this->user());
@@ -417,7 +435,7 @@ class ProfileControllerTest extends TestCase
*/
public function testPostCode(): void
{
$this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
Log::info(sprintf('Now in test %s.', __METHOD__));
$this->mockDefaultSession();
@@ -428,6 +446,8 @@ class ProfileControllerTest extends TestCase
$this->withoutMiddleware();
$this->session(['two-factor-secret' => $secret]);
$userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), $secret])->atLeast()->once();
Preferences::shouldReceive('mark')->once();
Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);

View File

@@ -62,7 +62,7 @@ class TagFactoryTest extends TestCase
*/
public function testFindOrCreateNew(): void
{
$tag = sprintf('Some new tag #%d', $this->randomInt());
$tag = sprintf('§Some new tag #%d', $this->randomInt());
/** @var TagFactory $factory */
$factory = app(TagFactory::class);
$factory->setUser($this->user());

View File

@@ -58,8 +58,10 @@ class ConvertToTransferTest extends TestCase
public function testActDeposit(): void
{
$deposit = $this->getRandomDeposit();
/** @var Account $asset */
$asset = $this->getRandomAsset();
// make sure that $asset is not the destination account of $deposit:
$forbiddenId = (int)$deposit->transactions()->where('amount', '>', 0)->first()->account_id;
$asset = $this->getRandomAsset($forbiddenId);
// mock used stuff:
$accountRepos = $this->mock(AccountRepositoryInterface::class);

View File

@@ -64,7 +64,6 @@ class RecurrenceTransformerTest extends TestCase
$budget = $this->getRandomBudget();
$piggy = $this->getRandomPiggyBank();
$bill = $this->getRandomBill();
$foreignCurrency = $this->getDollar();
$ranges = [new Carbon];
$recurrence = $this->getRandomRecurrence();
// mock calls:
@@ -91,7 +90,7 @@ class RecurrenceTransformerTest extends TestCase
$result = $transformer->transform($recurrence);
$this->assertEquals($recurrence->id, $result['id']);
$this->assertEquals('withdrawal', $result['transaction_type']);
//$this->assertEquals('deposit', $result['transaction_type']);
$this->assertEquals(true, $result['apply_rules']);
$this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);