Merge pull request #4073 from solgenomics/topic/fix_another_type_id_issue
[sgn.git] / t / unit_mech / AJAX / Stability.t
blob7593f9c4c2f6e85580c805ae8f9fcb2d7bbcac13
2 use strict;
3 use warnings;
5 use lib 't/lib';
6 use SGN::Test::Fixture;
7 use Test::More;
8 use Test::WWW::Mechanize;
10 use Data::Dumper;
11 use JSON;
12 use Spreadsheet::Read;
14 use CXGN::Dataset;
16 my $f = SGN::Test::Fixture->new();
17 my $schema = $f->bcs_schema;
18 my $people_schema = $f->people_schema();
20 my $mech = Test::WWW::Mechanize->new;
21 my $response;
23 # login
25 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ], 'login with brapi call');
27 $response = decode_json $mech->content;
29 is($response->{'userDisplayName'}, 'Jane Doe', 'check login name');
31 # create a suitable dataset
33 my $ds = CXGN::Dataset->new( { schema=> $schema, people_schema => $people_schema });
35 $ds->trials( [ 139, 141 ]);
36 $ds->store();
38 my $dataset_id = $ds->sp_dataset_id();
40 $mech->get_ok('http://localhost:3010/tools/stability', 'load stability input page');
42 $mech->get_ok('http://localhost:3010/ajax/stability/shared_phenotypes?dataset_id='.$dataset_id, 'get common traits for dataset');
44 my $sp_data = JSON::Any->decode($mech->content());
46 my $trait_id = $sp_data->{options}->[0]->[0];
48 $mech->get_ok('http://localhost:3010//ajax/stability/generate_results?dataset_id='.$dataset_id.'&trait_id='.$trait_id."&method_id=AMMI", 'run the AMMI analysis');
50 my $rdata = JSON::Any->decode($mech->content());
52 # check if files were created
54 ok( -e "static/".$rdata->{figure1}, "AMMI figure 1 created");
55 ok( -e "static/".$rdata->{figure2}, "AMMI figure 2 created");
56 ok( -e "static/".$rdata->{AMMITable}, "AMMI table created");
58 $mech->get_ok('http://localhost:3010//ajax/stability/generate_results?dataset_id='.$dataset_id.'&trait_id='.$trait_id."&method_id=GGE", 'run the GGE analysis');
60 my $rdata2 = JSON::Any->decode($mech->content());
62 # check if files were created
64 ok( -e "static/".$rdata2->{figure1}, "GGE figure 1 created");
65 ok( -e "static/".$rdata2->{figure2}, "GGE figure 2 created");
66 ok( -e "static/".$rdata2->{AMMITable}, "GGE table created");
68 # remove changes to the database
70 $ds->delete();
72 done_testing();