This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
generated from renoki-co/laravel-package-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
PaymentMethodTest.php
120 lines (88 loc) · 3.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace RenokiCo\BillingPortal\Test;
use RenokiCo\BillingPortal\Test\Models\User;
class PaymentMethodTest extends TestCase
{
public function test_payment_methods_index()
{
$user = factory(User::class)->create();
$this->actingAs($user)
->get(route('billing-portal.payment-method.index'))
->assertOk();
$user->createOrGetStripeCustomer();
$user->addPaymentMethod('pm_card_visa');
$user->addPaymentMethod('pm_card_mastercard');
$defaultPaymentMethod = $user->defaultPaymentMethod();
$methods = $user->paymentMethods()
->filter(function ($method) {
return $method->type === 'card';
})->map(function ($method) use ($defaultPaymentMethod) {
return [
'default' => $method->id === optional($defaultPaymentMethod)->id,
'id' => $method->id,
'brand' => $method->card->brand,
'last_four' => $method->card->last4,
'month' => $method->card->exp_month,
'year' => $method->card->exp_year,
];
});
$this->actingAs($user)
->get(route('billing-portal.payment-method.index'))
->assertInertia('BillingPortal/PaymentMethod/Index', [
'methods' => $methods,
]);
}
public function test_payment_methods_create()
{
$user = factory(User::class)->create();
$this->actingAs($user)
->get(route('billing-portal.payment-method.create'))
->assertInertia('BillingPortal/PaymentMethod/Create');
}
public function test_payment_methods_store_without_default_method_set()
{
$user = factory(User::class)->create();
$this->actingAs($user)
->post(route('billing-portal.payment-method.store', ['token' => 'pm_card_visa']))
->assertRedirect(route('billing-portal.payment-method.index'));
$this->assertTrue($user->hasDefaultPaymentMethod());
}
public function test_payment_methods_store()
{
$user = factory(User::class)->create();
$user->createOrGetStripeCustomer();
$user->addPaymentMethod('pm_card_visa');
$user->updateDefaultPaymentMethod('pm_card_visa');
$this->actingAs($user)
->post(route('billing-portal.payment-method.store', ['token' => 'pm_card_mastercard']))
->assertRedirect(route('billing-portal.payment-method.index'));
}
public function test_payment_methods_destroy()
{
$user = factory(User::class)->create();
$user->createOrGetStripeCustomer();
$user->addPaymentMethod('pm_card_visa');
$pm = $user->updateDefaultPaymentMethod('pm_card_visa');
$this->actingAs($user)
->delete(route('billing-portal.payment-method.destroy', ['payment_method' => 'not_existent']))
->assertRedirect(route('billing-portal.payment-method.index'));
$this->actingAs($user)
->delete(route('billing-portal.payment-method.destroy', ['payment_method' => $pm->id]))
->assertRedirect(route('billing-portal.payment-method.index'));
}
public function test_payment_methods_set_default()
{
$user = factory(User::class)->create();
$user->createOrGetStripeCustomer();
$user->createOrGetStripeCustomer();
$user->addPaymentMethod('pm_card_visa');
$pm = $user->addPaymentMethod('pm_card_mastercard');
$user->updateDefaultPaymentMethod('pm_card_visa');
$this->actingAs($user)
->post(route('billing-portal.payment-method.default', ['payment_method' => 'not_existent']))
->assertRedirect(route('billing-portal.payment-method.index'));
$this->actingAs($user)
->post(route('billing-portal.payment-method.default', ['payment_method' => $pm->id]))
->assertRedirect(route('billing-portal.payment-method.index'));
}
}