aboutsummaryrefslogtreecommitdiff
path: root/test/test_autojoin.t
blob: fb0e4b13245595b3db4ae7263648b49755e32e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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");