2021-04-26 23:29:04 +00:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
use strict;
|
2021-08-19 20:36:43 +00:00
|
|
|
use warnings;
|
2021-04-26 23:29:04 +00:00
|
|
|
use Setup;
|
2021-10-20 02:53:39 +00:00
|
|
|
use JSON::MaybeXS qw(decode_json encode_json);
|
2021-04-26 23:29:04 +00:00
|
|
|
|
|
|
|
my %ctx = test_init();
|
|
|
|
|
|
|
|
require Hydra::Schema;
|
|
|
|
require Hydra::Model::DB;
|
|
|
|
require Hydra::Helper::Nix;
|
|
|
|
use HTTP::Request::Common;
|
|
|
|
|
|
|
|
use Test2::V0;
|
|
|
|
require Catalyst::Test;
|
|
|
|
Catalyst::Test->import('Hydra');
|
|
|
|
|
|
|
|
my $db = Hydra::Model::DB->new;
|
|
|
|
hydra_setup($db);
|
|
|
|
|
2021-05-05 21:42:53 +00:00
|
|
|
# Create a user to log in to
|
|
|
|
my $user = $db->resultset('Users')->create({ username => 'alice', emailaddress => 'root@invalid.org', password => '!' });
|
|
|
|
$user->setPassword('foobar');
|
|
|
|
$user->userroles->update_or_create({ role => 'admin' });
|
2021-04-26 23:29:04 +00:00
|
|
|
|
2021-05-05 21:42:53 +00:00
|
|
|
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "Tests", owner => "root"});
|
2021-04-26 23:29:04 +00:00
|
|
|
|
2021-05-05 21:42:53 +00:00
|
|
|
# Login and save cookie for future requests
|
|
|
|
my $req = request(POST '/login',
|
|
|
|
Referer => 'http://localhost/',
|
|
|
|
Content => {
|
|
|
|
username => 'alice',
|
|
|
|
password => 'foobar'
|
2021-05-02 06:27:47 +00:00
|
|
|
}
|
2021-05-05 21:42:53 +00:00
|
|
|
);
|
|
|
|
is($req->code, 302);
|
|
|
|
my $cookie = $req->header("set-cookie");
|
|
|
|
|
|
|
|
subtest "Read project 'tests'" => sub {
|
|
|
|
my $projectinfo = request(GET '/project/tests',
|
|
|
|
Accept => 'application/json',
|
|
|
|
);
|
|
|
|
|
|
|
|
ok($projectinfo->is_success);
|
|
|
|
is(decode_json($projectinfo->content), {
|
|
|
|
description => "",
|
|
|
|
displayname => "Tests",
|
2021-10-20 02:53:39 +00:00
|
|
|
enabled => JSON::MaybeXS::true,
|
2021-12-15 20:41:55 +00:00
|
|
|
enable_dynamic_run_command => JSON::MaybeXS::false,
|
2021-10-20 02:53:39 +00:00
|
|
|
hidden => JSON::MaybeXS::false,
|
2021-05-05 21:42:53 +00:00
|
|
|
homepage => "",
|
|
|
|
jobsets => [],
|
|
|
|
name => "tests",
|
2021-05-24 22:22:25 +00:00
|
|
|
owner => "root"
|
2021-05-05 21:42:53 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Transitioning from declarative project to normal" => sub {
|
|
|
|
subtest "Make project declarative" => sub {
|
|
|
|
my $projectupdate = request(PUT '/project/tests',
|
|
|
|
Accept => 'application/json',
|
|
|
|
Content_Type => 'application/json',
|
|
|
|
Cookie => $cookie,
|
|
|
|
Content => encode_json({
|
2021-10-20 02:53:39 +00:00
|
|
|
enabled => JSON::MaybeXS::true,
|
|
|
|
visible => JSON::MaybeXS::true,
|
2021-05-05 21:42:53 +00:00
|
|
|
name => "tests",
|
|
|
|
displayname => "Tests",
|
|
|
|
declarative => {
|
|
|
|
file => "bogus",
|
|
|
|
type => "boolean",
|
|
|
|
value => "false"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
ok($projectupdate->is_success);
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Project has '.jobsets' jobset" => sub {
|
|
|
|
my $projectinfo = request(GET '/project/tests',
|
|
|
|
Accept => 'application/json',
|
|
|
|
);
|
|
|
|
|
|
|
|
ok($projectinfo->is_success);
|
|
|
|
is(decode_json($projectinfo->content), {
|
|
|
|
description => "",
|
|
|
|
displayname => "Tests",
|
2021-10-20 02:53:39 +00:00
|
|
|
enabled => JSON::MaybeXS::true,
|
2021-12-15 20:41:55 +00:00
|
|
|
enable_dynamic_run_command => JSON::MaybeXS::false,
|
2021-10-20 02:53:39 +00:00
|
|
|
hidden => JSON::MaybeXS::false,
|
2021-05-05 21:42:53 +00:00
|
|
|
homepage => "",
|
|
|
|
jobsets => [".jobsets"],
|
|
|
|
name => "tests",
|
|
|
|
owner => "root",
|
|
|
|
declarative => {
|
|
|
|
file => "bogus",
|
|
|
|
type => "boolean",
|
|
|
|
value => "false"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Make project normal" => sub {
|
|
|
|
my $projectupdate = request(PUT '/project/tests',
|
|
|
|
Accept => 'application/json',
|
|
|
|
Content_Type => 'application/json',
|
|
|
|
Cookie => $cookie,
|
|
|
|
Content => encode_json({
|
2021-10-20 02:53:39 +00:00
|
|
|
enabled => JSON::MaybeXS::true,
|
|
|
|
visible => JSON::MaybeXS::true,
|
2021-05-05 21:42:53 +00:00
|
|
|
name => "tests",
|
|
|
|
displayname => "Tests",
|
|
|
|
declarative => {
|
|
|
|
file => "",
|
|
|
|
type => "boolean",
|
|
|
|
value => "false"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
ok($projectupdate->is_success);
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Project doesn't have '.jobsets' jobset" => sub {
|
|
|
|
my $projectinfo = request(GET '/project/tests',
|
|
|
|
Accept => 'application/json',
|
|
|
|
);
|
|
|
|
|
|
|
|
ok($projectinfo->is_success);
|
|
|
|
is(decode_json($projectinfo->content), {
|
|
|
|
description => "",
|
|
|
|
displayname => "Tests",
|
2021-10-20 02:53:39 +00:00
|
|
|
enabled => JSON::MaybeXS::true,
|
2021-12-15 20:41:55 +00:00
|
|
|
enable_dynamic_run_command => JSON::MaybeXS::false,
|
2021-10-20 02:53:39 +00:00
|
|
|
hidden => JSON::MaybeXS::false,
|
2021-05-05 21:42:53 +00:00
|
|
|
homepage => "",
|
|
|
|
jobsets => [],
|
|
|
|
name => "tests",
|
2021-05-24 22:22:25 +00:00
|
|
|
owner => "root"
|
2021-05-05 21:42:53 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2021-04-26 23:29:04 +00:00
|
|
|
|
|
|
|
done_testing;
|