|
3 | 3 | namespace Tests\Unit\Services; |
4 | 4 |
|
5 | 5 | use App\Services\DatabaseUpdateService; |
6 | | -use App\Services\StripeApiService; |
| 6 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
7 | 7 | use Tests\TestCase; |
8 | 8 |
|
9 | 9 | class StripeSubscriptionServiceTest extends TestCase |
10 | 10 | { |
11 | | - /** |
12 | | - * Update an existing subscription. |
13 | | - * |
14 | | - * @param string $subscriptionId The ID of the subscription to update. |
15 | | - * @param string $newPlanId The ID of the new plan. |
16 | | - * |
17 | | - * @return array An array containing the result of the operation. |
18 | | - */ |
19 | | - public function testUpdateSubscription(): void |
20 | | - { |
21 | | - // Test case 1: Valid subscription ID and new plan ID |
22 | | - // Mock the StripeApiService and DatabaseUpdateService |
23 | | - // Call the updateSubscription method with valid parameters |
24 | | - // Assert that the expected result is returned |
| 11 | + use RefreshDatabase; |
25 | 12 |
|
26 | | - // Test case 2: Invalid subscription ID |
27 | | - // Mock the StripeApiService and DatabaseUpdateService |
28 | | - // Call the updateSubscription method with an invalid subscription ID |
29 | | - // Assert that the expected error message is returned |
| 13 | + private DatabaseUpdateService $service; |
30 | 14 |
|
31 | | - // Test case 3: Invalid new plan ID |
32 | | - // Mock the StripeApiService and DatabaseUpdateService |
33 | | - // Call the updateSubscription method with an invalid new plan ID |
34 | | - // Assert that the expected error message is returned |
| 15 | + protected function setUp(): void |
| 16 | + { |
| 17 | + parent::setUp(); |
| 18 | + $this->service = new DatabaseUpdateService(); |
| 19 | + } |
35 | 20 |
|
36 | | - // Test case 4: Stripe API error |
37 | | - // Mock the StripeApiService and DatabaseUpdateService |
38 | | - // Call the updateSubscription method and simulate a Stripe API error |
39 | | - // Assert that the expected error message is returned |
40 | | - // Test case 4: Stripe API error |
41 | | - // Mock the StripeApiService and DatabaseUpdateService |
42 | | - // Call the updateSubscription method and simulate a Stripe API error |
43 | | - // Assert that the expected error message is returned |
| 21 | + public function testUpdateSubscription(): void |
| 22 | + { |
| 23 | + // When no team has the given subscription, updateSubscriptionRecord returns failure |
| 24 | + $result = $this->service->updateSubscriptionRecord('sub_nonexistent', 'plan_new'); |
| 25 | + |
| 26 | + $this->assertIsArray($result); |
| 27 | + $this->assertArrayHasKey('success', $result); |
| 28 | + $this->assertArrayHasKey('message', $result); |
| 29 | + $this->assertFalse($result['success']); |
| 30 | + $this->assertStringContainsString('not found', $result['message']); |
44 | 31 | } |
45 | 32 |
|
46 | 33 | public function testCancelSubscription(): void |
47 | 34 | { |
48 | | - // Test case 1: Valid subscription ID |
49 | | - // Mock the StripeApiService and DatabaseUpdateService |
50 | | - // Call the cancelSubscription method with a valid subscription ID |
51 | | - // Assert that the expected result is returned |
52 | | - |
53 | | - // Test case 2: Invalid subscription ID |
54 | | - // Mock the StripeApiService and DatabaseUpdateService |
55 | | - // Call the cancelSubscription method with an invalid subscription ID |
56 | | - // Assert that the expected error message is returned |
57 | | - |
58 | | - // Test case 3: Stripe API error |
59 | | - // Mock the StripeApiService and DatabaseUpdateService |
60 | | - // Call the cancelSubscription method and simulate a Stripe API error |
61 | | - // Assert that the expected error message is returned |
62 | | - // Mock the StripeApiService and DatabaseUpdateService |
63 | | - // Call the cancelSubscription method and simulate a Stripe API error |
64 | | - // Assert that the expected error message is returned |
| 35 | + // When no team has the given subscription, cancelSubscriptionRecord returns failure |
| 36 | + $result = $this->service->cancelSubscriptionRecord('sub_nonexistent'); |
| 37 | + |
| 38 | + $this->assertIsArray($result); |
| 39 | + $this->assertArrayHasKey('success', $result); |
| 40 | + $this->assertArrayHasKey('message', $result); |
| 41 | + $this->assertFalse($result['success']); |
| 42 | + $this->assertStringContainsString('not found', $result['message']); |
65 | 43 | } |
66 | 44 | } |
0 commit comments