Skip to content

Commit

Permalink
bugfix(embed): Fix manual embedding (#8)
Browse files Browse the repository at this point in the history
* bugfix(embed): Fix manual embedding

* test: cover using a manual embed

---------

Co-authored-by: Enzo Innocenzi <enzo@innocenzi.dev>
  • Loading branch information
ClaraLeigh and innocenzi authored Dec 5, 2024
1 parent b68b9a6 commit c4a0e2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/BlueskyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function resolvePost(string|BlueskyPost $post): BlueskyPost
$post->facets(facets: $this->facetsResolver->resolve($this, $post));
}

$post->embed($this->resolveEmbed($post));
if ($embed = $this->resolveEmbed($post)) {
$post->embed(embed: $embed);
}

return $post;
}
Expand All @@ -54,11 +56,11 @@ private function resolveEmbed(BlueskyPost $post): ?Embed
if ($post->embedUrl) {
return $this->embedResolver->createEmbedFromUrl($this, $post->embedUrl);
}

if ($post->automaticallyResolvesEmbeds()) {
return $this->embedResolver->resolve($this, $post);
}

return null;
}

Expand Down
17 changes: 16 additions & 1 deletion tests/BlueskyServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
]);
})->skip('Needs updating');

test('the embed specified in the post is used', function () {
test('the embed url specified in the post is resolved', function () {
HttpResponsesFactory::fake([
LinkEmbedResolverUsingCardyb::ENDPOINT => [
'error' => '',
Expand All @@ -74,3 +74,18 @@
->toBeInstanceOf(External::class)
->title->toBe('Google');
});

test('the embed specified in the post is used', function () {
$post = BlueskyPost::make()
->withoutAutomaticEmbeds()
->embed(new External('https://foo.fr', 'Foo', 'Bar'));

/** @var BlueskyService */
$service = resolve(BlueskyService::class);
$service->resolvePost($post);

expect($post->embed)
->toBeInstanceOf(External::class)
->uri->toBe('https://foo.fr')
->title->toBe('Foo');
});

0 comments on commit c4a0e2d

Please sign in to comment.