#!perl -T
note
'test first with the token in the QS'
;
my
$conf
= Plack::App::PubSubHubbub::Subscriber::Config->new(
token_in_path
=> 0,
);
my
$client
= Plack::App::PubSubHubbub::Subscriber::Client->new(
config
=>
$conf
,
);
isa_ok
$client
,
'Plack::App::PubSubHubbub::Subscriber::Client'
;
note
'subscribe'
;
{
my
$request
=
$client
->subscribe_request(
"mytoken"
,
);
isa_ok
$request
,
'HTTP::Request'
;
is
$request
->method,
'POST'
,
'method'
;
my
$uri
= URI->new(
'http:'
);
$uri
->query(
$request
->content);
my
%args
=
$uri
->query_form;
my
$expected
= {
'hub.mode'
=>
'subscribe'
,
'hub.verify'
=>
'sync'
,
'hub.verify_token'
=>
'mytoken'
};
is_deeply(\
%args
,
$expected
,
'request content'
);
}
note
'unsubscribe'
;
{
my
$request
=
$client
->unsubscribe_request(
"mytoken"
,
);
isa_ok
$request
,
'HTTP::Request'
;
is
$request
->method,
'POST'
,
'method'
;
my
$uri
= URI->new(
'http:'
);
$uri
->query(
$request
->content);
my
%args
=
$uri
->query_form;
my
$expected
= {
'hub.mode'
=>
'unsubscribe'
,
'hub.verify'
=>
'sync'
,
'hub.verify_token'
=>
'mytoken'
};
is_deeply(\
%args
,
$expected
,
'request content'
);
}
note
'with token in path'
;
$client
->config->{token_in_path} = 1;
note
'subscribe'
;
{
my
$request
=
$client
->subscribe_request(
"mytoken"
,
);
isa_ok
$request
,
'HTTP::Request'
;
is
$request
->method,
'POST'
,
'method'
;
my
$uri
= URI->new(
'http:'
);
$uri
->query(
$request
->content);
my
%args
=
$uri
->query_form;
my
$expected
= {
'hub.mode'
=>
'subscribe'
,
'hub.verify'
=>
'sync'
,
};
is_deeply(\
%args
,
$expected
,
'request content'
);
}
note
'unsubscribe'
;
{
my
$request
=
$client
->unsubscribe_request(
"mytoken"
,
);
isa_ok
$request
,
'HTTP::Request'
;
is
$request
->method,
'POST'
,
'method'
;
my
$uri
= URI->new(
'http:'
);
$uri
->query(
$request
->content);
my
%args
=
$uri
->query_form;
my
$expected
= {
'hub.mode'
=>
'unsubscribe'
,
'hub.verify'
=>
'sync'
,
};
is_deeply(\
%args
,
$expected
,
'request content'
);
}
note
"inject token"
;
sub
test_inject_token {
my
(
$base
,
$token
,
$expected
) =
@_
;
cmp_ok(
Plack::App::PubSubHubbub::Subscriber::Client::_inject_token(
$base
,
$token
),
'eq'
,
$expected
,
"inject token: $expected"
);
}