Skip to content

Commit 1faafcb

Browse files
committed
tests: Url::isExpired method
Introduces unit tests to verify the behavior of the Url::isExpired method under various conditions, including expiration by date and click limits. Ensures correct handling of expired and non-expired URLs. related: - #1109
1 parent a929717 commit 1faafcb

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/Unit/Models/UrlTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,38 @@ public function testKeywordColumnIsCaseSensitive(): void
143143
$this->assertSame('https://example.com', $dest_1->destination);
144144
$this->assertSame('https://example.org', $dest_2->destination);
145145
}
146+
147+
#[PHPUnit\Test]
148+
public function isExpired(): void
149+
{
150+
// Not expired - no limits set
151+
$url = Url::factory()->create([
152+
'expires_at' => null,
153+
'expired_clicks' => null,
154+
]);
155+
$this->assertFalse($url->isExpired());
156+
157+
// Not expired - expires_at is in the future
158+
$url = Url::factory()->create(['expires_at' => now()->addDay()]);
159+
$this->assertFalse($url->isExpired());
160+
161+
// Not expired - clicks are less than expired_clicks
162+
$url = Url::factory()->create(['expired_clicks' => 2]);
163+
Visit::factory()->for($url)->create();
164+
$this->assertFalse($url->isExpired());
165+
166+
// Expired - expires_at is in the past
167+
$url = Url::factory()->create(['expires_at' => now()->subDay()]);
168+
$this->assertTrue($url->isExpired());
169+
170+
// Expired - clicks are equal to expired_clicks
171+
$url = Url::factory()->create(['expired_clicks' => 1]);
172+
Visit::factory()->for($url)->create();
173+
$this->assertTrue($url->isExpired());
174+
175+
// Not expired - expired_clicks is 0
176+
$url = Url::factory()->create(['expired_clicks' => 0]);
177+
Visit::factory()->for($url)->create();
178+
$this->assertFalse($url->isExpired());
179+
}
146180
}

0 commit comments

Comments
 (0)