# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

#######################################
# Tests for REST calls in Bugzilla.pm #
#######################################

use 5.10.1;
use strict;
use warnings;
use lib qw(lib ../../lib ../../local/lib/perl5);

use Test::More tests => 8;
use QA::REST;

my $rest   = get_rest_client();
my $config = $rest->bz_config;

my $version = $rest->call('version')->{version};
ok($version, "GET /rest/version returns $version");

my $extensions = $rest->call('extensions')->{extensions};
isa_ok($extensions, 'HASH', 'GET /rest/extensions');
my @ext_names = sort keys %$extensions;

# There is always at least the QA extension enabled.
ok(scalar(@ext_names),
  scalar(@ext_names) . ' extension(s) found: ' . join(', ', @ext_names));
ok($extensions->{QA},
  'The QA extension is enabled, with version ' . $extensions->{QA}->{version});

my $timezone = $rest->call('timezone')->{timezone};
ok($timezone, "GET /rest/timezone returns $timezone");

my $time = $rest->call('time');
foreach my $type (qw(db_time web_time)) {
  ok($time->{$type}, "GET /rest/time returns $type = " . $time->{$type});
}

my $jobqueue_errors
  = $rest->call('jobqueue_status', {api_key => $config->{admin_user_api_key}})
  ->{errors};
ok(!$jobqueue_errors, "GET /rest/jobqueue_status returns zero errors");
