From 7744defa1f8a5f1b54d8eb78657bd2c8d73df29f Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 4 Apr 2020 00:21:47 +1300 Subject: WIP: Start writing some plugin tests --- test/test_autojoin.t | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 test/test_autojoin.t (limited to 'test/test_autojoin.t') diff --git a/test/test_autojoin.t b/test/test_autojoin.t new file mode 100755 index 0000000..fb0e4b1 --- /dev/null +++ b/test/test_autojoin.t @@ -0,0 +1,69 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::Simple tests => 12; + +use Mock::IRC; + +use Plugin::Autojoin; + + +my $irc = new Mock::IRC; + +sub null_logger{} +my @expected_channels = ( "#channel", "#another", "#and_another" ); +my $channel; +my %config = ( + "channels" => \@expected_channels +); + +my $nick = "someBotNick"; +$irc->yield('nick' => $nick); + +Plugin::Autojoin->configure(undef, undef, \%config, undef); + +### +# Check that all configured channels are joined to on IRC 001 (initial +# connection +Plugin::Autojoin->on_001_welcome(\&null_logger, undef, undef, $irc); +for my $expected (@expected_channels) { + ok($irc->idalius_is_joined_to($expected), "joined $expected"); +} + +# Check that the number of channels joined matches the number of channels +# configured. Along with the above assertions, this ensures we join only those +# channels instructed to +my @joined = $irc->idalius_get_channels(); +ok(@joined == @expected_channels, "No extra channels joined"); + +### +# Check that being "kicked" from a channel (even unconfigured) joins us back +# to it +$channel = "#notconfigured"; +ok(!($irc->idalius_is_joined_to($channel)), "not in $channel"); +Plugin::Autojoin->on_kick(\&null_logger, "someUser", $channel, $nick, "reason", $irc); +ok($irc->idalius_is_joined_to($channel), "joined to $channel after kick"); + +# Check that seeing someone else be kicked wouldn't make us yield any +# unnecessary join +$channel = $expected_channels[0]; +$irc->yield(part => $channel); +ok(!($irc->idalius_is_joined_to($channel)), "not in $channel"); +Plugin::Autojoin->on_kick(\&null_logger, "someUser", $channel, "a$nick", "reason", $irc); +ok(!($irc->idalius_is_joined_to($channel)), "not in $channel after someone else was kicked"); + + +### +# Check that being invited to a configured channel joins us back to it +$channel = $expected_channels[0]; +$irc->yield(part => $channel); +ok(!($irc->idalius_is_joined_to($channel)), "removed from $channel"); +Plugin::Autojoin->on_invite(\&null_logger, "someUser", $channel, $irc); +ok($irc->idalius_is_joined_to($channel), "joined to $channel after invitation"); + +# Check that being invited to a channel not configured doesn't join us to it +$channel = "#fronglegrong"; +ok(!($irc->idalius_is_joined_to($channel)), "not in $channel"); +Plugin::Autojoin->on_invite(\&null_logger, "someUser", $channel, $irc); +ok(!($irc->idalius_is_joined_to($channel)), "not in $channel after invitation"); -- cgit v1.1