mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-10 17:09:42 +00:00
Add some tests.
This commit is contained in:
42
tests/integration/Api/Chart/AccountControllerTest.php
Normal file
42
tests/integration/Api/Chart/AccountControllerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\integration\Api\Chart;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\integration\TestCase;
|
||||
|
||||
class AccountControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
private $user;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!isset($this->user)) {
|
||||
$this->user = $this->createAuthenticatedUser();
|
||||
}
|
||||
$this->actingAs($this->user);
|
||||
}
|
||||
|
||||
public function testGetOverviewChartFails(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$response = $this->getJson(route('api.v1.chart.account.overview'));
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
public function testGetOverviewChart(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$params = [
|
||||
'start' => '2024-01-01',
|
||||
'end' => '2024-01-31',
|
||||
];
|
||||
$response = $this->getJson(route('api.v1.chart.account.overview') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
||||
42
tests/integration/Api/Chart/BalanceControllerTest.php
Normal file
42
tests/integration/Api/Chart/BalanceControllerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\integration\Api\Chart;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\integration\TestCase;
|
||||
|
||||
class BalanceControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
private $user;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!isset($this->user)) {
|
||||
$this->user = $this->createAuthenticatedUser();
|
||||
}
|
||||
$this->actingAs($this->user);
|
||||
}
|
||||
|
||||
public function testGetOverviewChartFails(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$response = $this->getJson(route('api.v1.chart.balance.balance'));
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
public function testGetOverviewChart(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$params = [
|
||||
'start' => '2024-01-01',
|
||||
'end' => '2024-01-31',
|
||||
];
|
||||
$response = $this->getJson(route('api.v1.chart.balance.balance') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
||||
42
tests/integration/Api/Chart/BudgetControllerTest.php
Normal file
42
tests/integration/Api/Chart/BudgetControllerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\integration\Api\Chart;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\integration\TestCase;
|
||||
|
||||
class BudgetControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
private $user;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!isset($this->user)) {
|
||||
$this->user = $this->createAuthenticatedUser();
|
||||
}
|
||||
$this->actingAs($this->user);
|
||||
}
|
||||
|
||||
public function testGetOverviewChartFails(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$response = $this->getJson(route('api.v1.chart.budget.overview'));
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
public function testGetOverviewChart(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$params = [
|
||||
'start' => '2024-01-01',
|
||||
'end' => '2024-01-31',
|
||||
];
|
||||
$response = $this->getJson(route('api.v1.chart.budget.overview') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
||||
42
tests/integration/Api/Chart/CategoryControllerTest.php
Normal file
42
tests/integration/Api/Chart/CategoryControllerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\integration\Api\Chart;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\integration\TestCase;
|
||||
|
||||
class CategoryControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
private $user;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!isset($this->user)) {
|
||||
$this->user = $this->createAuthenticatedUser();
|
||||
}
|
||||
$this->actingAs($this->user);
|
||||
}
|
||||
|
||||
public function testGetOverviewChartFails(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$response = $this->getJson(route('api.v1.chart.category.overview'));
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
public function testGetOverviewChart(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
$params = [
|
||||
'start' => '2024-01-01',
|
||||
'end' => '2024-01-31',
|
||||
];
|
||||
$response = $this->getJson(route('api.v1.chart.category.overview') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\integration\Traits\CollectsValues;
|
||||
|
||||
/**
|
||||
@@ -42,7 +41,7 @@ abstract class TestCase extends BaseTestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
protected const MAX_ITERATIONS = 2;
|
||||
protected $seed = true;
|
||||
protected $seed = true;
|
||||
|
||||
public function dateRangeProvider(): array
|
||||
{
|
||||
@@ -57,15 +56,20 @@ abstract class TestCase extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
protected function getAuthenticatedUser(): User
|
||||
{
|
||||
return User::where('email', 'james@firefly')->first();
|
||||
}
|
||||
|
||||
protected function createAuthenticatedUser(): User
|
||||
{
|
||||
$group = UserGroup::create(['title' => 'test@email.com']);
|
||||
$role = UserRole::where('title', 'owner')->first();
|
||||
$user = User::create([
|
||||
'email' => 'test@email.com',
|
||||
'password' => 'password',
|
||||
'user_group_id' => $group->id,
|
||||
]);
|
||||
$role = UserRole::where('title', 'owner')->first();
|
||||
$user = User::create([
|
||||
'email' => 'test@email.com',
|
||||
'password' => 'password',
|
||||
'user_group_id' => $group->id,
|
||||
]);
|
||||
|
||||
GroupMembership::create(
|
||||
[
|
||||
@@ -76,8 +80,6 @@ abstract class TestCase extends BaseTestCase
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user