|
5 | 5 |
|
6 | 6 | describe Chemotion::SuggestionAPI do
|
7 | 7 | let!(:user) { create(:person, first_name: 'tam', last_name: 'M') }
|
| 8 | + let(:material) { create(:cellline_material) } |
8 | 9 | let(:collection) { create(:collection, user: user, is_shared: true, permission_level: 1, sample_detail_level: 10) }
|
9 | 10 | let(:query) { 'query' }
|
10 |
| - let(:json_repsonse) { JSON.parse(response.body) } |
11 |
| - let(:json_response) { response.body } |
| 11 | + let(:json_response) { JSON.parse(response.body) } |
12 | 12 | let(:params) do
|
13 | 13 | {
|
14 | 14 | collection_id: collection.id,
|
|
19 | 19 |
|
20 | 20 | describe 'GET /api/v1/cell_lines/suggestions/cell_lines' do
|
21 | 21 | include_context 'api request authorization context'
|
22 |
| - let!(:cell_line) { create(:cellline_sample, collections: [collection]) } |
23 |
| - let!(:cell_line2) { create(:cellline_sample, name: 'search-example', collections: [collection]) } |
24 |
| - let!(:cell_line_without_col) { create(:cellline_sample, name: 'search-example') } |
| 22 | + let!(:cell_line) { create(:cellline_sample, collections: [collection], cellline_material: material) } |
| 23 | + let!(:cell_line2) do |
| 24 | + create(:cellline_sample, name: 'search-example', collections: [collection], cellline_material: material) |
| 25 | + end |
| 26 | + let!(:cell_line_without_col) { create(:cellline_sample, name: 'search-example', cellline_material: material) } |
25 | 27 | let!(:sample) { create(:sample, name: 'search-example', collections: [collection]) }
|
26 | 28 |
|
27 | 29 | before do
|
|
36 | 38 | end
|
37 | 39 |
|
38 | 40 | it 'suggestions should be returned' do
|
39 |
| - expect(json_repsonse['suggestions'].length).to be 1 |
40 |
| - expect(json_repsonse['suggestions'].first['name']).to eq 'name-001' |
41 |
| - expect(json_repsonse['suggestions'].first['search_by_method']).to eq 'cell_line_material_name' |
| 41 | + expect(json_response['suggestions'].length).to be 1 |
| 42 | + expect(json_response['suggestions'].first['name']).to eq 'name-001' |
| 43 | + expect(json_response['suggestions'].first['search_by_method']).to eq 'cell_line_material_name' |
42 | 44 | end
|
43 | 45 | end
|
44 | 46 |
|
|
50 | 52 | end
|
51 | 53 |
|
52 | 54 | it 'suggestions should be returned' do
|
53 |
| - expect(json_repsonse['suggestions'].length).to be 1 |
54 |
| - expect(json_repsonse['suggestions'].first['name']).to eq 'search-example' |
55 |
| - expect(json_repsonse['suggestions'].first['search_by_method']).to eq 'cell_line_sample_name' |
| 55 | + expect(json_response['suggestions'].length).to be 1 |
| 56 | + expect(json_response['suggestions'].first['name']).to eq 'search-example' |
| 57 | + expect(json_response['suggestions'].first['search_by_method']).to eq 'cell_line_sample_name' |
56 | 58 | end
|
57 | 59 | end
|
58 | 60 | end
|
59 | 61 |
|
60 | 62 | describe 'GET /api/v1/cell_lines/suggestions/all' do
|
61 | 63 | include_context 'api request authorization context'
|
62 |
| - let!(:cell_line) { create(:cellline_sample, collections: [collection]) } |
63 |
| - let!(:cell_line2) { create(:cellline_sample, name: 'search-example', collections: [collection]) } |
| 64 | + let!(:cell_line) { create(:cellline_sample, collections: [collection], cellline_material: material) } |
| 65 | + let!(:cell_line2) do |
| 66 | + create(:cellline_sample, name: 'search-example', collections: [collection], cellline_material: material) |
| 67 | + end |
64 | 68 | let!(:sample) { create(:sample, name: 'search-example', collections: [collection]) }
|
65 | 69 |
|
66 | 70 | before do
|
|
75 | 79 | end
|
76 | 80 |
|
77 | 81 | it 'suggestions should be returned' do
|
78 |
| - expect(json_repsonse['suggestions'].length).to be 1 |
79 |
| - expect(json_repsonse['suggestions'].first['name']).to eq 'name-001' |
80 |
| - expect(json_repsonse['suggestions'].first['search_by_method']).to eq 'cell_line_material_name' |
| 82 | + expect(json_response['suggestions'].length).to be 1 |
| 83 | + expect(json_response['suggestions'].first['name']).to eq 'name-001' |
| 84 | + expect(json_response['suggestions'].first['search_by_method']).to eq 'cell_line_material_name' |
81 | 85 | end
|
82 | 86 | end
|
83 | 87 |
|
|
89 | 93 | end
|
90 | 94 |
|
91 | 95 | it 'two suggestions were found' do
|
92 |
| - expect(json_repsonse['suggestions'].length).to be 2 |
| 96 | + expect(json_response['suggestions'].length).to be 2 |
93 | 97 | end
|
94 | 98 |
|
95 | 99 | it 'first suggestion from sample' do
|
96 |
| - expect(json_repsonse['suggestions'].first['name']).to eq 'search-example' |
97 |
| - expect(json_repsonse['suggestions'].first['search_by_method']).to eq 'sample_name' |
| 100 | + expect(json_response['suggestions'].first['name']).to eq 'search-example' |
| 101 | + expect(json_response['suggestions'].first['search_by_method']).to eq 'sample_name' |
98 | 102 | end
|
99 | 103 |
|
100 | 104 | it 'second suggestion from cell line' do
|
101 |
| - expect(json_repsonse['suggestions'].second['name']).to eq 'search-example' |
102 |
| - expect(json_repsonse['suggestions'].second['search_by_method']).to eq 'cell_line_sample_name' |
| 105 | + expect(json_response['suggestions'].second['name']).to eq 'search-example' |
| 106 | + expect(json_response['suggestions'].second['search_by_method']).to eq 'cell_line_sample_name' |
103 | 107 | end
|
104 | 108 | end
|
105 | 109 | end
|
|
114 | 118 | is_sync: false,
|
115 | 119 | }
|
116 | 120 | expect(response).to have_http_status(:success)
|
117 |
| - json_response = JSON.parse(response.body) |
118 | 121 | expect(json_response.keys).to contain_exactly('suggestions')
|
119 | 122 | suggestions = json_response['suggestions']
|
120 | 123 | expect(suggestions).to be_an(Array)
|
|
0 commit comments