Project: add test for declarative->normal project transition

[?]
May 5, 2021, 9:42 PM
K4B5ECOH33HAFDGRBRHK2KV7254HZUI3WA3VYWMMXTXLJIWTYESAC

Dependencies

  • [2] 3NGONGQ7 Project: add declfile, decltype, declvalue to API
  • [3] LN3E2P4E t: Test Projects JSON serialization and deserialization
  • [4] 2XGJ54SF ToJSON: serialize string_columns to JSON

Change contents

  • replacement in t/Controller/projects.t at line 4
    [3.56][3.56:82]()
    use JSON qw(decode_json);
    [3.56]
    [3.82]
    use JSON qw(decode_json encode_json);
  • replacement in t/Controller/projects.t at line 20
    [3.336][3.336:441]()
    my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
    [3.336]
    [3.441]
    # 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' });
  • replacement in t/Controller/projects.t at line 25
    [3.442][3.442:524]()
    my $projectinfo = request(GET '/project/tests',
    Accept => 'application/json',
    [3.442]
    [3.524]
    my $project = $db->resultset('Projects')->create({name => "tests", displayname => "Tests", owner => "root"});
    # Login and save cookie for future requests
    my $req = request(POST '/login',
    Referer => 'http://localhost/',
    Content => {
    username => 'alice',
    password => 'foobar'
    }
  • edit in t/Controller/projects.t at line 35
    [3.527]
    [3.527]
    is($req->code, 302);
    my $cookie = $req->header("set-cookie");
  • replacement in t/Controller/projects.t at line 38
    [3.528][3.528:599](),[3.599][3.144:167](),[3.167][3.625:702](),[3.625][3.625:702](),[3.702][3.168:188](),[3.188][3.725:765](),[3.725][3.725:765](),[3.765][2.2385:2493](),[2.2493][3.785:789](),[3.785][3.785:789]()
    ok($projectinfo->is_success);
    is(decode_json($projectinfo->content), {
    description => "",
    displayname => "",
    enabled => JSON::true,
    hidden => JSON::false,
    homepage => "",
    jobsets => [],
    name => "tests",
    owner => "root",
    declarative => {
    file => "",
    type => "",
    value => ""
    }
    });
    [3.528]
    [3.789]
    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",
    enabled => JSON::true,
    hidden => JSON::false,
    homepage => "",
    jobsets => [],
    name => "tests",
    owner => "root",
    declarative => {
    file => "",
    type => "",
    value => ""
    }
    });
    };
    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({
    enabled => JSON::true,
    visible => JSON::true,
    name => "tests",
    displayname => "Tests",
    declarative => {
    file => "bogus",
    type => "boolean",
    value => "false"
    }
    })
    );
    ok($projectupdate->is_success);
    };
  • edit in t/Controller/projects.t at line 82
    [3.790]
    [3.790]
    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",
    enabled => JSON::true,
    hidden => JSON::false,
    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({
    enabled => JSON::true,
    visible => JSON::true,
    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",
    enabled => JSON::true,
    hidden => JSON::false,
    homepage => "",
    jobsets => [],
    name => "tests",
    owner => "root",
    declarative => {
    file => "",
    type => "",
    value => ""
    }
    });
    };
    };