Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Reseller/WalletsTest.php
Show All 32 Lines | class WalletsTest extends TestCase | ||||
* @group stripe | * @group stripe | ||||
*/ | */ | ||||
public function testShow(): void | public function testShow(): void | ||||
{ | { | ||||
\config(['services.payment_provider' => 'stripe']); | \config(['services.payment_provider' => 'stripe']); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount_id = null; | $wallet->discount_id = null; | ||||
$wallet->save(); | $wallet->save(); | ||||
// Make sure there's no stripe/mollie identifiers | // Make sure there's no stripe/mollie identifiers | ||||
$wallet->setSetting('stripe_id', null); | $wallet->setSetting('stripe_id', null); | ||||
$wallet->setSetting('stripe_mandate_id', null); | $wallet->setSetting('stripe_mandate_id', null); | ||||
$wallet->setSetting('mollie_id', null); | $wallet->setSetting('mollie_id', null); | ||||
Show All 36 Lines | class WalletsTest extends TestCase | ||||
/** | /** | ||||
* Test awarding/penalizing a wallet (POST /api/v4/wallets/:id/one-off) | * Test awarding/penalizing a wallet (POST /api/v4/wallets/:id/one-off) | ||||
*/ | */ | ||||
public function testOneOff(): void | public function testOneOff(): 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'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$reseller1_wallet = $reseller1->wallets()->first(); | $reseller1_wallet = $reseller1->wallets()->first(); | ||||
$balance = $wallet->balance; | $balance = $wallet->balance; | ||||
$reseller1_balance = $reseller1_wallet->balance; | $reseller1_balance = $reseller1_wallet->balance; | ||||
Transaction::where('object_id', $wallet->id) | Transaction::where('object_id', $wallet->id) | ||||
->whereIn('type', [Transaction::WALLET_AWARD, Transaction::WALLET_PENALTY]) | ->whereIn('type', [Transaction::WALLET_AWARD, Transaction::WALLET_PENALTY]) | ||||
->delete(); | ->delete(); | ||||
Transaction::where('object_id', $reseller1_wallet->id)->delete(); | Transaction::where('object_id', $reseller1_wallet->id)->delete(); | ||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->post("api/v4/wallets/{$wallet->id}/one-off", []); | $response = $this->actingAs($user)->post("api/v4/wallets/{$wallet->id}/one-off", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin user | // Admin user | ||||
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", []); | $response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Reseller from a different tenant | // Reseller from a different tenant | ||||
$response = $this->actingAs($reseller2)->post("api/v4/wallets/{$wallet->id}/one-off", []); | $response = $this->actingAs($reseller2)->post("api/v4/wallets/{$wallet->id}/one-off", []); | ||||
$response->assertStatus(403); | $response->assertStatus(404); | ||||
// Admin user - invalid input | // Admin user - invalid input | ||||
$post = ['amount' => 'aaaa']; | $post = ['amount' => 'aaaa']; | ||||
$response = $this->actingAs($reseller1)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | $response = $this->actingAs($reseller1)->post("api/v4/wallets/{$wallet->id}/one-off", $post); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public function testTransactions(): void | ||||
// Note: Here we're testing only that the end-point works, | // Note: Here we're testing only that the end-point works, | ||||
// and admin can get the transaction log, response details | // and admin can get the transaction log, response details | ||||
// are tested in Feature/Controller/WalletsTest.php | // are tested in Feature/Controller/WalletsTest.php | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | $this->deleteTestUser('wallets-controller@kolabnow.com'); | ||||
$user = $this->getTestUser('wallets-controller@kolabnow.com'); | $user = $this->getTestUser('wallets-controller@kolabnow.com'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
// Non-admin | // Non-admin | ||||
$response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions"); | $response = $this->actingAs($user)->get("api/v4/wallets/{$wallet->id}/transactions"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin | // Admin | ||||
$response = $this->actingAs($admin)->get("api/v4/wallets/{$wallet->id}/transactions"); | $response = $this->actingAs($admin)->get("api/v4/wallets/{$wallet->id}/transactions"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 37 Lines | class WalletsTest extends TestCase | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
{ | { | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$discount = Discount::where('code', 'TEST')->first(); | $discount = Discount::where('code', 'TEST')->first(); | ||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->put("api/v4/wallets/{$wallet->id}", []); | $response = $this->actingAs($user)->put("api/v4/wallets/{$wallet->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin | // Admin | ||||
$response = $this->actingAs($admin)->put("api/v4/wallets/{$wallet->id}", []); | $response = $this->actingAs($admin)->put("api/v4/wallets/{$wallet->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Reseller from another tenant | // Reseller from another tenant | ||||
$response = $this->actingAs($reseller2)->put("api/v4/wallets/{$wallet->id}", []); | $response = $this->actingAs($reseller2)->put("api/v4/wallets/{$wallet->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(404); | ||||
// Admin user - setting a discount | // Admin user - setting a discount | ||||
$post = ['discount' => $discount->id]; | $post = ['discount' => $discount->id]; | ||||
$response = $this->actingAs($reseller1)->put("api/v4/wallets/{$wallet->id}", $post); | $response = $this->actingAs($reseller1)->put("api/v4/wallets/{$wallet->id}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
Show All 28 Lines |