Skip to content

Commit

Permalink
Merge pull request #19 from shahmal1yev/bss-issue-18
Browse files Browse the repository at this point in the history
Resolve the issue that external does not serialize by atproto/bsky specs (#18)
  • Loading branch information
shahmal1yev authored Nov 11, 2024
2 parents f75c3d8 + 421aea1 commit 6aa4a86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/Lexicons/App/Bsky/Embed/External.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Atproto\Lexicons\App\Bsky\Embed;

use Atproto\Client;
use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface;
use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract;
use Atproto\DataModel\Blob\Blob;
Expand All @@ -17,7 +18,7 @@ class External implements EmbedInterface, MediaContract
private string $description;
private ?Blob $blob = null;

public function __construct(string $uri, string $title, string $description)
public function __construct(Client $bsky, string $uri, string $title, string $description)
{
$this->uri($uri)
->title($title)
Expand Down Expand Up @@ -94,12 +95,14 @@ public function thumb(Blob $blob = null)

public function jsonSerialize(): array
{
return array_filter([
return [
'$type' => $this->nsid(),
'uri' => $this->uri,
'title' => $this->title,
'description' => $this->description,
'blob' => ($b = $this->blob) ? $b : null,
]);
'external' => array_filter([
'uri' => $this->uri,
'title' => $this->title,
'description' => $this->description,
'blob' => ($b = $this->blob) ? $b : null,
])
];
}
}
21 changes: 13 additions & 8 deletions tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit\Lexicons\App\Bsky\Embed;

use Atproto\Client;
use Atproto\DataModel\Blob\Blob;
use Atproto\Exceptions\InvalidArgumentException;
use Atproto\Lexicons\App\Bsky\Embed\External;
Expand All @@ -17,7 +18,7 @@ class ExternalTest extends TestCase

public function setUp(): void
{
$this->external = new External('https://shahmal1yev.dev', 'foo', 'bar');
$this->external = new External($this->createMock(Client::class), 'https://shahmal1yev.dev', 'foo', 'bar');

$this->blob = $this->getMockBuilder(Blob::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -107,9 +108,11 @@ public function testJsonSerializeWithoutSetBlob(): void
{
$expected = [
'$type' => 'app.bsky.embed.external',
'uri' => 'https://shahmal1yev.dev',
'title' => 'foo',
'description' => 'bar',
'external' => [
'uri' => 'https://shahmal1yev.dev',
'title' => 'foo',
'description' => 'bar',
]
];

$this->assertSame($expected, json_decode($this->external, true));
Expand All @@ -124,10 +127,12 @@ public function testJsonSerializeWithSetBlob(): void

$expected = [
'$type' => 'app.bsky.embed.external',
'uri' => 'https://shahmal1yev.dev',
'title' => 'foo',
'description' => 'bar',
'blob' => $this->blob->jsonSerialize(),
'external' => [
'uri' => 'https://shahmal1yev.dev',
'title' => 'foo',
'description' => 'bar',
'blob' => $this->blob->jsonSerialize()
],
];

$this->assertSame($expected, json_decode($this->external, true));
Expand Down

0 comments on commit 6aa4a86

Please sign in to comment.