combined all new cvterms
[sgn.git] / t / unit_mech / AJAX / Fieldbook.t
blobe657fb0180babd79939775332661205fe4b8cfa7
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 my $f = SGN::Test::Fixture->new();
15 my $schema = $f->bcs_schema;
17 my $mech = Test::WWW::Mechanize->new;
18 my $response;
20 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
21 $response = decode_json $mech->content;
22 print STDERR Dumper $response;
23 is($response->{'userDisplayName'}, 'Jane Doe');
25 my $trial_id = 137;
26 my $data_level = 'plots';
27 my $selected_columns = encode_json {'plot_name'=>1,'block_number'=>1,'plot_number'=>1,'rep_number'=>1,'row_number'=>1,'col_number'=>1,'accession_name'=>1,'is_a_control'=>1,'pedigree'=>1,'location_name'=>1,'trial_name'=>1,'year'=>1,'synonyms'=>1,'tier'=>1,'seedlot_name'=>1,'seed_transaction_operator'=>1,'num_seed_per_plot'=>1};
28 my $trait_list = 13;
30 $mech->post_ok('http://localhost:3010/ajax/fieldbook/create', ['trial_id'=>$trial_id, 'data_level'=>$data_level, 'selected_columns'=>$selected_columns, 'trait_list'=>$trait_list] );
31 $response = decode_json $mech->content;
32 print STDERR Dumper $response;
33 my $file_name = $response->{file};
35 my $contents = ReadData ($file_name);
36 #print STDERR Dumper $contents;
38 my $cells = $contents->[1]->{cell};
39 print STDERR Dumper $cells;
40 is_deeply($cells, [
41           [],
42           [
43             undef,
44             'plot_name',
45             'test_trial21',
46             'test_trial22',
47             'test_trial23',
48             'test_trial24',
49             'test_trial25',
50             'test_trial26',
51             'test_trial27',
52             'test_trial28',
53             'test_trial29',
54             'test_trial210',
55             'test_trial211',
56             'test_trial212',
57             'test_trial213',
58             'test_trial214',
59             'test_trial215'
60           ],
61           [
62             undef,
63             'accession_name',
64             'test_accession4',
65             'test_accession5',
66             'test_accession3',
67             'test_accession3',
68             'test_accession1',
69             'test_accession4',
70             'test_accession5',
71             'test_accession1',
72             'test_accession2',
73             'test_accession3',
74             'test_accession1',
75             'test_accession5',
76             'test_accession2',
77             'test_accession4',
78             'test_accession2'
79           ],
80           [
81             undef,
82             'plot_number',
83             '1',
84             '2',
85             '3',
86             '4',
87             '5',
88             '6',
89             '7',
90             '8',
91             '9',
92             '10',
93             '11',
94             '12',
95             '13',
96             '14',
97             '15'
98           ],
99           [
100             undef,
101             'block_number',
102             '1',
103             '1',
104             '1',
105             '1',
106             '1',
107             '1',
108             '1',
109             '1',
110             '1',
111             '1',
112             '1',
113             '1',
114             '1',
115             '1',
116             '1'
117           ],
118           [
119             undef,
120             'is_a_control'
121           ],
122           [
123             undef,
124             'rep_number',
125             '1',
126             '1',
127             '1',
128             '2',
129             '1',
130             '2',
131             '2',
132             '2',
133             '1',
134             '3',
135             '3',
136             '3',
137             '2',
138             '3',
139             '3'
140           ],
141           [
142             undef,
143             'row_number'
144           ],
145           [
146             undef,
147             'col_number'
148           ],
149           [
150             undef,
151             'seedlot_name'
152           ],
153           [
154             undef,
155             'seed_transaction_operator'
156           ],
157           [
158             undef,
159             'num_seed_per_plot'
160           ],
161           [
162             undef,
163             'pedigree',
164             'test_accession1/test_accession2',
165             'test_accession3/NA',
166             'NA/NA',
167             'NA/NA',
168             'NA/NA',
169             'test_accession1/test_accession2',
170             'test_accession3/NA',
171             'NA/NA',
172             'NA/NA',
173             'NA/NA',
174             'NA/NA',
175             'test_accession3/NA',
176             'NA/NA',
177             'test_accession1/test_accession2',
178             'NA/NA'
179           ],
180           [
181             undef,
182             'location_name',
183             'test_location',
184             'test_location',
185             'test_location',
186             'test_location',
187             'test_location',
188             'test_location',
189             'test_location',
190             'test_location',
191             'test_location',
192             'test_location',
193             'test_location',
194             'test_location',
195             'test_location',
196             'test_location',
197             'test_location'
198           ],
199           [
200             undef,
201             'trial_name',
202             'test_trial',
203             'test_trial',
204             'test_trial',
205             'test_trial',
206             'test_trial',
207             'test_trial',
208             'test_trial',
209             'test_trial',
210             'test_trial',
211             'test_trial',
212             'test_trial',
213             'test_trial',
214             'test_trial',
215             'test_trial',
216             'test_trial'
217           ],
218           [
219             undef,
220             'year',
221             '2014',
222             '2014',
223             '2014',
224             '2014',
225             '2014',
226             '2014',
227             '2014',
228             '2014',
229             '2014',
230             '2014',
231             '2014',
232             '2014',
233             '2014',
234             '2014',
235             '2014'
236           ],
237           [
238             undef,
239             'synonyms',
240             undef,
241             undef,
242             'test_accession3_synonym1',
243             'test_accession3_synonym1',
244             'test_accession1_synonym1',
245             undef,
246             undef,
247             'test_accession1_synonym1',
248             'test_accession2_synonym1,test_accession2_synonym2',
249             'test_accession3_synonym1',
250             'test_accession1_synonym1',
251             undef,
252             'test_accession2_synonym1,test_accession2_synonym2',
253             undef,
254             'test_accession2_synonym1,test_accession2_synonym2'
255           ],
256           [
257             undef,
258             'tier',
259             '/',
260             '/',
261             '/',
262             '/',
263             '/',
264             '/',
265             '/',
266             '/',
267             '/',
268             '/',
269             '/',
270             '/',
271             '/',
272             '/',
273             '/'
274           ]
275         ], 'test fieldbook ajax file contents');
278 $f->clean_up_db();
279 done_testing;