|
| 1 | +describe "Volume Mappings API" do |
| 2 | + context "POST /api/volume_mappings" do |
| 3 | + it "with an invalid ems_id it responds with 404 Not Found" do |
| 4 | + api_basic_authorize(collection_action_identifier(:volume_mappings, :create)) |
| 5 | + |
| 6 | + request = { |
| 7 | + "action" => "create", |
| 8 | + "resource" => { |
| 9 | + "ems_id" => nil, |
| 10 | + "cloud_volume_id" => "1", |
| 11 | + "host_initiator_id" => "1", |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + post(api_volume_mappings_url, :params => request) |
| 16 | + |
| 17 | + expect(response).to have_http_status(:bad_request) |
| 18 | + end |
| 19 | + |
| 20 | + it "creates new Volume Mapping" do |
| 21 | + api_basic_authorize(collection_action_identifier(:volume_mappings, :create)) |
| 22 | + provider = FactoryBot.create(:ems_autosde, :name => 'Autosde') |
| 23 | + cloud_volume = FactoryBot.create(:cloud_volume) |
| 24 | + host_initiator = FactoryBot.create(:host_initiator) |
| 25 | + |
| 26 | + request = { |
| 27 | + "action" => "create", |
| 28 | + "resource" => { |
| 29 | + "ems_id" => provider.id, |
| 30 | + "cloud_volume_id" => cloud_volume.id, |
| 31 | + "host_initiator_id" => host_initiator.id, |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + post(api_volume_mappings_url, :params => request) |
| 36 | + |
| 37 | + expect_multiple_action_result(1, :success => true, :message => "Creating Host Initiator test_host_initiator for Provider: #{provider.name}", :task => true) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context "GET /api/volume_mappings" do |
| 42 | + it "returns all volume mappings" do |
| 43 | + volume_mapping = FactoryBot.create(:volume_mapping) |
| 44 | + api_basic_authorize('volume_mapping_show_list') |
| 45 | + |
| 46 | + get(api_volume_mappings_url) |
| 47 | + |
| 48 | + expected = { |
| 49 | + "name" => "volume_mappings", |
| 50 | + "resources" => [{"href" => api_volume_mapping_url(nil, volume_mapping)}] |
| 51 | + } |
| 52 | + expect(response).to have_http_status(:ok) |
| 53 | + expect(response.parsed_body).to include(expected) |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context "GET /api/volume_mappings/:id" do |
| 58 | + it "returns one volume_mapping" do |
| 59 | + volume_mapping = FactoryBot.create(:volume_mapping) |
| 60 | + api_basic_authorize('volume_mapping_show') |
| 61 | + |
| 62 | + get(api_volume_mapping_url(nil, volume_mapping)) |
| 63 | + |
| 64 | + expected = { |
| 65 | + "href" => api_volume_mapping_url(nil, volume_mapping) |
| 66 | + } |
| 67 | + expect(response).to have_http_status(:ok) |
| 68 | + expect(response.parsed_body).to include(expected) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + describe "Volume Mapping refresh action" do |
| 73 | + context "with an invalid id" do |
| 74 | + it "it responds with 404 Not Found" do |
| 75 | + api_basic_authorize(action_identifier(:volume_mappings, :refresh, :resource_actions, :post)) |
| 76 | + |
| 77 | + post(api_volume_mapping_url(nil, 999_999), :params => gen_request(:refresh)) |
| 78 | + |
| 79 | + expect(response).to have_http_status(:not_found) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + context "without an appropriate role" do |
| 84 | + it "it responds with 403 Forbidden" do |
| 85 | + volume_mapping = FactoryBot.create(:volume_mapping) |
| 86 | + api_basic_authorize |
| 87 | + |
| 88 | + post(api_volume_mapping_url(nil, volume_mapping), :params => gen_request(:refresh)) |
| 89 | + |
| 90 | + expect(response).to have_http_status(:forbidden) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context "with an appropriate role" do |
| 95 | + it "rejects refresh for unspecified volume mapping" do |
| 96 | + api_basic_authorize(action_identifier(:volume_mappings, :refresh, :resource_actions, :post)) |
| 97 | + |
| 98 | + post(api_volume_mappings_url, :params => gen_request(:refresh, [{"href" => "/api/volume_mappings/"}, {"href" => "/api/volume_mappings/"}])) |
| 99 | + |
| 100 | + expect_bad_request(/Must specify an id/i) |
| 101 | + end |
| 102 | + |
| 103 | + it "refresh of a single Volume Mapping" do |
| 104 | + volume_mapping = FactoryBot.create(:volume_mapping) |
| 105 | + api_basic_authorize('volume_mapping_refresh') |
| 106 | + |
| 107 | + post(api_volume_mapping_url(nil, volume_mapping), :params => gen_request(:refresh)) |
| 108 | + |
| 109 | + expect_single_action_result(:success => true, :message => /#{volume_mapping.id}.* refreshing/i, :href => api_volume_mapping_url(nil, volume_mapping)) |
| 110 | + end |
| 111 | + |
| 112 | + it "refresh of multiple Host Initiators" do |
| 113 | + volume_mapping = FactoryBot.create(:volume_mapping) |
| 114 | + volume_mapping_two = FactoryBot.create(:volume_mapping) |
| 115 | + api_basic_authorize('volume_mapping_refresh') |
| 116 | + |
| 117 | + post(api_volume_mappings_url, :params => gen_request(:refresh, [{"href" => api_volume_mapping_url(nil, volume_mapping)}, {"href" => api_volume_mapping_url(nil, volume_mapping_two)}])) |
| 118 | + |
| 119 | + expected = { |
| 120 | + "results" => a_collection_containing_exactly( |
| 121 | + a_hash_including( |
| 122 | + "message" => a_string_matching(/#{volume_mapping.id}.* refreshing/i), |
| 123 | + "success" => true, |
| 124 | + "href" => api_volume_mapping_url(nil, volume_mapping) |
| 125 | + ), |
| 126 | + a_hash_including( |
| 127 | + "message" => a_string_matching(/#{volume_mapping_two.id}.* refreshing/i), |
| 128 | + "success" => true, |
| 129 | + "href" => api_volume_mapping_url(nil, volume_mapping_two) |
| 130 | + ) |
| 131 | + ) |
| 132 | + } |
| 133 | + expect(response.parsed_body).to include(expected) |
| 134 | + expect(response).to have_http_status(:ok) |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | +end |
0 commit comments