Skip to content

Commit 5c104b5

Browse files
committed
merge PoliciesControllerTest class into one file
1 parent 7b950eb commit 5c104b5

2 files changed

Lines changed: 40 additions & 60 deletions

File tree

tests/Http/Controllers/PoliciesControllerTest.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/Routes/PoliciesControllerTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class PoliciesControllerTest extends TestCase {
1313
use DatabaseTransactions;
1414

15+
private string $currentPoliciesRoute = 'v1/policies/current';
1516
private string $missingPoliciesRoute = 'v1/policies/missing';
1617

1718
private function createPolicy(string $type, CarbonImmutable $activeFrom, string $content): Policy {
@@ -27,6 +28,45 @@ public function testMissingPoliciesRequiresAuthentication(): void {
2728
->assertStatus(401);
2829
}
2930

31+
public function testGetCurrentPolicies(): void {
32+
$now = CarbonImmutable::now();
33+
34+
// Future policy
35+
$this->createPolicy('terms-of-use', $now->addDay(), 'terms-of-use/version-future.vue');
36+
37+
// Older active policy of the same type should be excluded
38+
$this->createPolicy('hosting-policy', $now->subMonths(2), 'hosting-policy/version-1.vue');
39+
40+
// Active policies
41+
$latestActiveToUPolicy = $this->createPolicy('terms-of-use', $now->subMonth(), 'terms-of-use/version-2.vue');
42+
$latestActiveHostingPolicy = $this->createPolicy('hosting-policy', $now->subWeek(), 'hosting-policy/version-2.vue');
43+
44+
$response = $this->json('GET', $this->currentPoliciesRoute);
45+
46+
$response->assertOk();
47+
$response->assertJsonStructure([
48+
'items' => [
49+
'*' => [
50+
'metadata' => [
51+
'policy_id',
52+
'active_from',
53+
'content_vue_file',
54+
'type',
55+
],
56+
],
57+
],
58+
]);
59+
60+
$response->assertJsonFragment([
61+
'policy_id' => $latestActiveToUPolicy->id,
62+
'active_from' => $latestActiveToUPolicy->active_from->format('Y-m-d'),
63+
]);
64+
$response->assertJsonFragment([
65+
'policy_id' => $latestActiveHostingPolicy->id,
66+
'active_from' => $latestActiveHostingPolicy->active_from->format('Y-m-d'),
67+
]);
68+
}
69+
3070
public function testMissingPoliciesReturnsOnlyLatestCurrentPolicyPerType(): void {
3171
$user = User::factory()->create();
3272
$now = CarbonImmutable::now();

0 commit comments

Comments
 (0)