Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/WalletsTest.php
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | class WalletsTest extends TestCase | ||||
/** | /** | ||||
* Test fetching a wallet (GET /api/v4/wallets/:id) | * Test fetching a wallet (GET /api/v4/wallets/:id) | ||||
*/ | */ | ||||
public function testShow(): void | public function testShow(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->balance = -100; | |||||
$wallet->save(); | |||||
// Accessing a wallet of someone else | // Accessing a wallet of someone else | ||||
$response = $this->actingAs($jack)->get("api/v4/wallets/{$wallet->id}"); | $response = $this->actingAs($jack)->get("api/v4/wallets/{$wallet->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Accessing non-existing wallet | // Accessing non-existing wallet | ||||
$response = $this->actingAs($jack)->get("api/v4/wallets/aaa"); | $response = $this->actingAs($jack)->get("api/v4/wallets/aaa"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// Wallet owner | // Wallet owner | ||||
$response = $this->actingAs($john)->get("api/v4/wallets/{$wallet->id}"); | $response = $this->actingAs($john)->get("api/v4/wallets/{$wallet->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame($wallet->id, $json['id']); | $this->assertSame($wallet->id, $json['id']); | ||||
$this->assertSame('CHF', $json['currency']); | $this->assertSame('CHF', $json['currency']); | ||||
$this->assertSame($wallet->balance, $json['balance']); | $this->assertSame($wallet->balance, $json['balance']); | ||||
$this->assertTrue(empty($json['description'])); | $this->assertTrue(empty($json['description'])); | ||||
// TODO: This assertion does not work after a longer while from seeding | |||||
$this->assertTrue(!empty($json['notice'])); | $this->assertTrue(!empty($json['notice'])); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching wallet transactions | * Test fetching wallet transactions | ||||
*/ | */ | ||||
public function testTransactions(): void | public function testTransactions(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |