-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathCoursePageTest.php
More file actions
109 lines (91 loc) · 3.16 KB
/
CoursePageTest.php
File metadata and controls
109 lines (91 loc) · 3.16 KB
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
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class CoursePageTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function course_page_loads_successfully(): void
{
$this
->withoutVite()
->get(route('course'))
->assertStatus(200)
->assertSee('The NativePHP Masterclass')
->assertSee('Early Bird');
}
#[Test]
public function course_page_contains_mailcoach_signup_form(): void
{
$this
->withoutVite()
->get(route('course'))
->assertSee('simonhamp.mailcoach.app/subscribe/', false)
->assertSee('Join Waitlist');
}
#[Test]
public function course_page_contains_checkout_form(): void
{
$this
->withoutVite()
->get(route('course'))
->assertSee(route('course.checkout'), false)
->assertSee('Get Early Bird Access');
}
#[Test]
public function course_checkout_redirects_guests_to_login(): void
{
$this
->post(route('course.checkout'))
->assertRedirect(route('customer.login'));
}
#[Test]
public function course_checkout_redirects_to_stripe_with_cart_success_url(): void
{
$user = User::factory()->create(['stripe_id' => 'cus_test123']);
$stripeSessionUrl = 'https://checkout.stripe.com/test-session';
$capturedParams = null;
$mockCheckoutSessions = new class($stripeSessionUrl, $capturedParams)
{
public function __construct(
private string $url,
private &$capturedParams,
) {}
public function create(array $params): object
{
$this->capturedParams = $params;
return (object) [
'id' => 'cs_test123',
'url' => $this->url,
];
}
};
$mockCheckout = new \stdClass;
$mockCheckout->sessions = $mockCheckoutSessions;
$mockCustomers = new class
{
public function retrieve(): \Stripe\Customer
{
return \Stripe\Customer::constructFrom([
'id' => 'cus_test123',
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
};
$mockStripeClient = $this->createMock(\Stripe\StripeClient::class);
$mockStripeClient->checkout = $mockCheckout;
$mockStripeClient->customers = $mockCustomers;
$this->app->bind(\Stripe\StripeClient::class, fn () => $mockStripeClient);
$this
->actingAs($user)
->post(route('course.checkout'))
->assertRedirect($stripeSessionUrl);
$this->assertNotNull($capturedParams, 'Stripe checkout session should have been created');
$this->assertStringContainsString(route('cart.success'), $capturedParams['success_url']);
$this->assertStringContainsString('{CHECKOUT_SESSION_ID}', $capturedParams['success_url']);
}
}