Aion-Surf

 view release on metacpan or  search on metacpan

t/aion/surf.t  view on Meta::CPAN

# ## bot_message (;$message)
# 
# Sends a message to a telegram bot.
# 
done_testing; }; subtest 'bot_message (;$message)' => sub { 
::is_deeply scalar do {bot_message "hi!"}, scalar do {{ok => 1}}, 'bot_message "hi!" # --> {ok => 1}';

# 
# ## tech_message (;$message)
# 
# Sends a message to a technical telegram channel.
# 
done_testing; }; subtest 'tech_message (;$message)' => sub { 
::is_deeply scalar do {tech_message "hi!"}, scalar do {{ok => 1}}, 'tech_message "hi!" # --> {ok => 1}';

# 
# ## bot_update ()
# 
# Receives the latest messages sent to the bot.
# 
done_testing; }; subtest 'bot_update ()' => sub { 
# mock
*LWP::UserAgent::request = sub {
    my ($ua, $request) = @_;

    my $offset = from_json($request->content)->{offset};
    if($offset) {
        return HTTP::Response->new(200, "OK", undef, to_json {
            ok => 1,
            result => [],
        });
    }

    HTTP::Response->new(200, "OK", undef, to_json {
        ok => 1,
        result => [{
            message => "hi!",
            update_id => 0,
        }],
    });
};

::is_deeply scalar do {bot_update}, scalar do {["hi!"]}, 'bot_update  # --> ["hi!"]';


# mock
*LWP::UserAgent::request = sub {
    HTTP::Response->new(200, "OK", undef, to_json {
        ok => 0,
        description => "nooo!"
    })
};

::like scalar do {eval { bot_update }; $@}, qr!nooo\!!, 'eval { bot_update }; $@  # ~> nooo!';

# 
# # SEE ALSO
# 
# * LWP::Simple
# * LWP::Simple::Post
# * HTTP::Request::Common
# * WWW::Mechanize
# * [An article about sending an HTTP request to a server](https://habr.com/ru/articles/63432/)
# 
# # AUTHOR
# 
# Yaroslav O. Kosmina [dart@cpan.org](dart@cpan.org)
# 
# # LICENSE
# 
# âš– **GPLv3**
# 
# # COPYRIGHT
# 
# The Aion::Surf module is copyright © 2023 Yaroslav O. Kosmina. Rusland. All rights reserved.

	done_testing;
};

done_testing;



( run in 1.288 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )