Skip to content

Commit

Permalink
Merge pull request #2231 from solgenomics/topic/trial_stock_deletion
Browse files Browse the repository at this point in the history
fix trial deletion of stocks
  • Loading branch information
aco46 committed Oct 18, 2018
2 parents 3e6a025 + 8307c14 commit 1f8ba04
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/CXGN/Trial.pm
Expand Up @@ -1652,7 +1652,9 @@ sub _delete_field_layout_experiment {

#print STDERR Dumper \@all_stock_ids;
my $stock_delete_rs = $self->bcs_schema->resultset('Stock::Stock')->search({stock_id=>{'-in'=>\@all_stock_ids}});
$stock_delete_rs->delete();
while (my $r = $stock_delete_rs->next){
$r->delete();
}

my $has_plants = $self->has_plant_entries();
my $has_subplots = $self->has_subplot_entries();
Expand Down
76 changes: 76 additions & 0 deletions t/unit_fixture/CXGN/VerifyDeletion/TrialDeletion.t
@@ -0,0 +1,76 @@


# Tests trial deletion functions as they are used from the trial detail page through AJAX requests

use strict;
use warnings;

use lib 't/lib';
use SGN::Test::Fixture;
use Test::More;
use Test::WWW::Mechanize;

#Needed to update IO::Socket::SSL
use Data::Dumper;
use JSON;
use URI::Encode qw(uri_encode uri_decode);
use CXGN::Chado::Stock;
use LWP::UserAgent;
use CXGN::List;
use CXGN::Stock::Accession;
use CXGN::Trial;
local $Data::Dumper::Indent = 0;

my $f = SGN::Test::Fixture->new();
my $schema = $f->bcs_schema;
my $metadata_schema = $f->metadata_schema;
my $phenome_schema = $f->phenome_schema;

my $mech = Test::WWW::Mechanize->new;
my $response;
my $json = JSON->new->allow_nonref;

$mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
$response = decode_json $mech->content;
print STDERR Dumper $response;
is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
my $sgn_session_id = $response->{access_token};

my $project_rs = $schema->resultset("Project::Project")->find({name=>'CASS_6Genotypes_Sampling_2015'});
my $project_id = $project_rs->project_id;

my $trial = CXGN::Trial->new({
bcs_schema => $schema,
metadata_schema => $metadata_schema,
phenome_schema => $phenome_schema,
trial_id => $project_id
});

my $traits_assayed = $trial->get_traits_assayed();
my @trait_ids;
foreach (@$traits_assayed){
push @trait_ids, $_->[0];
}

$mech->get_ok('http://localhost:3010/ajax/breeders/trial/'.$project_id.'/delete/layout');
$response = decode_json $mech->content;
print STDERR Dumper $response;
ok($response->{'error'});

$mech->post_ok('http://localhost:3010/ajax/breeders/trial/'.$project_id.'/delete_single_trait', [ "traits_id"=> encode_json(\@trait_ids) ]);
$response = decode_json $mech->content;
print STDERR Dumper $response;
is_deeply($response, {'success' => 1});

$mech->get_ok('http://localhost:3010/ajax/breeders/trial/'.$project_id.'/delete/layout');
$response = decode_json $mech->content;
print STDERR Dumper $response;
is_deeply($response, {'message' => 'Successfully deleted trial data.','success' => 1}, 'test trial layout + entry deletion');

my $project_rs_after_delete = $schema->resultset("Project::Project")->find({name=>'CASS_6Genotypes_Sampling_2015'});
ok(!$project_rs_after_delete);

my $plot_rs_after_delete = $schema->resultset("Stock::Stock")->find({name=>'CASS_6Genotypes_103'});
ok(!$plot_rs_after_delete);

done_testing();

0 comments on commit 1f8ba04

Please sign in to comment.