Merge pull request #1716 from solgenomics/topic/seedlot_upload_fix
[sgn.git] / t / unit_fixture / CXGN / BreederSearch.t
blobaf913fd19175bec23617e2779361189ad725529b
2 use strict;
4 use lib 't/lib';
6 use Test::More;
7 use SGN::Test::Fixture;
8 use CXGN::BreederSearch;
9 use Data::Dumper;
11 my $f = SGN::Test::Fixture->new();
13 my $bs = CXGN::BreederSearch->new( { dbh=> $f->dbh() });
15 my $criteria_list = [
16                'years'
17              ];
18 my $dataref = {};
19 my $queryref = {};
21 my $results = $bs->metadata_query($criteria_list, $dataref, $queryref);
22 #print STDERR Dumper $results;
23 is_deeply($results, {
24                'results' => [
25                               [
26                                 '2014',
27                                 '2014'
28                               ],
29                               [
30                                 '2015',
31                                 '2015'
32                               ],
33                               [
34                                 '2016',
35                                 '2016'
36                               ],
37                               [
38                                 '2017',
39                                 '2017'
40                               ]
41                             ]
42              }, 'wizard one category query');
44 $criteria_list = [
45                'years',
46                'locations'
47              ];
48 $dataref = {
49                'locations' => {
50                               'years' => '\'2014\''
51                             }
52              };
53 $queryref = {
54                'locations' => {
55                               'years' => 0
56                             }
57              };
59 $results = $bs->metadata_query($criteria_list, $dataref, $queryref);
60 is_deeply($results, {
61                'results' => [
62                               [
63                                 23,
64                                 'test_location'
65                               ]
66                             ]
67              }, "wizard two category query" );
69 $criteria_list = [
70                'years',
71                'locations',
72                'trials'
73              ];
74 $dataref = {
75                'trials' => {
76                            'locations' => '\'23\'',
77                            'years' => '\'2014\''
78                          }
79              };
80 $queryref = {
81                'trials' => {
82                            'locations' => 0,
83                            'years' => 0
84                          }
85              };
86 $results = $bs ->metadata_query($criteria_list, $dataref, $queryref);
87 is_deeply($results, {
88                'results' => [
89                               [
90                                 139,
91                                 'Kasese solgs trial'
92                               ],
93                               [
94                                 137,
95                                 'test_trial'
96                               ],
97                               [
98                                 141,
99                                 'trial2 NaCRRI'
100                               ]
101                             ]
102              }, "wizard three category query");
104 $criteria_list = [
105                'years',
106                'locations',
107                'trials',
108                'genotyping_protocols'
109              ];
110 $dataref = {
111                'genotyping_protocols' => {
112                                          'trials' => '\'139\'',
113                                          'locations' => '\'23\'',
114                                          'years' => '\'2014\''
115                                        }
116              };
117 $queryref = {
118                'genotyping_protocols' => {
119                                          'trials' => 0,
120                                          'locations' => 0,
121                                          'years' => 0
122                                        }
123              };
124 $results = $bs ->metadata_query($criteria_list, $dataref, $queryref);
125 is_deeply($results, {
126                'results' => [
127                               [
128                                 1,
129                                 'GBS ApeKI genotyping v4'
130                               ]
131                             ]
132              }, "wizard four category query");
134 $criteria_list = [
135                'breeding_programs',
136                'trials',
137                'traits'
138              ];
139 $dataref = {
140                'traits' => {
141                            'trials' => '\'139\',\'141\'',
142                            'breeding_programs' => '\'134\''
143                          }
144              };
145 $queryref = {
146                'traits' => {
147                            'trials' => 1,
148                            'breeding_programs' => 0
149                          }
150              };
151 $results = $bs ->metadata_query($criteria_list, $dataref, $queryref);
152 is_deeply($results, {
153                'results' => [
154                               [
155                                 70741,
156                                 'dry matter content percentage|CO_334:0000092'
157                               ],
158                               [
159                                 70666,
160                                 'fresh root weight|CO_334:0000012'
161                               ],
162                               [
163                                 70773,
164                                 'fresh shoot weight measurement in kg|CO_334:0000016'
165                               ]
166                             ]
167              }, "wizard intersect query");
169 $criteria_list = [
170                'trials',
171                'accessions',
172                'plots'
173              ];
174 $dataref = {
175                'plots' => {
176                           'trials' => '\'137\'',
177                           'accessions' => '\'38840\',\'38841\''
178                         }
179              };
180 $queryref = {
181                'plots' => {
182                           'trials' => 0,
183                           'accessions' => 1
184                         }
185              };
186 $results = $bs ->metadata_query($criteria_list, $dataref, $queryref);
187 is_deeply($results, {
188                'results' => []
189              }, "wizard 0 results error query");
191 done_testing();