Skip to content

Commit cb54707

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

2 files changed

Lines changed: 41 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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
class PoliciesControllerTest extends TestCase {
1313
use DatabaseTransactions;
1414

15+
private string $currentPoliciesRoute = 'v1/policies/current';
16+
1517
private string $missingPoliciesRoute = 'v1/policies/missing';
1618

1719
private function createPolicy(string $type, CarbonImmutable $activeFrom, string $content): Policy {
@@ -27,6 +29,45 @@ public function testMissingPoliciesRequiresAuthentication(): void {
2729
->assertStatus(401);
2830
}
2931

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

0 commit comments

Comments
 (0)