mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* AccountControllerTest.php
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
*
|
|
* This file is part of Firefly III.
|
|
*
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Api\V1\Controllers;
|
|
|
|
use FireflyIII\Models\Account;
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
|
use Laravel\Passport\Passport;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class AccountControllerTest
|
|
*/
|
|
class AccountControllerTest extends TestCase
|
|
{
|
|
/**
|
|
*
|
|
*/
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
Passport::actingAs($this->user());
|
|
}
|
|
|
|
/**
|
|
* Destroy account over API.
|
|
*
|
|
* @covers \FireflyIII\Api\V1\Controllers\AccountController::delete
|
|
*/
|
|
public function testDestroy()
|
|
{
|
|
// mock stuff:
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
// mock calls:
|
|
$repository->shouldReceive('setUser')->once();
|
|
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
|
$currencyRepos->shouldReceive('setUser')->once();
|
|
|
|
// get account:
|
|
$account = $this->user()->accounts()->first();
|
|
|
|
// call API
|
|
$response = $this->delete('/api/v1/accounts/' . $account->id);
|
|
$response->assertStatus(204);
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers \FireflyIII\Api\V1\Controllers\AccountController::__construct
|
|
* @covers \FireflyIII\Api\V1\Controllers\AccountController::index
|
|
*/
|
|
public function testIndex()
|
|
{
|
|
// create stuff
|
|
$accounts = factory(Account::class, 10)->create();
|
|
|
|
// mock stuff:
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
// mock calls:
|
|
$repository->shouldReceive('setUser')->once();
|
|
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($accounts)->once();
|
|
$currencyRepos->shouldReceive('setUser')->once();
|
|
|
|
// test API
|
|
$response = $this->get('/api/v1/accounts');
|
|
$response->assertStatus(200);
|
|
$response->assertJson(['data' => [],]);
|
|
$response->assertJson(['meta' => ['pagination' => ['total' => 10, 'count' => 10, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
|
$response->assertJson(
|
|
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
|
);
|
|
$response->assertSee('type=all'); // default returns this.
|
|
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
|
}
|
|
|
|
|
|
} |