aboutsummaryrefslogtreecommitdiff
path: root/t/30-room.t
blob: f5b653e587a5c5650f1afb235e621529188ad467 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use lib 'lib';
use Test;
use Matrix::Client;
plan 14;

use-ok 'Matrix::Client::Room';

my $room = Matrix::Client::Room.new(:home-server<test>, :id<!something>);
can-ok $room, 'read-marker';
can-ok $room, 'typing';

# Integrations tests;

unless %*ENV<MATRIX_CLIENT_TEST_SERVER> {
    skip-rest 'No test server setted';
    exit;
}

my $home-server = %*ENV<MATRIX_CLIENT_TEST_SERVER>;
my $username = %*ENV<MATRIX_CLIENT_USERNAME>;
my $password = %*ENV<MATRIX_CLIENT_PASSWORD>;
my $device-id = %*ENV<MATRIX_CLIENT_DEVICE_ID>;
my $public-room-id = %*ENV<MATRIX_CLIENT_PUBLIC_ROOM> // '!cYTYddgfJTLTzdiDBP:localhost';
my Matrix::Client $client .= new(:$home-server);

$client.login(:$username, :$password);

my $room-alias = 'Room' ~ (^10).map({('a''z').pick}).join;
my $main-room;

lives-ok {
    $main-room = $client.create-room(
        :public,
        :preset<public_chat>,
        :room_alias_name($room-alias),
        :name("The Grand Duke Pub"),
        :topic("All about happy hour"),
        :creation_content({
            "m.federate" => False
        })
    );
}, 'Can create room';

isa-ok $main-room, Matrix::Client::Room;

my $room-id = $main-room.id;

lives-ok {
    $main-room.leave;
}, 'Can leave room';

skip 'M_UNKNOWN: No known servers', 1;
#lives-ok {
#    $main-room.join;
#}, 'Can join a room';

lives-ok {
    $client.join-room($public-room-id)
}, 'Can join public room';

my @rooms = $client.joined-rooms;
my $public-room = @rooms.first(-> $room { $room.id eq $public-room-id });

isa-ok $public-room, Matrix::Client::Room;
isa-ok $public-room.send('hi'), Str;

subtest 'states' => {
    plan 2;
    isa-ok $main-room.state(), Seq;
    my @states = $main-room.state();
    isa-ok @states.first(), Matrix::Client::Response::StateEvent;
};

subtest 'creation' => {
    plan 3;
    my $new-room = Matrix::Client::Room.new(
        :id($public-room.id),
        :$home-server,
        :access-token($client.access-token)
    );

    ok $new-room, 'Can .new a room with the id of the public room';
    isa-ok $new-room, Matrix::Client::Room;
    is $new-room.id, $public-room.id, 'The id is the same as the public room';
};

subtest 'name' => {
    plan 4;

    my $name = "Name room test";
    my $test-room = $client.create-room:
        :creation_content({
            "m.federate" => False
        });

    is $test-room.name(), '';

    lives-ok {
        $test-room.send-state('m.room.name', :name($name))
    }, 'Can change name to an unnamed room';

    lives-ok {
        $test-room.name()
    }, '.name with a name set dont die';

    is $test-room.name, $name, 'The name is set correctly';

    $test-room.leave;
};

subtest 'ban' => {
    plan 2;
    my Matrix::Client $new-user-client .= new(:$home-server);
    my $new-username = ('a'..'z').pick(20).join;
    $new-user-client.register($new-username, 'password');
    $new-user-client.join-room($public-room-id);
    my $user-id = $new-user-client.whoami;

    my $room = $client.create-room(
        :public,
        :preset<public_chat>,
        :name("The Grand Duke Pub"),
        :topic("All about happy hour"),
        :creation_content({
            "m.federate" => False
        })
    );

    $new-user-client.join-room($room.id);

    lives-ok {
        $room.ban($user-id, :reason<testing>)
    }, 'can ban usernames';

    lives-ok {
        $room.unban($user-id, :reason<testing>);
    }, 'can unban';
}