|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Http\Controllers; |
| 4 | + |
| 5 | +use App\Policy; |
| 6 | +use Illuminate\Foundation\Testing\DatabaseTransactions; |
| 7 | +use Tests\TestCase; |
| 8 | + |
| 9 | +class PoliciesControllerTest extends TestCase { |
| 10 | + use DatabaseTransactions; |
| 11 | + |
| 12 | + public function testGetCurrentPolicies(): void { |
| 13 | + $currentTime = now(); |
| 14 | + |
| 15 | + // Future policy |
| 16 | + Policy::factory()->create([ |
| 17 | + 'policy_type' => 'terms-of-use', |
| 18 | + 'active_from' => $currentTime->addDay(), |
| 19 | + ]); |
| 20 | + // Old policy |
| 21 | + Policy::factory()->create([ |
| 22 | + 'policy_type' => 'hosting-policy', |
| 23 | + 'active_from' => $currentTime->subMonth(), |
| 24 | + ]); |
| 25 | + // Active policies |
| 26 | + $latestActiveToUPolicy = Policy::factory()->create([ |
| 27 | + 'policy_type' => 'terms-of-use', |
| 28 | + 'active_from' => $currentTime->subMonth(), |
| 29 | + ]); |
| 30 | + $latestActiveHostingPolicy = Policy::factory()->create([ |
| 31 | + 'policy_type' => 'hosting-policy', |
| 32 | + 'active_from' => $currentTime->subWeek(), |
| 33 | + ]); |
| 34 | + |
| 35 | + $response = $this->getJson('/v1/policies/current'); |
| 36 | + |
| 37 | + $response->assertOk(); |
| 38 | + $response->assertJsonStructure([ |
| 39 | + 'items' => [ |
| 40 | + '*' => [ |
| 41 | + 'metadata' => [ |
| 42 | + 'policy_id', |
| 43 | + 'active_from', |
| 44 | + 'content_vue_file', |
| 45 | + 'type', |
| 46 | + ], |
| 47 | + ], |
| 48 | + ], |
| 49 | + ]); |
| 50 | + |
| 51 | + $response->assertJsonFragment([ |
| 52 | + 'policy_id' => $latestActiveToUPolicy->id, |
| 53 | + 'active_from' => $latestActiveToUPolicy->active_from->format('Y-m-d'), |
| 54 | + ]); |
| 55 | + $response->assertJsonFragment([ |
| 56 | + 'policy_id' => $latestActiveHostingPolicy->id, |
| 57 | + 'active_from' => $latestActiveHostingPolicy->active_from->format('Y-m-d'), |
| 58 | + ]); |
| 59 | + } |
| 60 | +} |
0 commit comments