Skip to content

Commit

Permalink
Merge pull request #23 from shahmal1yev/bss-86
Browse files Browse the repository at this point in the history
[BSS-86] Fix incorrect JSON serialization of External with image preview card
  • Loading branch information
shahmal1yev authored Nov 28, 2024
2 parents ff4bfc7 + 62a2de3 commit e9bc31c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Lexicons/App/Bsky/Embed/External.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function jsonSerialize(): array
'uri' => $this->uri,
'title' => $this->title,
'description' => $this->description,
'blob' => ($b = $this->blob) ? $b : null,
'thumb' => ($b = $this->blob) ? $b : null,
])
];
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,36 @@ public function testPostCreationWithoutBlobUploading(): void

$this->assertIsString($createdRecord->uri());
}

public function testPostCreationWithPreviewCard(): void
{
$client = static::$client;

$uploadedBlob = $client->com()->atproto()->repo()->uploadBlob()->forge()
->token($client->authenticated()->accessJwt())
->blob(__DIR__.'/../../../../../../art/logo-small.webp')
->send()
->blob();

$external = $client->app()->bsky()->embed()->external()->forge(
'https://shahmal1yev.dev',
'Eldar Shahmaliyev\'s blog',
'A personal blog about cybersecurity and development.'
)->thumb($uploadedBlob);

$post = $client->app()->bsky()->feed()->post()->forge()
->text('Come to my blog: ')
->link('https://shahmal1yev.dev', 'click here and read the posts')
->embed($external);

$createRecord = $client->com()->atproto()->repo()->createRecord()->forge()
->record($post)
->repo($client->authenticated()->did())
->collection($post->nsid())
;

$serializedCreateRecord = json_decode($createRecord, true);

$this->assertIsArray(Arr::get($serializedCreateRecord, 'record.embed.external.thumb'));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function testJsonSerializeWithSetBlob(): void
'uri' => 'https://shahmal1yev.dev',
'title' => 'foo',
'description' => 'bar',
'blob' => $this->blob->jsonSerialize()
'thumb' => $this->blob->jsonSerialize()
],
];

Expand Down

0 comments on commit e9bc31c

Please sign in to comment.