-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from chrisrhymes/feature/rate-limiter
Add rate limiter
- Loading branch information
Showing
6 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use ChrisRhymes\LinkChecker\Jobs\CheckModelForBrokenLinks; | ||
use ChrisRhymes\LinkChecker\Models\BrokenLink; | ||
use ChrisRhymes\LinkChecker\Test\Models\Post; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
uses(RefreshDatabase::class); | ||
|
||
beforeEach(function () { | ||
Http::fake([ | ||
'*' => Http::response(null, 404), | ||
]); | ||
}); | ||
|
||
it('triggers the rate limit and only finds one broken link', function () { | ||
Config::set('link-checker.rate_limit', 1); | ||
|
||
$post = Post::factory() | ||
->create([ | ||
'content' => ' | ||
<a href="https://this-is-broken.com/test1">Broken link</a> | ||
<p>Some other content here</p> | ||
<a href="https://this-is-broken.com/test2">Broken link</a> | ||
<a href="https://this-is-broken.com/test3">Broken link</a>', | ||
]); | ||
|
||
CheckModelForBrokenLinks::dispatch($post, ['content']); | ||
|
||
expect(BrokenLink::get()) | ||
->toHaveCount(1) | ||
->first()->broken_link->toBe('https://this-is-broken.com/test1'); | ||
}); |