-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPoliciesControllerTest.php
More file actions
60 lines (52 loc) · 1.81 KB
/
Copy pathPoliciesControllerTest.php
File metadata and controls
60 lines (52 loc) · 1.81 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
<?php
namespace Tests\Http\Controllers;
use App\Policy;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class PoliciesControllerTest extends TestCase {
use DatabaseTransactions;
public function testGetCurrentPolicies(): void {
$currentTime = now();
// Future policy
Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $currentTime->addDay(),
]);
// Old policy
Policy::factory()->create([
'policy_type' => 'hosting-policy',
'active_from' => $currentTime->subMonth(),
]);
// Active policies
$latestActiveToUPolicy = Policy::factory()->create([
'policy_type' => 'terms-of-use',
'active_from' => $currentTime->subMonth(),
]);
$latestActiveHostingPolicy = Policy::factory()->create([
'policy_type' => 'hosting-policy',
'active_from' => $currentTime->subWeek(),
]);
$response = $this->getJson('/v1/policies/current');
$response->assertOk();
$response->assertJsonStructure([
'items' => [
'*' => [
'metadata' => [
'policy_id',
'active_from',
'content_vue_file',
'type',
],
],
],
]);
$response->assertJsonFragment([
'policy_id' => $latestActiveToUPolicy->id,
'active_from' => $latestActiveToUPolicy->active_from->format('Y-m-d'),
]);
$response->assertJsonFragment([
'policy_id' => $latestActiveHostingPolicy->id,
'active_from' => $latestActiveHostingPolicy->active_from->format('Y-m-d'),
]);
}
}