Skip to content

Commit c2699a4

Browse files
committed
CREATE - Tests
1 parent 334a3d1 commit c2699a4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

app/Models/Article.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class Article extends Model implements Feedable
4545
'original_url',
4646
'slug',
4747
'hero_image',
48+
'hero_image_url',
4849
'is_pinned',
4950
'view_count',
5051
'tweet_id',
@@ -105,7 +106,7 @@ public function hasHeroImage(): bool
105106

106107
public function heroImage($width = 400, $height = 300): string
107108
{
108-
if ($this->hero_image) {
109+
if ($this->hero_image_url) {
109110
return "{$this->hero_image_url}&fit=clip&w={$width}&h={$height}";
110111
}
111112

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use App\Console\Commands\SyncArticleImages;
4+
use App\Models\Article;
5+
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Tests\TestCase;
7+
8+
uses(TestCase::class);
9+
uses(DatabaseMigrations::class);
10+
11+
12+
test('hero image url is updated for published articles with hero image', function () {
13+
14+
$article = Article::factory()->create([
15+
'hero_image' => 'sxiSod0tyYQ',
16+
'submitted_at' => now(),
17+
'approved_at' => now(),
18+
]);
19+
20+
(new SyncArticleImages)->handle();
21+
22+
$article->refresh();
23+
24+
expect($article->heroImage())->toBeUrl();
25+
expect($article->heroImage())->toContain('https://images.unsplash.com/photo-1584824486509-112e4181ff6b');
26+
});
27+
28+
test('hero image url is not updated for published articles with no hero image', function () {
29+
30+
$article = Article::factory()->create([
31+
'submitted_at' => now(),
32+
'approved_at' => now(),
33+
]);
34+
35+
(new SyncArticleImages)->handle();
36+
37+
$article->refresh();
38+
39+
expect($article->hero_image_url)->toBe(null);
40+
})->only();

0 commit comments

Comments
 (0)