Lock lexicon values and the URL paren-keep branch in tests
Add a unit test asserting each BlueskyLexicon constant equals its AT Protocol
NSID — a wrong value (not just a typo'd name) would otherwise fail silently at
runtime. Add a test that a URL with a matching '(' keeps its trailing ')'
(Wikipedia-style), covering the previously-untested keep branch of the trim.
This commit is contained in:
parent
8cfdd4c128
commit
444d522012
2 changed files with 43 additions and 0 deletions
|
|
@ -123,6 +123,27 @@
|
|||
});
|
||||
});
|
||||
|
||||
test('bluesky publisher keeps a closing paren that has a matching open paren', function () {
|
||||
$this->post->update(['content' => 'see https://en.wikipedia.org/wiki/Foo_(bar)']);
|
||||
|
||||
Http::fake([
|
||||
config('trypost.platforms.bluesky.default_service').'/xrpc/com.atproto.repo.createRecord' => Http::response([
|
||||
'uri' => 'at://did:plc:testuser123/app.bsky.feed.post/3abc123xyz',
|
||||
'cid' => 'bafyreiabc123',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$this->publisher->publish($this->postPlatform);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
$link = collect($request['record']['facets'] ?? [])
|
||||
->first(fn ($facet) => $facet['features'][0]['$type'] === 'app.bsky.richtext.facet#link');
|
||||
|
||||
// The trailing ')' is part of the URL because it has a matching '('.
|
||||
return $link && $link['features'][0]['uri'] === 'https://en.wikipedia.org/wiki/Foo_(bar)';
|
||||
});
|
||||
});
|
||||
|
||||
test('bluesky publisher computes byte offsets after multibyte characters', function () {
|
||||
$this->post->update(['content' => 'Olá 🎉 #café']);
|
||||
|
||||
|
|
|
|||
22
tests/Unit/Services/Social/BlueskyLexiconTest.php
Normal file
22
tests/Unit/Services/Social/BlueskyLexiconTest.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Social\BlueskyLexicon;
|
||||
|
||||
test('bluesky lexicon constants match their AT Protocol NSIDs', function (string $constant, string $nsid) {
|
||||
expect($constant)->toBe($nsid);
|
||||
})->with([
|
||||
[BlueskyLexicon::RESOLVE_HANDLE, 'com.atproto.identity.resolveHandle'],
|
||||
[BlueskyLexicon::CREATE_RECORD, 'com.atproto.repo.createRecord'],
|
||||
[BlueskyLexicon::UPLOAD_BLOB, 'com.atproto.repo.uploadBlob'],
|
||||
[BlueskyLexicon::CREATE_SESSION, 'com.atproto.server.createSession'],
|
||||
[BlueskyLexicon::REFRESH_SESSION, 'com.atproto.server.refreshSession'],
|
||||
[BlueskyLexicon::FEED_POST, 'app.bsky.feed.post'],
|
||||
[BlueskyLexicon::GET_POSTS, 'app.bsky.feed.getPosts'],
|
||||
[BlueskyLexicon::GET_PROFILE, 'app.bsky.actor.getProfile'],
|
||||
[BlueskyLexicon::EMBED_IMAGES, 'app.bsky.embed.images'],
|
||||
[BlueskyLexicon::FACET_LINK, 'app.bsky.richtext.facet#link'],
|
||||
[BlueskyLexicon::FACET_MENTION, 'app.bsky.richtext.facet#mention'],
|
||||
[BlueskyLexicon::FACET_TAG, 'app.bsky.richtext.facet#tag'],
|
||||
]);
|
||||
Loading…
Reference in a new issue