start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / VerifyDeletion / StockObsoletion.t
blob6bd6fb02d5619fe0bf1309762b9fc992794c2189
3 # Tests stock deletion (obsoleted) function on stock detail page through AJAX request
5 use strict;
6 use warnings;
8 use lib 't/lib';
9 use SGN::Test::Fixture;
10 use Test::More;
11 use Test::WWW::Mechanize;
13 #Needed to update IO::Socket::SSL
14 use Data::Dumper;
15 use JSON;
16 use URI::Encode qw(uri_encode uri_decode);
17 use CXGN::Chado::Stock;
18 use LWP::UserAgent;
19 use CXGN::List;
20 use CXGN::Stock::Accession;
21 use CXGN::Trial;
22 local $Data::Dumper::Indent = 0;
24 my $f = SGN::Test::Fixture->new();
25 my $schema = $f->bcs_schema;
26 my $metadata_schema = $f->metadata_schema;
27 my $phenome_schema = $f->phenome_schema;
29 my $mech = Test::WWW::Mechanize->new;
30 my $response;
31 my $json = JSON->new->allow_nonref;
33 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
34 $response = decode_json $mech->content;
35 print STDERR Dumper $response;
36 my $sgn_session_id = $response->{access_token};
38 my $previous_stock_count_all = $schema->resultset("Stock::Stock")->search({})->count();
39 my $previous_stock_count_obsolete = $schema->resultset("Stock::Stock")->search({is_obsolete=>1})->count();
41 my $stock_id = $schema->resultset("Stock::Stock")->find({name=>'test_accession1'})->stock_id;
43 $mech->get_ok('http://localhost:3010/stock/obsolete?stock_id='.$stock_id.'&is_obsolete=1');
44 $response = decode_json $mech->content;
45 print STDERR Dumper $response;
46 is_deeply($response, { message => "Stock obsoleted" }, 'obsolete stock via ajax catalyst controller');
48 my $after_stock_count_all = $schema->resultset("Stock::Stock")->search({})->count();
49 my $after_stock_count_obsolete = $schema->resultset("Stock::Stock")->search({is_obsolete=>1})->count();
51 is($after_stock_count_all, $previous_stock_count_all);
52 is($after_stock_count_obsolete, $previous_stock_count_obsolete + 1);
54 done_testing();