-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaymentMethodTest.php
68 lines (58 loc) · 2.96 KB
/
PaymentMethodTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Tests\Unit\PaymentMethods;
use App\Models\BalanceTransaction;
use App\Models\User;
use App\PaymentMethods\BasePaymentMethod;
use App\PaymentMethods\WebmoneyPaymentMethod;
use App\WithdrawalUser;
use MoneyFmt;
use Tests\TestCase;
class PaymentMethodTest extends TestCase
{
public function testAvailableForPayoutWhenMinPayoutIsZeroAndBalanceIsZero()
{
$webmoney = new WebmoneyPaymentMethod(MoneyFmt::make(0), 0);
$user = factory(User::class)->create(['payment_method_name' => WebmoneyPaymentMethod::NAME]);
$this->assertFalse($webmoney->availableForPayout(new WithdrawalUser($user)));
}
public function testAvailableForPayoutWhenMinPayoutIsZeroAndBalanceIsPositive()
{
$webmoney = new WebmoneyPaymentMethod(MoneyFmt::make(0), 0);
$user = factory(User::class)->create(['payment_method_name' => WebmoneyPaymentMethod::NAME]);
$user->transactions()->save(factory(BalanceTransaction::class)->state('deposit')->make());
$this->assertTrue($webmoney->availableForPayout(new WithdrawalUser($user)));
}
public function testAvailableForPayoutWhenMinPayoutIsPositiveAndBalanceIsLessThanMinPayout()
{
$webmoney = new WebmoneyPaymentMethod(MoneyFmt::make(10), 0);
$user = factory(User::class)->create(['payment_method_name' => WebmoneyPaymentMethod::NAME]);
$user->transactions()->save(factory(BalanceTransaction::class)->state('deposit')->make([
'amount' => MoneyFmt::make(5)
]));
$this->assertFalse($webmoney->availableForPayout(new WithdrawalUser($user)));
}
public function testAvailableForPayoutWhenMinPayoutIsPositiveAndBalanceIsEqualsMinPayout()
{
$webmoney = new WebmoneyPaymentMethod(MoneyFmt::make(10), 0);
$user = factory(User::class)->create(['payment_method_name' => WebmoneyPaymentMethod::NAME]);
$user->transactions()->save(factory(BalanceTransaction::class)->state('deposit')
->make(['amount' => MoneyFmt::make(10)]));
$this->assertTrue($webmoney->availableForPayout(new WithdrawalUser($user)));
}
public function testGetUsersForPayoutDoesNotIncludeBannedUser()
{
$mock = \Mockery::mock(WebmoneyPaymentMethod::class, [MoneyFmt::make(10), 0])->makePartial();
$mock->shouldReceive('availableForPayout')->andReturn(true)->zeroOrMoreTimes();
$user = factory(User::class)->create([
'payment_method_name' => WebmoneyPaymentMethod::NAME,
]);
$banned_user = factory(User::class)->state('is_banned')->create([
'payment_method_name' => WebmoneyPaymentMethod::NAME,
]);
$for_payout = $mock->getUsersForPayout();
// XXX пока не сделан assertContains, используем заглушку
$for_payout = new \Illuminate\Database\Eloquent\Collection($for_payout->all());
$this->assertTrue($for_payout->contains($user));
$this->assertFalse($for_payout->contains($banned_user));
}
}