At

 view release on metacpan or  search on metacpan

t/00_compile.t  view on Meta::CPAN

            my $todo = todo 'Working with live services here. Things might not go as we expect or hope...';
            ok $login = $bsky->login( $auth->{login}{identifier}, $auth->{login}{password} ), 'logging in for the following tests';
            if ($login) {
                $auth->{resume} = { accessJwt => $bsky->session->accessJwt, refreshJwt => $bsky->session->refreshJwt };
                $path->spew_raw( encode_json $auth );
            }
        };
    };

    # }
    #
    subtest 'upsertProfile correctly handles CAS failures' => sub {
        $login || skip_all "$login";
        my $profile;
        my $cid;
        {
            my $res = $bsky->get( 'com.atproto.repo.getRecord' => { repo => $bsky->did, collection => 'app.bsky.actor.profile', rkey => 'self' } );
            $res->throw unless $res;
            $profile = $res->{value};
            $cid     = $res->{cid}
        }
        my $original = $profile->{description};
    SKIP: {
            $original // skip 'failed to get display name';
            $profile->{displayName} = 'At.pm';
            $profile->{description} = localtime . ' [' . ( int rand time ) . ']';
            ok my $upsert
                = $bsky->post( 'com.atproto.repo.putRecord' =>
                    { repo => $bsky->did, collection => 'app.bsky.actor.profile', rkey => 'self', record => $profile, swapRecord => $cid } ),
                'upsertProfile';
            #
            {
                my $todo = todo 'Bluesky might take a little time to commit changes';
                my $ok   = 0;
                for ( 1 .. 3 ) {
                    diag 'giving Bluesky a moment to catch up...';
                    sleep 2;
                    $profile = $bsky->get( 'app.bsky.actor.getProfile' => { actor => $bsky->did } );
                    $profile || next;

                    #~ use Data::Dump;
                    #~ ddx $profile;
                    ++$ok && last if defined $profile->{description} && $original ne $profile->{description};
                }
                ok $ok, 'displayName has changed';
            }
        }
    };
    subtest 'pull timeline' => sub {
        $login || skip_all "$login";
        is my $timeline = $bsky->get( 'app.bsky.feed.getTimeline' => { actor => $bsky->did } ), hash {
            field cursor => D();
            field feed   => D();    # Feed items are subject to change
            end;
        }, 'getTimeline( )';
    };
    subtest 'pull author feed' => sub {
        $login || skip_all "$login";
        is my $feed
            = $bsky->get(
            'app.bsky.feed.getAuthorFeed' => { actor => 'did:plc:z72i7hdynmk6r22z27h6tvur', filter => 'posts_and_author_threads', limit => 30 } ),
            hash {
            field cursor => D();
            field feed   => D();    # Feed items are subject to change
            end;
            }, 'getAuthorFeed( ... )';
    };
    subtest 'pull post thread' => sub {
        $login || skip_all "$login";
        is my $thread
            = $bsky->get( 'app.bsky.feed.getPostThread' => { uri => 'at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3l2s5xxv2ze2c' } ),
            hash {
            field threadgate => E();
            field thread     => meta {    # Feed items are subject to change
                prop reftype => 'HASH';
            };
            end;
            }, 'getPostThread( ... )';
    };
    subtest 'pull post' => sub {
        $login || skip_all "$login";
        is my $post
            = $bsky->get( 'app.bsky.feed.getPosts' => { uris => ['at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3l2s5xxv2ze2c'] } ), hash {
            field posts => array {
                item meta {
                    prop reftype => 'HASH';
                };
                end;
            };
            end;
            }, 'getPost( ... )';
    };
    subtest 'pull reposts' => sub {
        $login || skip_all "$login";
        is my $reposts
            = $bsky->get( 'app.bsky.feed.getRepostedBy' => { uri => 'at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3l2s5xxv2ze2c' } ),
            hash {
            field cursor     => D();
            field cid        => E();
            field repostedBy => D();    # array
            field uri        => D();    # AT-uri
            end;
            }, 'getRepostedBy( ... )';
    };
    {
        my $post;
        subtest 'post plain text content' => sub {
            $login || skip_all "$login";
            is $post = $bsky->post(
                'com.atproto.repo.createRecord' => {
                    repo       => $bsky->did,
                    collection => 'app.bsky.feed.post',
                    record     => { '$type' => 'app.bsky.feed.post', createdAt => Time::Moment->now->to_string, text => 'Testing' }
                }
                ),
                hash {    # com.atproto.repo.createRecord#output
                field cid => D();    # CID
                field uri => D();    # AT-uri
                etc;                 # might also contain commit and validationStatus
                }, 'post( ... )';
        };
        {
            my $like;
            subtest 'like the post we just created' => sub {
                $login || skip_all "$login";
                $post  || skip_all "$post";
                is $like = $bsky->post(
                    'com.atproto.repo.createRecord' => {
                        repo       => $bsky->did,
                        collection => 'app.bsky.feed.like',
                        record     => {
                            '$type' => 'app.bsky.feed.like',
                            subject => {                       # com.atproto.repo.strongRef
                                uri => $post->{uri},



( run in 0.669 second using v1.01-cache-2.11-cpan-437f7b0c052 )