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\Payment; | use App\Payment; | ||||
use App\Providers\PaymentProvider; | use App\Providers\PaymentProvider; | ||||
use Illuminate\Support\Facades\DB; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class StatsTest extends TestCase | class StatsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
Payment::truncate(); | Payment::truncate(); | ||||
DB::table('wallets')->update(['discount_id' => null]); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
Payment::truncate(); | Payment::truncate(); | ||||
DB::table('wallets')->update(['discount_id' => null]); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test charts (GET /api/v4/stats/chart/<chart>) | * Test charts (GET /api/v4/stats/chart/<chart>) | ||||
*/ | */ | ||||
public function testChart(): void | public function testChart(): void | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public function testChart(): void | ||||
$response = $this->actingAs($admin)->get("api/v4/stats/chart/users-all"); | $response = $this->actingAs($admin)->get("api/v4/stats/chart/users-all"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('All Users - last year', $json['title']); | $this->assertSame('All Users - last year', $json['title']); | ||||
$this->assertCount(54, $json['data']['labels']); | $this->assertCount(54, $json['data']['labels']); | ||||
$this->assertCount(1, $json['data']['datasets']); | $this->assertCount(1, $json['data']['datasets']); | ||||
// 'vouchers' chart | |||||
$discount = \App\Discount::withObjectTenantContext($user)->where('code', 'TEST')->first(); | |||||
$wallet = $user->wallets->first(); | |||||
$wallet->discount()->associate($discount); | |||||
$wallet->save(); | |||||
$response = $this->actingAs($admin)->get("api/v4/stats/chart/vouchers"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('Vouchers', $json['title']); | |||||
$this->assertSame(['TEST'], $json['data']['labels']); | |||||
$this->assertSame([['values' => [1]]], $json['data']['datasets']); | |||||
} | } | ||||
/** | /** | ||||
* Test income chart currency handling | * Test income chart currency handling | ||||
*/ | */ | ||||
public function testChartIncomeCurrency(): void | public function testChartIncomeCurrency(): void | ||||
{ | { | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |