Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/WalletsTest.php
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | public function testTransactions(): void | ||||
$this->assertSame(10, $json['count']); | $this->assertSame(10, $json['count']); | ||||
$this->assertSame(true, $json['hasMore']); | $this->assertSame(true, $json['hasMore']); | ||||
$this->assertCount(10, $json['list']); | $this->assertCount(10, $json['list']); | ||||
foreach ($pages[0] as $idx => $transaction) { | foreach ($pages[0] as $idx => $transaction) { | ||||
$this->assertSame($transaction->id, $json['list'][$idx]['id']); | $this->assertSame($transaction->id, $json['list'][$idx]['id']); | ||||
$this->assertSame($transaction->type, $json['list'][$idx]['type']); | $this->assertSame($transaction->type, $json['list'][$idx]['type']); | ||||
$this->assertSame($transaction->shortDescription(), $json['list'][$idx]['description']); | $this->assertSame($transaction->shortDescription(), $json['list'][$idx]['description']); | ||||
$this->assertFalse($json['list'][$idx]['hasDetails']); | $this->assertFalse($json['list'][$idx]['hasDetails']); | ||||
$this->assertFalse(array_key_exists('user', $json['list'][$idx])); | |||||
} | } | ||||
$search = null; | $search = null; | ||||
// Get the second page | // Get the second page | ||||
$response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions?page=2"); | $response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions?page=2"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(5, $json); | $this->assertCount(5, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame(2, $json['page']); | $this->assertSame(2, $json['page']); | ||||
$this->assertSame(2, $json['count']); | $this->assertSame(2, $json['count']); | ||||
$this->assertSame(false, $json['hasMore']); | $this->assertSame(false, $json['hasMore']); | ||||
$this->assertCount(2, $json['list']); | $this->assertCount(2, $json['list']); | ||||
foreach ($pages[1] as $idx => $transaction) { | foreach ($pages[1] as $idx => $transaction) { | ||||
$this->assertSame($transaction->id, $json['list'][$idx]['id']); | $this->assertSame($transaction->id, $json['list'][$idx]['id']); | ||||
$this->assertSame($transaction->type, $json['list'][$idx]['type']); | $this->assertSame($transaction->type, $json['list'][$idx]['type']); | ||||
$this->assertSame($transaction->shortDescription(), $json['list'][$idx]['description']); | $this->assertSame($transaction->shortDescription(), $json['list'][$idx]['description']); | ||||
$this->assertSame( | $this->assertSame( | ||||
$transaction->type == Transaction::WALLET_DEBIT, | $transaction->type == Transaction::WALLET_DEBIT, | ||||
$json['list'][$idx]['hasDetails'] | $json['list'][$idx]['hasDetails'] | ||||
); | ); | ||||
$this->assertFalse(array_key_exists('user', $json['list'][$idx])); | |||||
if ($transaction->type == Transaction::WALLET_DEBIT) { | if ($transaction->type == Transaction::WALLET_DEBIT) { | ||||
$search = $transaction->id; | $search = $transaction->id; | ||||
} | } | ||||
} | } | ||||
// Get a non-existing page | // Get a non-existing page | ||||
$response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions?page=3"); | $response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions?page=3"); | ||||
Show All 36 Lines |