|
3 | 3 | namespace Http\Controllers; |
4 | 4 |
|
5 | 5 | use App\Policy; |
| 6 | +use Carbon\CarbonImmutable; |
6 | 7 | use Illuminate\Foundation\Testing\DatabaseTransactions; |
7 | 8 | use Tests\TestCase; |
8 | 9 |
|
@@ -46,4 +47,115 @@ public function testMissingPolicyByTypeAndActiveFromReturns404(): void { |
46 | 47 | $request = $this->getJson('v1/policies/hosting-policy/by_active_from/2026-07-01'); |
47 | 48 | $request->assertNotFound(); |
48 | 49 | } |
| 50 | + |
| 51 | + public function testUpcomingTermsOfUseMissing(): void { |
| 52 | + Policy::query()->delete(); |
| 53 | + |
| 54 | + $request = $this->getJson('v1/policies/terms-of-use/upcoming'); |
| 55 | + $request->assertNotFound(); |
| 56 | + } |
| 57 | + |
| 58 | + public function testUpcomingHostingPolicyMissing(): void { |
| 59 | + Policy::query()->delete(); |
| 60 | + |
| 61 | + $request = $this->getJson('v1/policies/hosting-policy/upcoming'); |
| 62 | + $request->assertNotFound(); |
| 63 | + } |
| 64 | + |
| 65 | + public function testUpcomingTermsOfUseMultiple(): void { |
| 66 | + Policy::query()->delete(); |
| 67 | + |
| 68 | + $now = CarbonImmutable::now(); |
| 69 | + |
| 70 | + Policy::factory()->create([ |
| 71 | + 'policy_type' => 'terms-of-use', |
| 72 | + 'active_from' => $now->addWeek(), |
| 73 | + ]); |
| 74 | + |
| 75 | + Policy::factory()->create([ |
| 76 | + 'policy_type' => 'terms-of-use', |
| 77 | + 'active_from' => null, |
| 78 | + ]); |
| 79 | + |
| 80 | + $request = $this->getJson('v1/policies/terms-of-use/upcoming'); |
| 81 | + $request->assertServerError(); |
| 82 | + } |
| 83 | + |
| 84 | + public function testUpcomingTermsOfUse(): void { |
| 85 | + Policy::query()->delete(); |
| 86 | + |
| 87 | + $now = CarbonImmutable::now(); |
| 88 | + |
| 89 | + Policy::factory()->create([ |
| 90 | + 'policy_type' => 'terms-of-use', |
| 91 | + 'active_from' => $now->addWeek(), |
| 92 | + 'content_vue_file' => 'terms-of-use/version-1.vue', |
| 93 | + ]); |
| 94 | + |
| 95 | + $request = $this->getJson('v1/policies/terms-of-use/upcoming'); |
| 96 | + |
| 97 | + $request->assertOk(); |
| 98 | + $request->assertJsonStructure([ |
| 99 | + 'metadata' => [ |
| 100 | + 'policy_id', |
| 101 | + 'active_from', |
| 102 | + 'content_vue_file', |
| 103 | + 'type', |
| 104 | + ], |
| 105 | + ]); |
| 106 | + |
| 107 | + $request->assertJsonFragment([ |
| 108 | + 'active_from' => $now->addWeek()->format('Y-m-d'), |
| 109 | + 'type' => 'terms-of-use', |
| 110 | + 'content_vue_file' => 'terms-of-use/version-1.vue', |
| 111 | + ]); |
| 112 | + } |
| 113 | + |
| 114 | + public function testCurrentTermsOfUseMissing(): void { |
| 115 | + Policy::query()->delete(); |
| 116 | + |
| 117 | + $request = $this->getJson('v1/policies/terms-of-use/current'); |
| 118 | + $request->assertNotFound(); |
| 119 | + } |
| 120 | + |
| 121 | + public function testCurrentHostingPolicyMissing(): void { |
| 122 | + Policy::query()->delete(); |
| 123 | + |
| 124 | + $request = $this->getJson('v1/policies/hosting-policy/current'); |
| 125 | + $request->assertNotFound(); |
| 126 | + } |
| 127 | + |
| 128 | + public function testCurrentTermsOfUse() { |
| 129 | + $now = CarbonImmutable::now(); |
| 130 | + |
| 131 | + Policy::factory()->create([ |
| 132 | + 'policy_type' => 'terms-of-use', |
| 133 | + 'active_from' => $now->subMonth(), |
| 134 | + 'content_vue_file' => 'terms-of-use/version-1.vue', |
| 135 | + ]); |
| 136 | + |
| 137 | + $current = Policy::factory()->create([ |
| 138 | + 'policy_type' => 'terms-of-use', |
| 139 | + 'active_from' => $now->subWeek(), |
| 140 | + 'content_vue_file' => 'terms-of-use/version-2.vue', |
| 141 | + ]); |
| 142 | + |
| 143 | + $request = $this->getJson('v1/policies/terms-of-use/current'); |
| 144 | + |
| 145 | + $request->assertOk(); |
| 146 | + $request->assertJsonStructure([ |
| 147 | + 'metadata' => [ |
| 148 | + 'policy_id', |
| 149 | + 'active_from', |
| 150 | + 'content_vue_file', |
| 151 | + 'type', |
| 152 | + ], |
| 153 | + ]); |
| 154 | + |
| 155 | + $request->assertJsonFragment([ |
| 156 | + 'active_from' => $current->active_from->format('Y-m-d'), |
| 157 | + 'type' => $current->policy_type, |
| 158 | + 'content_vue_file' => $current->content_vue_file, |
| 159 | + ]); |
| 160 | + } |
49 | 161 | } |
0 commit comments