EV-Telegram-TDLib
view release on metacpan or search on metacpan
t/35_practical_planes.t view on Meta::CPAN
$td->file(7, sub {});
is last_req()->{'@type'}, 'getFile', 'file works';
$td->remote_file('abc', file_type => 'Photo', sub {});
$r = last_req();
is $r->{'@type'}, 'getRemoteFile', 'remote_file works';
is $r->{file_type}{'@type'}, 'fileTypePhoto', 'a short file type is expanded';
$td->add_to_downloads(7, -100, 55, sub {});
is last_req()->{'@type'}, 'addFileToDownloads', 'add_to_downloads works';
$td->pause_download(7, sub {});
like last_json(), qr/"is_paused":true/, 'pause_download defaults to pausing';
$td->storage_statistics(sub {});
is last_req()->{'@type'}, 'getStorageStatisticsFast', 'storage_statistics works';
$td->optimize_storage(size => 100, sub {});
$r = last_req();
is $r->{'@type'}, 'optimizeStorage', 'optimize_storage works';
is $r->{ttl}, -1, 'unset limits are -1, which TDLib reads as no limit';
# --- search and chats
$td->search_chats('bob', sub {});
is last_req()->{'@type'}, 'searchChats', 'search_chats works';
$td->search_public_chats('news', sub {});
is last_req()->{'@type'}, 'searchPublicChats', 'search_public_chats works';
$td->top_chats('bots', sub {});
$r = last_req();
is $r->{'@type'}, 'getTopChats', 'top_chats works';
is $r->{category}{'@type'}, 'topChatCategoryBots', 'the category is typed';
$td->recommended_chats(sub {});
is last_req()->{'@type'}, 'getRecommendedChats', 'recommended_chats works';
$td->check_chat_username(-100, 'name', sub {});
is last_req()->{'@type'}, 'checkChatUsername', 'check_chat_username works';
$td->report_chat(-100, text => 'spam', sub {});
is last_req()->{'@type'}, 'reportChat', 'report_chat works';
$err = do { local $@; eval { $td->top_chats('wizards', sub {}) }; $@ };
like $err, qr/unknown top chat category/, 'an unknown category is refused';
# --- users and privacy
$td->search_by_phone('+15550001', sub {});
is last_req()->{'@type'}, 'searchUserByPhoneNumber', 'search_by_phone works';
$td->my_link(sub {});
is last_req()->{'@type'}, 'getUserLink', 'my_link works';
$td->toggle_username('alt', sub {});
like last_json(), qr/"is_active":true/, 'toggle_username defaults to activating';
$td->privacy('status', sub {});
$r = last_req();
is $r->{'@type'}, 'getUserPrivacySettingRules', 'privacy works';
is $r->{setting}{'@type'}, 'userPrivacySettingShowStatus', 'the setting is typed';
$td->set_privacy('status', [ { '@type' => 'userPrivacySettingRuleAllowAll' } ], sub {});
$r = last_req();
is $r->{'@type'}, 'setUserPrivacySettingRules', 'set_privacy works';
is $r->{rules}{'@type'}, 'userPrivacySettingRules', 'rules are wrapped';
$err = do { local $@; eval { $td->privacy('mind', sub {}) }; $@ };
like $err, qr/unknown privacy setting/, 'an unknown privacy setting is refused';
# --- bots menu button
$td->set_menu_button(42, text => 'Shop', url => 'https://example.com', sub {});
$r = last_req();
is $r->{'@type'}, 'setMenuButton', 'set_menu_button works';
is $r->{menu_button}{'@type'}, 'botMenuButton', 'the button is typed';
is $r->{menu_button}{text}, 'Shop', 'with its text';
$td->menu_button(42, sub {});
is last_req()->{'@type'}, 'getMenuButton', 'menu_button works';
# --- connection, proxies, account
$td->add_proxy({ server => '1.2.3.4', port => 1080, type => 'socks5' }, sub {});
$r = last_req();
is $r->{'@type'}, 'addProxy', 'add_proxy works';
is $r->{proxy}{'@type'}, 'proxy', 'the proxy is typed';
is $r->{proxy}{type}{'@type'}, 'proxyTypeSocks5', 'and so is its type';
is $r->{proxy}{port}, 1080, 'with the port';
$td->add_proxy({ server => 'h', port => 8080, type => 'mtproto', secret => 'ss' }, sub {});
is last_req()->{proxy}{type}{secret}, 'ss', 'an mtproto proxy carries its secret';
$td->proxies(sub {});
is last_req()->{'@type'}, 'getProxies', 'proxies works';
$td->enable_proxy(1, sub {});
is last_req()->{'@type'}, 'enableProxy', 'enable_proxy works';
$td->disable_proxy(sub {});
is last_req()->{'@type'}, 'disableProxy', 'disable_proxy works';
$td->remove_proxy(1, sub {});
is last_req()->{'@type'}, 'removeProxy', 'remove_proxy works';
$td->set_network_type('wifi', sub {});
is last_req()->{type}{'@type'}, 'networkTypeWiFi', 'set_network_type works';
$td->network_statistics(sub {});
is last_req()->{'@type'}, 'getNetworkStatistics', 'network_statistics works';
$td->log_out(sub {});
is last_req()->{'@type'}, 'logOut', 'log_out works';
$td->password_state(sub {});
is last_req()->{'@type'}, 'getPasswordState', 'password_state works';
$td->set_password('old', 'new', hint => 'h', sub {});
$r = last_req();
is $r->{'@type'}, 'setPassword', 'set_password works';
like last_json(), qr/"set_recovery_email_address":false/,
'no recovery email means the flag is off';
# reading and writing share one method, told apart by the argument
$td->account_ttl(sub {});
is last_req()->{'@type'}, 'getAccountTtl', 'account_ttl with no days reads';
$td->account_ttl(365, sub {});
$r = last_req();
is $r->{'@type'}, 'setAccountTtl', 'and with days it writes';
is $r->{ttl}{days}, 365, 'wrapping the days in an accountTtl';
$td->register_device({ '@type' => 'deviceTokenApplePush' }, sub {});
is last_req()->{'@type'}, 'registerDevice', 'register_device works';
$err = do { local $@; eval { $td->set_network_type('moon', sub {}) }; $@ };
like $err, qr/unknown network type/, 'an unknown network type is refused';
# --- regression: a method whose last positional is optional must not swallow
# the callback. Before the fix, close_topic($chat,$topic,$cb) bound $cb to the
# is_closed flag, left @rest empty, and silently registered a no-op instead --
# the caller's callback never fired and nothing said so.
{
my @fired;
for my $case (
[ 'close_topic' => sub { $_[0]->close_topic(-100, 55, $_[1]) } ],
[ 'pin_chat' => sub { $_[0]->pin_chat(-100, $_[1]) } ],
[ 'mark_unread' => sub { $_[0]->mark_unread(-100, $_[1]) } ],
( run in 1.850 second using v1.01-cache-2.11-cpan-8dfa8b56332 )