6 use SGN::Test::Fixture;
8 use Test::WWW::Mechanize;
10 use CXGN::BreedersToolbox::Projects;
13 local $Data::Dumper::Indent = 0;
16 my $f = SGN::Test::Fixture->new();
17 my $schema = $f->bcs_schema();
19 for my $extension ("xls", "xlsx") {
21 my $mech = Test::WWW::Mechanize->new;
23 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username" => "janedoe", "password" => "secretpw", "grant_type" => "password" ]);
24 my $response = decode_json $mech->content;
25 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
26 my $session_id = $response->{access_token};
28 my $program_rs = $schema->resultset('Project::Project')->find({ name => 'test' });
29 my $program_id = $program_rs->project_id();
31 my $profile_json_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'product_profile_json', 'project_property')->cvterm_id();
32 my $before_adding_profile_all_projectprop = $schema->resultset("Project::Projectprop")->search({})->count();
33 my $before_adding_profile_projectprop = $schema->resultset("Project::Projectprop")->search({ project_id => $program_id, type_id => $profile_json_type_id })->count();
35 my $file = $f->config->{basepath} . "/t/data/product_profile_test.$extension";
36 my $ua = LWP::UserAgent->new;
37 $response = $ua->post(
38 'http://localhost:3010/ajax/breeders/program/upload_profile',
39 Content_Type => 'form-data',
41 "profile_uploaded_file" => [
43 "product_profile_test.$extension",
44 Content_Type => ($extension eq "xls") ? 'application/vnd.ms-excel' : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
46 "profile_program_id" => $program_id,
47 "new_profile_name" => 'product_profile_1',
48 "new_profile_scope" => 'test_upload',
49 "sgn_session_id" => $session_id
53 ok($response->is_success);
54 my $message = $response->decoded_content;
55 my $message_hash = decode_json $message;
56 is_deeply($message_hash, { 'success' => 1 });
58 my $after_adding_profile_all_projectprop = $schema->resultset("Project::Projectprop")->search({})->count();
59 my $after_adding_profile_projectprop = $schema->resultset("Project::Projectprop")->search({ project_id => $program_id, type_id => $profile_json_type_id })->count();
60 is($after_adding_profile_all_projectprop, $before_adding_profile_all_projectprop + 1);
61 is($after_adding_profile_projectprop, $before_adding_profile_projectprop + 1);