line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Mattermost::TestHelper; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
156328
|
use strict; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
242
|
|
6
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
147
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
466
|
use Mojo::Message::Response; |
|
6
|
|
|
|
|
248015
|
|
|
6
|
|
|
|
|
68
|
|
9
|
6
|
|
|
6
|
|
640
|
use Mojo::Transaction::HTTP; |
|
6
|
|
|
|
|
12240
|
|
|
6
|
|
|
|
|
46
|
|
10
|
6
|
|
|
6
|
|
198
|
use Mojo::URL; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
31
|
|
11
|
6
|
|
|
6
|
|
3175
|
use Test::Most; |
|
6
|
|
|
|
|
30560
|
|
|
6
|
|
|
|
|
30
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
101531
|
use WebService::Mattermost; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
161
|
|
16
|
6
|
|
|
6
|
|
38
|
use WebService::Mattermost::V4::API::Resource::Users; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
187
|
|
17
|
6
|
|
|
6
|
|
38
|
use WebService::Mattermost::V4::API::Response; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
273
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use constant { |
20
|
6
|
|
|
|
|
536
|
AUTH_TOKEN => 'whatever', |
21
|
|
|
|
|
|
|
BASE_URL => 'https://my-mattermost-server.com/api/v4', |
22
|
|
|
|
|
|
|
USERNAME => 'myusername', |
23
|
|
|
|
|
|
|
PASSWORD => 'mypassword', |
24
|
6
|
|
|
6
|
|
51
|
}; |
|
6
|
|
|
|
|
13
|
|
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
6
|
|
38
|
use base 'Exporter'; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
69
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
29
|
|
|
|
|
|
|
AUTH_TOKEN |
30
|
|
|
|
|
|
|
BASE_URL |
31
|
|
|
|
|
|
|
PASSWORD |
32
|
|
|
|
|
|
|
USERNAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
client_arguments |
35
|
|
|
|
|
|
|
headers |
36
|
|
|
|
|
|
|
mojo_response |
37
|
|
|
|
|
|
|
mojo_tx |
38
|
|
|
|
|
|
|
resource_url |
39
|
|
|
|
|
|
|
response |
40
|
|
|
|
|
|
|
webservice_mattermost |
41
|
|
|
|
|
|
|
user_resource_expects_login |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
expects_api_call |
44
|
|
|
|
|
|
|
test_id_error |
45
|
|
|
|
|
|
|
test_single_response_of_type |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub client_arguments { |
51
|
42
|
|
100
|
42
|
1
|
72026
|
my $extra = shift || {}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return { |
54
|
|
|
|
|
|
|
authenticate => 1, |
55
|
|
|
|
|
|
|
base_url => BASE_URL, |
56
|
|
|
|
|
|
|
password => PASSWORD, |
57
|
|
|
|
|
|
|
username => USERNAME, |
58
|
|
|
|
|
|
|
|
59
|
42
|
|
|
|
|
118
|
%{$extra} |
|
42
|
|
|
|
|
384
|
|
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub headers { |
64
|
10
|
|
50
|
10
|
0
|
1549
|
my $extra = shift || {}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return { |
67
|
|
|
|
|
|
|
'Keep-Alive' => 1, |
68
|
|
|
|
|
|
|
'Authorization' => 'Bearer '.AUTH_TOKEN, |
69
|
|
|
|
|
|
|
|
70
|
10
|
|
|
|
|
29
|
%{$extra}, |
|
10
|
|
|
|
|
109
|
|
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub mojo_response { |
75
|
28
|
|
100
|
28
|
0
|
134
|
my $args = shift || {}; |
76
|
|
|
|
|
|
|
|
77
|
28
|
|
|
|
|
67
|
return Mojo::Message::Response->new(%{$args}); |
|
28
|
|
|
|
|
233
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub mojo_tx { |
81
|
10
|
|
|
10
|
0
|
174
|
return Mojo::Transaction::HTTP->new(res => mojo_response({ |
82
|
|
|
|
|
|
|
code => 200, |
83
|
|
|
|
|
|
|
message => 'OK', |
84
|
|
|
|
|
|
|
})); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub webservice_mattermost { |
88
|
9
|
|
50
|
9
|
1
|
53020
|
my $extra = shift || {}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return WebService::Mattermost->new({ |
91
|
|
|
|
|
|
|
base_url => BASE_URL, |
92
|
|
|
|
|
|
|
username => USERNAME, |
93
|
|
|
|
|
|
|
password => PASSWORD, |
94
|
|
|
|
|
|
|
|
95
|
9
|
|
|
|
|
28
|
%{$extra}, |
|
9
|
|
|
|
|
282
|
|
96
|
|
|
|
|
|
|
}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub resource_url { |
100
|
10
|
|
|
10
|
0
|
3484
|
my $endpoint = shift; |
101
|
|
|
|
|
|
|
|
102
|
10
|
|
|
|
|
114
|
return Mojo::URL->new(sprintf('%s%s', BASE_URL, $endpoint)); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub response { |
106
|
18
|
|
100
|
18
|
1
|
24645
|
my $args = shift || {}; |
107
|
|
|
|
|
|
|
|
108
|
18
|
|
|
|
|
183
|
my $headers = Mojo::Headers->new(); |
109
|
|
|
|
|
|
|
|
110
|
18
|
|
|
|
|
223
|
$headers->add(token => AUTH_TOKEN); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return WebService::Mattermost::V4::API::Response->new({ |
113
|
|
|
|
|
|
|
content => { id => 'asd1234' }, |
114
|
|
|
|
|
|
|
base_url => BASE_URL, |
115
|
|
|
|
|
|
|
auth_token => AUTH_TOKEN, |
116
|
|
|
|
|
|
|
code => 200, |
117
|
|
|
|
|
|
|
headers => $headers, |
118
|
|
|
|
|
|
|
prev => mojo_response(), |
119
|
|
|
|
|
|
|
|
120
|
18
|
|
|
|
|
496
|
%{$args}, |
|
18
|
|
|
|
|
767
|
|
121
|
|
|
|
|
|
|
}); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub user_resource_expects_login { |
125
|
18
|
|
|
18
|
1
|
42
|
my $responds_with = shift; |
126
|
|
|
|
|
|
|
|
127
|
18
|
|
|
|
|
56
|
my $args = client_arguments(); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
WebService::Mattermost::V4::API::Resource::Users |
130
|
|
|
|
|
|
|
->stubs('login') |
131
|
|
|
|
|
|
|
->with($args->{username}, $args->{password}) |
132
|
18
|
|
|
|
|
156
|
->once |
133
|
|
|
|
|
|
|
->returns($responds_with); |
134
|
|
|
|
|
|
|
|
135
|
18
|
|
|
|
|
5334
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub expects_api_call { |
139
|
10
|
|
|
10
|
0
|
5085
|
my $app = shift; |
140
|
10
|
|
|
|
|
29
|
my $args = shift; |
141
|
|
|
|
|
|
|
|
142
|
10
|
|
|
|
|
26
|
my $resource = $args->{resource}; |
143
|
10
|
100
|
66
|
|
|
84
|
my $form_type = $args->{method} eq 'post' || $args->{method} eq 'put' ? 'json' : 'form'; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
return $app->api->$resource->ua->expects($args->{method})->with_deep( |
146
|
|
|
|
|
|
|
resource_url($args->{url}) => headers(), |
147
|
|
|
|
|
|
|
$form_type => $args->{parameters} || {}, |
148
|
10
|
|
100
|
|
|
264
|
)->returns(mojo_tx())->once; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub test_id_error { |
152
|
2
|
|
|
2
|
0
|
5
|
my $input = shift; |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
16
|
is_deeply { |
155
|
|
|
|
|
|
|
error => 1, |
156
|
|
|
|
|
|
|
message => 'Invalid or missing ID parameter. No API query was made.', |
157
|
|
|
|
|
|
|
}, $input; |
158
|
|
|
|
|
|
|
|
159
|
2
|
|
|
|
|
2027
|
return 1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub test_single_response_of_type { |
163
|
1
|
|
|
1
|
0
|
9
|
my $response = shift; |
164
|
1
|
|
|
|
|
3
|
my $type = shift; |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
3
|
is 1, scalar @{$response->items}; |
|
1
|
|
|
|
|
22
|
|
167
|
|
|
|
|
|
|
|
168
|
1
|
|
|
|
|
687
|
is $type, ref $response->item; |
169
|
|
|
|
|
|
|
|
170
|
1
|
|
|
|
|
471
|
return 1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=pod |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=encoding UTF-8 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 NAME |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
WebService::Mattermost::TestHelper - Helper functions for the library's test suite. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 VERSION |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
version 0.26 |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 DESCRIPTION |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Exports subroutines used by the library's test suite. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 SYNPOSIS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Test files should import the helper as follows: |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Exported functions are listed in METHODS |
200
|
|
|
|
|
|
|
use WebService::Mattermost::TestHelper qw( |
201
|
|
|
|
|
|
|
webservice_mattermost |
202
|
|
|
|
|
|
|
... |
203
|
|
|
|
|
|
|
); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $mattermost = webservice_mattermost(); |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 METHODS |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=over 4 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * C<client_arguments()> |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Basic arguments required for L<WebService::Mattermost>. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * C<response()> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
A dummy L<Mojo::Message::Response>. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * C<webservice_mattermost()> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Creates a L<WebService::Mattermost> object with some defaults. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * C<user_resource_expects_login()> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Stubs the user resource's "login" method with a successful response. This can be |
226
|
|
|
|
|
|
|
used to fake a successful login call. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=back |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Mike Jones <mike@netsplit.org.uk> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Mike Jones. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This is free software, licensed under: |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
The MIT (X11) License |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut |
243
|
|
|
|
|
|
|
|