diff --git a/tests/Api/V1/Controllers/AboutControllerTest.php b/tests/Api/V1/Controllers/AboutControllerTest.php new file mode 100644 index 0000000000..5d73971fd1 --- /dev/null +++ b/tests/Api/V1/Controllers/AboutControllerTest.php @@ -0,0 +1,78 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Api\V1\Controllers; + +use FireflyIII\Transformers\UserTransformer; +use Laravel\Passport\Passport; +use Tests\TestCase; + +/** + * Class AboutControllerTest + */ +class AboutControllerTest extends TestCase +{ + /** + * Set up test + */ + public function setUp() + { + parent::setUp(); + Passport::actingAs($this->user()); + } + + /** + * Test the about endpoint + * + * @covers \FireflyIII\Api\V1\Controllers\AboutController::__construct + * @covers \FireflyIII\Api\V1\Controllers\AboutController::about + */ + public function testAbout() + { + // test API + $response = $this->get('/api/v1/about'); + $response->assertStatus(200); + $response->assertJson( + ['data' => [ + 'version' => true, + 'api_version' => true, + 'php_version' => true, + ]] + ); + } + + /** + * Test user end point + * @covers \FireflyIII\Api\V1\Controllers\AboutController::user + */ + public function testUser() + { + // test API + $response = $this->get('/api/v1/about/user'); + $response->assertStatus(200); + $response->assertJson(['data' => ['attributes' => true, 'links' => true]]); + $this->assertEquals($this->user()->id, $response->json()['data']['id']); + } + + +} \ No newline at end of file diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.php new file mode 100644 index 0000000000..1dfb8489c8 --- /dev/null +++ b/tests/Api/V1/Controllers/AccountControllerTest.php @@ -0,0 +1,101 @@ +. + */ + +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'); + } + + +} \ No newline at end of file