|
11 | 11 | let(:assets) { [ create(:plate), create(:tube), create(:plate), create(:well)]} |
12 | 12 | let(:remote_assets) {[build_remote_plate, build_remote_tube, build_remote_plate, build_remote_well('B1')]} |
13 | 13 |
|
14 | | - before do |
15 | | - assets.zip(remote_assets) do |a, remote| |
16 | | - allow(remote).to receive(:uuid).and_return(a.uuid) |
| 14 | + context 'when refreshing a list of assets' do |
| 15 | + before do |
| 16 | + assets.zip(remote_assets) do |a, remote| |
| 17 | + allow(remote).to receive(:uuid).and_return(a.uuid) |
| 18 | + end |
| 19 | + allow(SequencescapeClient).to receive(:find_by_uuid).with(assets.map(&:uuid)).and_return(remote_assets) |
| 20 | + end |
| 21 | + |
| 22 | + it 'refreshes the contents of the assets' do |
| 23 | + updates = instance.refresh_assets(assets) |
| 24 | + expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
| 25 | + expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(*uuids) |
17 | 26 | end |
18 | | - allow(SequencescapeClient).to receive(:find_by_uuid).with(assets.map(&:uuid)).and_return(remote_assets) |
19 | | - end |
20 | 27 |
|
21 | | - it 'refreshes the contents of the assets' do |
22 | | - updates = instance.refresh_assets(assets) |
23 | | - expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
24 | | - expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(*uuids) |
| 28 | + context 'when receiving an empty list' do |
| 29 | + it 'does nothing' do |
| 30 | + updates = instance.refresh_assets([]) |
| 31 | + expect(updates.to_h).to eq({}) |
| 32 | + end |
| 33 | + end |
25 | 34 | end |
26 | 35 |
|
27 | | - context 'when receiving an empty list' do |
28 | | - it 'does nothing' do |
29 | | - updates = instance.refresh_assets([]) |
30 | | - expect(updates.to_h).to eq({}) |
| 36 | + context 'when refreshing a single asset' do |
| 37 | + before do |
| 38 | + assets.zip(remote_assets) do |a, remote| |
| 39 | + allow(remote).to receive(:uuid).and_return(a.uuid) |
| 40 | + end |
| 41 | + allow(SequencescapeClient).to receive(:find_by_uuid).with([assets.map(&:uuid).first]).and_return(remote_assets.first) |
31 | 42 | end |
| 43 | + |
| 44 | + it 'refreshes the contents of the asset' do |
| 45 | + updates = instance.refresh_assets([assets.first]) |
| 46 | + expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
| 47 | + |
| 48 | + # It includes the asset |
| 49 | + expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).to include(uuids.first) |
| 50 | + |
| 51 | + # It does not refreshes other remote assets not passed as argument |
| 52 | + expect(updates.to_h[:add_facts].map{|t| t[0]}.uniq).not_to include(uuids.last) |
| 53 | + end |
| 54 | + |
32 | 55 | end |
33 | 56 | end |
34 | 57 |
|
|
51 | 74 | remote_assets.map{|a| a.labware_barcode['human_barcode']} |
52 | 75 | } |
53 | 76 |
|
54 | | - before do |
55 | | - allow(SequencescapeClient).to receive(:get_remote_asset).with(barcodes).and_return(remote_assets) |
56 | | - end |
| 77 | + context 'when scanning a list of barcodes' do |
| 78 | + before do |
| 79 | + allow(SequencescapeClient).to receive(:get_remote_asset).with(barcodes).and_return(remote_assets) |
| 80 | + end |
57 | 81 |
|
58 | | - it 'imports the assets' do |
59 | | - updates = instance.import_barcodes(barcodes) |
60 | | - expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
61 | | - expect(updates.to_h[:create_assets]).to include(*uuids) |
62 | | - end |
| 82 | + it 'imports the assets' do |
| 83 | + updates = instance.import_barcodes(barcodes) |
| 84 | + expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
| 85 | + expect(updates.to_h[:create_assets]).to include(*uuids) |
| 86 | + end |
63 | 87 |
|
64 | | - context 'when receiving an empty list' do |
65 | | - it 'does nothing' do |
66 | | - updates = instance.import_barcodes([]) |
67 | | - expect(updates.to_h).to eq({}) |
| 88 | + context 'when receiving an empty list' do |
| 89 | + it 'does nothing' do |
| 90 | + updates = instance.import_barcodes([]) |
| 91 | + expect(updates.to_h).to eq({}) |
| 92 | + end |
68 | 93 | end |
69 | 94 | end |
70 | 95 |
|
| 96 | + context 'when scanning a single barcode' do |
| 97 | + before do |
| 98 | + allow(SequencescapeClient).to receive(:get_remote_asset).with([barcodes.first]).and_return(remote_assets.first) |
| 99 | + end |
| 100 | + |
| 101 | + it 'imports the asset' do |
| 102 | + updates = instance.import_barcodes([barcodes.first]) |
| 103 | + expect(updates.to_h[:add_facts].detect{|t|t[1]=='sample_uuid'}).not_to be_nil |
| 104 | + expect(updates.to_h[:create_assets]).to eq([uuids.first]) |
| 105 | + end |
| 106 | + end |
71 | 107 | end |
72 | 108 | end |
0 commit comments