Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/WalletTest.php
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | class WalletTest extends TestCase | ||||
/** | /** | ||||
* Verify a wallet is created, when a user is created. | * Verify a wallet is created, when a user is created. | ||||
*/ | */ | ||||
public function testCreateUserCreatesWallet(): void | public function testCreateUserCreatesWallet(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet1@UserWallet.com'); | $user = $this->getTestUser('UserWallet1@UserWallet.com'); | ||||
$this->assertCount(1, $user->wallets); | $this->assertCount(1, $user->wallets); | ||||
$this->assertSame(\config('app.currency'), $user->wallets[0]->currency); | |||||
$this->assertSame(0, $user->wallets[0]->balance); | |||||
} | } | ||||
/** | /** | ||||
* Verify a user can haz more wallets. | * Verify a user can haz more wallets. | ||||
*/ | */ | ||||
public function testAddWallet(): void | public function testAddWallet(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet2@UserWallet.com'); | $user = $this->getTestUser('UserWallet2@UserWallet.com'); | ||||
$user->wallets()->save( | $user->wallets()->save( | ||||
new Wallet(['currency' => 'USD']) | new Wallet(['currency' => 'USD']) | ||||
); | ); | ||||
$this->assertCount(2, $user->wallets); | $this->assertCount(2, $user->wallets); | ||||
$user->wallets()->each( | $user->wallets()->each( | ||||
function ($wallet) { | function ($wallet) { | ||||
$this->assertEquals(0, $wallet->balance); | $this->assertEquals(0, $wallet->balance); | ||||
} | } | ||||
); | ); | ||||
// For now all wallets use system currency | |||||
$this->assertFalse($user->wallets()->where('currency', 'USD')->exists()); | |||||
} | } | ||||
/** | /** | ||||
* Verify we can not delete a user wallet that holds balance. | * Verify we can not delete a user wallet that holds balance. | ||||
*/ | */ | ||||
public function testDeleteWalletWithCredit(): void | public function testDeleteWalletWithCredit(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet3@UserWallet.com'); | $user = $this->getTestUser('UserWallet3@UserWallet.com'); | ||||
Show All 33 Lines | class WalletTest extends TestCase | ||||
public function testDeleteAddtWallet(): void | public function testDeleteAddtWallet(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UserWallet5@UserWallet.com'); | $user = $this->getTestUser('UserWallet5@UserWallet.com'); | ||||
$user->wallets()->save( | $user->wallets()->save( | ||||
new Wallet(['currency' => 'USD']) | new Wallet(['currency' => 'USD']) | ||||
); | ); | ||||
// For now additional wallets with a different currency is not allowed | |||||
$this->assertFalse($user->wallets()->where('currency', 'USD')->exists()); | |||||
/* | |||||
$user->wallets()->each( | $user->wallets()->each( | ||||
function ($wallet) { | function ($wallet) { | ||||
if ($wallet->currency == 'USD') { | if ($wallet->currency == 'USD') { | ||||
$this->assertNotFalse($wallet->delete()); | $this->assertNotFalse($wallet->delete()); | ||||
} | } | ||||
} | } | ||||
); | ); | ||||
*/ | |||||
} | } | ||||
/** | /** | ||||
* Verify a wallet can be assigned a controller. | * Verify a wallet can be assigned a controller. | ||||
*/ | */ | ||||
public function testAddWalletController(): void | public function testAddWalletController(): void | ||||
{ | { | ||||
$userA = $this->getTestUser('WalletControllerA@WalletController.com'); | $userA = $this->getTestUser('WalletControllerA@WalletController.com'); | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |