Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/WalletsTest.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$this->assertTrue(empty($json['description'])); | $this->assertTrue(empty($json['description'])); | ||||
$this->assertTrue(empty($json['discount_description'])); | $this->assertTrue(empty($json['discount_description'])); | ||||
$this->assertTrue(!empty($json['provider'])); | $this->assertTrue(!empty($json['provider'])); | ||||
$this->assertTrue(!empty($json['providerLink'])); | $this->assertTrue(!empty($json['providerLink'])); | ||||
$this->assertTrue(!empty($json['mandate'])); | $this->assertTrue(!empty($json['mandate'])); | ||||
} | } | ||||
/** | /** | ||||
* Test awarding/penalizing a wallet (POST /api/v4/wallets/:id/one-off) | |||||
*/ | |||||
public function testOneOff(): void | |||||
{ | |||||
$user = $this->getTestUser('john@kolab.org'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
$wallet = $user->wallets()->first(); | |||||
$balance = $wallet->balance; | |||||
// Non-admin user | |||||
$response = $this->actingAs($user)->post("api/v4/wallets/{$wallet->id}/one-off", []); | |||||
$response->assertStatus(403); | |||||
// Admin user - invalid input | |||||
$post = ['amount' => 'aaaa']; | |||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame('The amount must be a number.', $json['errors']['amount'][0]); | |||||
$this->assertSame('The description field is required.', $json['errors']['description'][0]); | |||||
$this->assertCount(2, $json); | |||||
$this->assertCount(2, $json['errors']); | |||||
// Admin user - a valid bonus | |||||
$post = ['amount' => '50', 'description' => 'A bonus']; | |||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame('The bonus has been added to the wallet successfully.', $json['message']); | |||||
$this->assertSame($balance += 5000, $json['balance']); | |||||
// Admin user - a valid penalty | |||||
$post = ['amount' => '-40', 'description' => 'A penalty']; | |||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame('The penalty has been added to the wallet successfully.', $json['message']); | |||||
$this->assertSame($balance -= 4000, $json['balance']); | |||||
} | |||||
/** | |||||
* Test updating a wallet (PUT /api/v4/wallets/:id) | * Test updating a wallet (PUT /api/v4/wallets/:id) | ||||
*/ | */ | ||||
public function testUpdate(): void | public function testUpdate(): void | ||||
{ | { | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$discount = Discount::where('code', 'TEST')->first(); | $discount = Discount::where('code', 'TEST')->first(); | ||||
Show All 35 Lines |