summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/t/feed-daemon-guts.t
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/PhabBugz/t/feed-daemon-guts.t')
-rw-r--r--extensions/PhabBugz/t/feed-daemon-guts.t191
1 files changed, 92 insertions, 99 deletions
diff --git a/extensions/PhabBugz/t/feed-daemon-guts.t b/extensions/PhabBugz/t/feed-daemon-guts.t
index 0c508be98..44d65eab4 100644
--- a/extensions/PhabBugz/t/feed-daemon-guts.t
+++ b/extensions/PhabBugz/t/feed-daemon-guts.t
@@ -24,8 +24,11 @@ use Digest::SHA qw(sha1_hex);
use ok 'Bugzilla::Extension::PhabBugz::Feed';
use ok 'Bugzilla::Extension::PhabBugz::Constants', 'PHAB_AUTOMATION_USER';
-use ok 'Bugzilla::Config', 'SetParam';
-can_ok('Bugzilla::Extension::PhabBugz::Feed', qw( group_query feed_query user_query ));
+use ok 'Bugzilla::Config', 'SetParam';
+can_ok(
+ 'Bugzilla::Extension::PhabBugz::Feed',
+ qw( group_query feed_query user_query )
+);
Bugzilla->error_mode(ERROR_MODE_TEST);
@@ -34,127 +37,117 @@ my $phab_bot = create_user(PHAB_AUTOMATION_USER, '*');
my $UserAgent = mock 'Mojo::UserAgent' => ();
{
- SetParam('phabricator_enabled', 0);
- my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
- my $Feed = mock 'Bugzilla::Extension::PhabBugz::Feed' => (
- override => [
- get_last_id => sub { die "get_last_id" },
- ],
- );
-
- foreach my $method (qw( feed_query user_query group_query )) {
- try {
- $feed->$method;
- pass "disabling the phabricator sync: $method";
- }
- catch {
- fail "disabling the phabricator sync: $method";
- }
+ SetParam('phabricator_enabled', 0);
+ my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+ my $Feed = mock 'Bugzilla::Extension::PhabBugz::Feed' =>
+ (override => [get_last_id => sub { die "get_last_id" },],);
+
+ foreach my $method (qw( feed_query user_query group_query )) {
+ try {
+ $feed->$method;
+ pass "disabling the phabricator sync: $method";
+ }
+ catch {
+ fail "disabling the phabricator sync: $method";
}
+ }
}
my @bad_response = (
- ['http error', mock_useragent_tx("doesn't matter", sub { $_->code(500) }) ],
- ['invalid json', mock_useragent_tx('<xml>foo</xml>') ],
- ['json containing error code', mock_useragent_tx(encode_json({error_code => 1234 }))],
+ ['http error', mock_useragent_tx("doesn't matter", sub { $_->code(500) })],
+ ['invalid json', mock_useragent_tx('<xml>foo</xml>')],
+ [
+ 'json containing error code',
+ mock_useragent_tx(encode_json({error_code => 1234}))
+ ],
);
-SetParam(phabricator_enabled => 1);
-SetParam(phabricator_api_key => 'FAKE-API-KEY');
+SetParam(phabricator_enabled => 1);
+SetParam(phabricator_api_key => 'FAKE-API-KEY');
SetParam(phabricator_base_uri => 'http://fake.fabricator.tld/');
foreach my $bad_response (@bad_response) {
- my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
- $UserAgent->override(
- post => sub {
- my ( $self, $url, undef, $params ) = @_;
- return $bad_response->[1];
- }
- );
-
- foreach my $method (qw( feed_query user_query group_query )) {
- try {
- # This is a hack to get reasonable exception objects.
- local $Bugzilla::Template::is_processing = 1;
- $feed->$method;
- fail "$method - $bad_response->[0]";
- }
- catch {
- is( $_->type, 'bugzilla.code.phabricator_api_error', "$method - $bad_response->[0]" );
- };
+ my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+ $UserAgent->override(
+ post => sub {
+ my ($self, $url, undef, $params) = @_;
+ return $bad_response->[1];
}
- $UserAgent->reset('post');
+ );
+
+ foreach my $method (qw( feed_query user_query group_query )) {
+ try {
+ # This is a hack to get reasonable exception objects.
+ local $Bugzilla::Template::is_processing = 1;
+ $feed->$method;
+ fail "$method - $bad_response->[0]";
+ }
+ catch {
+ is(
+ $_->type,
+ 'bugzilla.code.phabricator_api_error',
+ "$method - $bad_response->[0]"
+ );
+ };
+ }
+ $UserAgent->reset('post');
}
-my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
-my $json = JSON::MaybeXS->new( canonical => 1, pretty => 1 );
-my $dylan = create_user( 'dylan@mozilla.com', '*', realname => 'Dylan Hardison :dylan' );
-my $evildylan = create_user( 'dylan@gmail.com', '*', realname => 'Evil Dylan :dylan' );
-my $myk = create_user( 'myk@mozilla.com', '*', realname => 'Myk Melez :myk' );
+my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+my $json = JSON::MaybeXS->new(canonical => 1, pretty => 1);
+my $dylan
+ = create_user('dylan@mozilla.com', '*', realname => 'Dylan Hardison :dylan');
+my $evildylan
+ = create_user('dylan@gmail.com', '*', realname => 'Evil Dylan :dylan');
+my $myk = create_user('myk@mozilla.com', '*', realname => 'Myk Melez :myk');
my $phab_bot_phid = next_phid('PHID-USER');
done_testing;
sub user_search {
- my (%conf) = @_;
-
- return {
- error_info => undef,
- error_code => undef,
- result => {
- cursor => {
- after => $conf{after},
- order => undef,
- limit => 100,
- before => undef
+ my (%conf) = @_;
+
+ return {
+ error_info => undef,
+ error_code => undef,
+ result => {
+ cursor =>
+ {after => $conf{after}, order => undef, limit => 100, before => undef},
+ query => {queryKey => undef},
+ maps => {},
+ data => [
+ map {
+ +{
+ attachments => {
+ $_->{bmo_id}
+ ? ("external-accounts" =>
+ {"external-accounts" => [{type => 'bmo', id => $_->{bmo_id},}]})
+ : (),
},
- query => {
- queryKey => undef
+ fields => {
+ roles => ["verified", "approved", "activated"],
+ realName => $_->{realname},
+ dateModified => time,
+ policy => {view => "public", edit => "no-one"},
+ dateCreated => time,
+ username => $_->{username},
},
- maps => {},
- data => [
- map {
- +{
- attachments => {
- $_->{bmo_id}
- ? ( "external-accounts" => {
- "external-accounts" => [
- {
- type => 'bmo',
- id => $_->{bmo_id},
- }
- ]
- }
- )
- : (),
- },
- fields => {
- roles => [ "verified", "approved", "activated" ],
- realName => $_->{realname},
- dateModified => time,
- policy => {
- view => "public",
- edit => "no-one"
- },
- dateCreated => time,
- username => $_->{username},
- },
- phid => next_phid("PHID-USER"),
- type => "USER",
- id => $_->{phab_id},
- },
- } @{ $conf{users} },
- ]
- }
- };
+ phid => next_phid("PHID-USER"),
+ type => "USER",
+ id => $_->{phab_id},
+ },
+ } @{$conf{users}},
+ ]
+ }
+ };
}
sub next_phid {
- my ($prefix) = @_;
- state $number = 'a' x 20;
- return $prefix . '-' . ($number++);
+ my ($prefix) = @_;
+ state $number = 'a' x 20;
+ return $prefix . '-' . ($number++);
}