-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPolicyControllerTest.php
More file actions
161 lines (127 loc) · 4.68 KB
/
Copy pathPolicyControllerTest.php
File metadata and controls
161 lines (127 loc) · 4.68 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace Tests\Routes;
use App\Policy;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class PolicyControllerTest extends TestCase {
use DatabaseTransactions;
public function testGetPolicyByTypeAndActiveFrom(): void {
Policy::factory()->create([
'policy_type' => 'hosting-policy',
'active_from' => '2026-07-01',
]);
Policy::factory()->create([
'policy_type' => 'hosting-policy',
'active_from' => '2026-07-02',
]);
$request = $this->getJson('v1/policies/hosting-policy/by_active_from/2026-07-01');
$request->assertOk();
$request->assertJsonStructure([
'metadata' => [
'policy_id',
'active_from',
'content_vue_file',
'type',
],
]);
$request->assertJsonFragment([
'active_from' => '2026-07-01',
'type' => 'hosting-policy',
]);
}
public function testGetPolicyByTypeAndActiveFromReturns422WithInvalidParams(): void {
$request = $this->getJson('v1/policies/fake-policy/by_active_from/not-a-date');
$request->assertUnprocessable();
}
public function testMissingPolicyByTypeAndActiveFromReturns404(): void {
$request = $this->getJson('v1/policies/hosting-policy/by_active_from/2026-07-01');
$request->assertNotFound();
}
public function testUpcomingTermsOfUseMissing(): void {
Policy::query()->delete();
$request = $this->getJson('v1/policies/terms-of-use/upcoming');
$request->assertNotFound();
}
public function testUpcomingHostingPolicyMissing(): void {
Policy::query()->delete();
$request = $this->getJson('v1/policies/hosting-policy/upcoming');
$request->assertNotFound();
}
public function testUpcomingTermsOfUseMultiple(): void {
Policy::query()->delete();
$now = CarbonImmutable::now();
Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $now->addWeek(),
]);
Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => null,
]);
$request = $this->getJson('v1/policies/terms-of-use/upcoming');
$request->assertServerError();
}
public function testUpcomingTermsOfUse(): void {
Policy::query()->delete();
$now = CarbonImmutable::now();
Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $now->addWeek(),
'content_vue_file' => 'terms-of-use/version-1.vue',
]);
$request = $this->getJson('v1/policies/terms-of-use/upcoming');
$request->assertOk();
$request->assertJsonStructure([
'metadata' => [
'policy_id',
'active_from',
'content_vue_file',
'type',
],
]);
$request->assertJsonFragment([
'active_from' => $now->addWeek()->format('Y-m-d'),
'type' => 'terms-of-use',
'content_vue_file' => 'terms-of-use/version-1.vue',
]);
}
public function testCurrentTermsOfUseMissing(): void {
Policy::query()->delete();
$request = $this->getJson('v1/policies/terms-of-use/current');
$request->assertNotFound();
}
public function testCurrentHostingPolicyMissing(): void {
Policy::query()->delete();
$request = $this->getJson('v1/policies/hosting-policy/current');
$request->assertNotFound();
}
public function testCurrentTermsOfUse() {
$now = CarbonImmutable::now();
Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $now->subMonth(),
'content_vue_file' => 'terms-of-use/version-1.vue',
]);
$current = Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $now->subWeek(),
'content_vue_file' => 'terms-of-use/version-2.vue',
]);
$request = $this->getJson('v1/policies/terms-of-use/current');
$request->assertOk();
$request->assertJsonStructure([
'metadata' => [
'policy_id',
'active_from',
'content_vue_file',
'type',
],
]);
$request->assertJsonFragment([
'active_from' => $current->active_from->format('Y-m-d'),
'type' => $current->policy_type,
'content_vue_file' => $current->content_vue_file,
]);
}
}