Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/StatsTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller\Admin; | namespace Tests\Feature\Controller\Admin; | ||||
use App\Http\Controllers\API\V4\Admin\StatsController; | |||||
use App\Payment; | use App\Payment; | ||||
use App\Providers\PaymentProvider; | use App\Providers\PaymentProvider; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class StatsTest extends TestCase | class StatsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | public function testChartIncomeCurrency(): void | ||||
$this->assertSame(date('Y-W'), $json['data']['labels'][7]); | $this->assertSame(date('Y-W'), $json['data']['labels'][7]); | ||||
// 7000 CHF + 3000 EUR = | // 7000 CHF + 3000 EUR = | ||||
$expected = 7000 + intval(round(3000 * \App\Utils::exchangeRate('EUR', 'CHF'))); | $expected = 7000 + intval(round(3000 * \App\Utils::exchangeRate('EUR', 'CHF'))); | ||||
$this->assertCount(1, $json['data']['datasets']); | $this->assertCount(1, $json['data']['datasets']); | ||||
$this->assertSame($expected / 100, $json['data']['datasets'][0]['values'][7]); | $this->assertSame($expected / 100, $json['data']['datasets'][0]['values'][7]); | ||||
} | } | ||||
/** | |||||
* Test payers chart | |||||
*/ | |||||
public function testChartPayers(): void | |||||
{ | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
DB::table('stats')->truncate(); | |||||
$response = $this->actingAs($admin)->get("api/v4/stats/chart/payers"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('Payers - last year', $json['title']); | |||||
$this->assertSame('line', $json['type']); | |||||
$this->assertCount(54, $json['data']['labels']); | |||||
$this->assertSame(date('Y-W'), $json['data']['labels'][53]); | |||||
$this->assertCount(1, $json['data']['datasets']); | |||||
$this->assertCount(54, $json['data']['datasets'][0]['values']); | |||||
DB::table('stats')->insert([ | |||||
'type' => StatsController::TYPE_PAYERS, | |||||
'value' => 5, | |||||
'created_at' => \now(), | |||||
]); | |||||
DB::table('stats')->insert([ | |||||
'type' => StatsController::TYPE_PAYERS, | |||||
'value' => 7, | |||||
'created_at' => \now(), | |||||
]); | |||||
$response = $this->actingAs($admin)->get("api/v4/stats/chart/payers"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(6, $json['data']['datasets'][0]['values'][53]); | |||||
} | |||||
} | } |