Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/WalletsTest.php
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | public function testOneOff(): void | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertSame('The amount must be a number.', $json['errors']['amount'][0]); | $this->assertSame('The amount must be a number.', $json['errors']['amount'][0]); | ||||
$this->assertSame('The description field is required.', $json['errors']['description'][0]); | $this->assertSame('The description field is required.', $json['errors']['description'][0]); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertCount(2, $json['errors']); | $this->assertCount(2, $json['errors']); | ||||
// Admin user - a valid bonus | // Admin user - a valid bonus | ||||
$post = ['amount' => '50', 'description' => 'A bonus']; | $post = ['amount' => '17.40', 'description' => 'A bonus']; | ||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | $response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('The bonus has been added to the wallet successfully.', $json['message']); | $this->assertSame('The bonus has been added to the wallet successfully.', $json['message']); | ||||
$this->assertSame($balance += 5000, $json['balance']); | $this->assertSame($balance += 1740, $json['balance']); | ||||
$this->assertSame($balance, $wallet->fresh()->balance); | $this->assertSame($balance, $wallet->fresh()->balance); | ||||
$this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance); | $this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance); | ||||
$transaction = Transaction::where('object_id', $wallet->id) | $transaction = Transaction::where('object_id', $wallet->id) | ||||
->where('type', Transaction::WALLET_AWARD)->first(); | ->where('type', Transaction::WALLET_AWARD)->first(); | ||||
$this->assertSame($post['description'], $transaction->description); | $this->assertSame($post['description'], $transaction->description); | ||||
$this->assertSame(5000, $transaction->amount); | $this->assertSame(1740, $transaction->amount); | ||||
$this->assertSame($admin->email, $transaction->user_email); | $this->assertSame($admin->email, $transaction->user_email); | ||||
// Admin user - a valid penalty | // Admin user - a valid penalty | ||||
$post = ['amount' => '-40', 'description' => 'A penalty']; | $post = ['amount' => '-17.40', 'description' => 'A penalty']; | ||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | $response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('The penalty has been added to the wallet successfully.', $json['message']); | $this->assertSame('The penalty has been added to the wallet successfully.', $json['message']); | ||||
$this->assertSame($balance -= 4000, $json['balance']); | $this->assertSame($balance -= 1740, $json['balance']); | ||||
$this->assertSame($balance, $wallet->fresh()->balance); | $this->assertSame($balance, $wallet->fresh()->balance); | ||||
$this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance); | $this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance); | ||||
$transaction = Transaction::where('object_id', $wallet->id) | $transaction = Transaction::where('object_id', $wallet->id) | ||||
->where('type', Transaction::WALLET_PENALTY)->first(); | ->where('type', Transaction::WALLET_PENALTY)->first(); | ||||
$this->assertSame($post['description'], $transaction->description); | $this->assertSame($post['description'], $transaction->description); | ||||
$this->assertSame(-4000, $transaction->amount); | $this->assertSame(-1740, $transaction->amount); | ||||
$this->assertSame($admin->email, $transaction->user_email); | $this->assertSame($admin->email, $transaction->user_email); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching wallet transactions (GET /api/v4/wallets/:id/transactions) | * Test fetching wallet transactions (GET /api/v4/wallets/:id/transactions) | ||||
*/ | */ | ||||
public function testTransactions(): void | public function testTransactions(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |