-
Notifications
You must be signed in to change notification settings - Fork 41
fix(portal): não deixar payload malformado do dev.to derrubar /artigos #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielhe4rt
wants to merge
1
commit into
4.x
Choose a base branch
from
bugfix/artigos-payload-malformado
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use He4rt\Portal\Articles\Article; | ||
| use He4rt\Portal\Articles\ArticleFeed; | ||
| use He4rt\Portal\Livewire\ArticlesPage; | ||
| use Illuminate\Support\Facades\Cache; | ||
|
|
@@ -176,3 +177,67 @@ function devToArticle(array $overrides = []): array | |
| ->assertSee('Do cache') | ||
| ->assertDontSee('Não deu para carregar o acervo agora.'); | ||
| }); | ||
|
|
||
| it('descarta artigo com data impossível de interpretar em vez de derrubar a página', function (): void { | ||
| Http::fake([ | ||
| 'dev.to/api/articles*' => Http::response([ | ||
| devToArticle(['id' => 1, 'title' => 'Válido']), | ||
| devToArticle(['id' => 2, 'title' => 'Data podre', 'published_at' => 'amanhã cedo']), | ||
| ]), | ||
| ]); | ||
|
|
||
| $articles = resolve(ArticleFeed::class)->articles(); | ||
|
|
||
| expect($articles)->toHaveCount(1) | ||
| ->and($articles[0]->title)->toBe('Válido'); | ||
| }); | ||
|
|
||
| it('descarta data vazia em vez de assumir hoje e jogar o artigo para o topo', function (): void { | ||
| Http::fake([ | ||
| 'dev.to/api/articles*' => Http::response([ | ||
| devToArticle(['id' => 1, 'title' => 'Real', 'published_at' => now()->subMonth()->toIso8601String()]), | ||
| devToArticle(['id' => 2, 'title' => 'Sem data', 'published_at' => '']), | ||
| ]), | ||
| ]); | ||
|
|
||
| $articles = resolve(ArticleFeed::class)->articles(); | ||
|
|
||
| expect($articles)->toHaveCount(1) | ||
| ->and($articles[0]->title)->toBe('Real'); | ||
| }); | ||
|
|
||
| it('não quebra com campo de texto que não é texto', function (): void { | ||
| Http::fake([ | ||
| 'dev.to/api/articles*' => Http::response([ | ||
| devToArticle(['id' => 1, 'title' => ['isto' => 'é um array']]), | ||
| devToArticle(['id' => 2, 'title' => 'Sobrevivente']), | ||
| ]), | ||
| ]); | ||
|
|
||
| $titles = array_map(fn (Article $article): string => $article->title, resolve(ArticleFeed::class)->articles()); | ||
|
|
||
| expect($titles)->toContain('Sobrevivente'); | ||
|
Comment on lines
+217
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert that the invalid record is rejected. The assertion passes if the array title remains in the result and 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it('não deixa payload inteiro inválido envenenar a janela obsoleta do cache', function (): void { | ||
| Http::fake([ | ||
| 'dev.to/api/articles*' => Http::response([ | ||
| devToArticle(['id' => 1, 'published_at' => 'lixo']), | ||
| devToArticle(['id' => 2, 'published_at' => 'mais lixo']), | ||
| ]), | ||
| ]); | ||
|
|
||
| expect(resolve(ArticleFeed::class)->articles())->toBeEmpty() | ||
| ->and(Cache::has('portal.articles.devto-org'))->toBeFalse(); | ||
| }); | ||
|
|
||
| it('mantém a página de pé quando um item do acervo está corrompido', function (): void { | ||
| Http::fake([ | ||
| 'dev.to/api/articles*' => Http::response([ | ||
| devToArticle(['id' => 1, 'title' => 'Artigo bom']), | ||
| devToArticle(['id' => 2, 'published_at' => 'quebrado']), | ||
| ]), | ||
| ]); | ||
|
|
||
| $this->get('/artigos')->assertOk()->assertSee('Artigo bom'); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 1417
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 6028
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 50376
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 9614
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 38327
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 38327
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 4380
Valide
published_atcom formato estrito.CarbonImmutable::parse()aceita expressões relativas comoMonday next week. Aceite somente o timestamp ISO 8601 retornado pela API para evitar datas inválidas na ordenação e no destaque.🤖 Prompt for AI Agents