-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathGetLicenseTest.php
More file actions
115 lines (95 loc) · 3.21 KB
/
Copy pathGetLicenseTest.php
File metadata and controls
115 lines (95 loc) · 3.21 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
110
111
112
113
114
115
<?php
namespace Tests\Feature\Api;
use App\Models\License;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class GetLicenseTest extends TestCase
{
use RefreshDatabase;
public function test_requires_authentication()
{
$user = User::factory()->create();
$license = License::factory()->create([
'user_id' => $user->id,
'key' => 'TEST-KEY-123',
]);
$response = $this->getJson('/api/licenses/'.$license->key);
$response->assertStatus(401);
}
public function test_returns_404_for_non_existent_license()
{
$token = config('services.bifrost.api_key');
$response = $this->withHeaders([
'Authorization' => 'Bearer '.$token,
])->getJson('/api/licenses/NON-EXISTENT-KEY');
$response->assertStatus(404);
}
public function test_returns_license_with_user_email()
{
$user = User::factory()->create([
'email' => 'test@example.com',
'name' => 'Test User',
]);
$license = License::factory()->create([
'user_id' => $user->id,
'key' => 'TEST-LICENSE-KEY-123',
'policy_name' => 'pro',
'source' => 'bifrost',
'anystack_id' => 'anystack_123',
]);
$token = config('services.bifrost.api_key');
$response = $this->withHeaders([
'Authorization' => 'Bearer '.$token,
])->getJson('/api/licenses/'.$license->key);
$response->assertStatus(200)
->assertJson([
'data' => [
'id' => $license->id,
'anystack_id' => 'anystack_123',
'key' => 'TEST-LICENSE-KEY-123',
'policy_name' => 'pro',
'source' => 'bifrost',
'email' => 'test@example.com',
],
])
->assertJsonStructure([
'data' => [
'id',
'anystack_id',
'key',
'policy_name',
'source',
'expires_at',
'created_at',
'updated_at',
'email',
],
]);
}
public function test_returns_correct_license_by_key()
{
$user1 = User::factory()->create(['email' => 'user1@example.com']);
$user2 = User::factory()->create(['email' => 'user2@example.com']);
$license1 = License::factory()->create([
'user_id' => $user1->id,
'key' => 'KEY-USER-1',
]);
$license2 = License::factory()->create([
'user_id' => $user2->id,
'key' => 'KEY-USER-2',
]);
$token = config('services.bifrost.api_key');
$response = $this->withHeaders([
'Authorization' => 'Bearer '.$token,
])->getJson('/api/licenses/KEY-USER-2');
$response->assertStatus(200)
->assertJson([
'data' => [
'id' => $license2->id,
'key' => 'KEY-USER-2',
'email' => 'user2@example.com',
],
]);
}
}