|
42 | 42 | expect(response).to have_http_status(:forbidden) |
43 | 43 | end |
44 | 44 | end |
| 45 | + |
| 46 | + describe 'POST /api/customization_templates' do |
| 47 | + it 'forbids creating a customization template without an appropriate role' do |
| 48 | + api_basic_authorize |
| 49 | + post(api_customization_templates_url, :params => {:action => 'create'}) |
| 50 | + expect(response).to have_http_status(:forbidden) |
| 51 | + end |
| 52 | + |
| 53 | + it 'forbids updating a customization template without an appropriate role' do |
| 54 | + api_basic_authorize |
| 55 | + post(api_customization_templates_url, :params => {:action => 'edit'}) |
| 56 | + expect(response).to have_http_status(:forbidden) |
| 57 | + end |
| 58 | + |
| 59 | + it 'forbids deleting a customization template without an appropriate role' do |
| 60 | + api_basic_authorize |
| 61 | + post(api_customization_templates_url, :params => {:action => 'delete'}) |
| 62 | + expect(response).to have_http_status(:forbidden) |
| 63 | + end |
| 64 | + |
| 65 | + it 'creates a customization template with an appropriate role' do |
| 66 | + pxe_image_type = FactoryBot.create(:pxe_image_type) |
| 67 | + params = { |
| 68 | + "name" => 'name', |
| 69 | + "description" => 'description', |
| 70 | + "script" => 'test', |
| 71 | + "type" => 'CustomizationTemplateKickstart', |
| 72 | + "pxe_image_type_id" => pxe_image_type.id.to_s |
| 73 | + } |
| 74 | + api_basic_authorize collection_action_identifier(:customization_templates, :create) |
| 75 | + |
| 76 | + post(api_customization_templates_url, :params => params) |
| 77 | + |
| 78 | + expect(response).to have_http_status(:ok) |
| 79 | + expect(response.parsed_body["results"].first).to include(params) |
| 80 | + end |
| 81 | + |
| 82 | + it 'updates a customization template with an appropriate role' do |
| 83 | + api_basic_authorize collection_action_identifier(:customization_templates, :edit) |
| 84 | + |
| 85 | + post(api_customization_templates_url, :params => gen_request(:edit, 'id' => template.id, 'description' => 'description updated')) |
| 86 | + |
| 87 | + expect(response).to have_http_status(:ok) |
| 88 | + expect(response.parsed_body["results"].first).to include('href' => api_customization_template_url(nil, template)) |
| 89 | + expect(template.reload.description).to eq('description updated') |
| 90 | + end |
| 91 | + |
| 92 | + it 'deletes a customization template with an appropriate role' do |
| 93 | + api_basic_authorize collection_action_identifier(:customization_templates, :delete) |
| 94 | + |
| 95 | + post(api_customization_templates_url, :params => gen_request(:delete, 'id' => template.id, 'href' => api_customization_template_url(nil, template))) |
| 96 | + |
| 97 | + expect(response).to have_http_status(:ok) |
| 98 | + expect(CustomizationTemplate.exists?(template.id)).to be false |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + describe 'POST /api/customization_templates/:id' do |
| 103 | + it 'forbids updating a customization template without an appropriate role' do |
| 104 | + api_basic_authorize |
| 105 | + post(api_customization_template_url(nil, template), :params => {:action => 'edit', :description => 'description updated'}) |
| 106 | + expect(response).to have_http_status(:forbidden) |
| 107 | + end |
| 108 | + |
| 109 | + it 'forbids deleting a customization template without an appropriate role' do |
| 110 | + api_basic_authorize |
| 111 | + post(api_customization_template_url(nil, template), :params => {:action => 'delete'}) |
| 112 | + expect(response).to have_http_status(:forbidden) |
| 113 | + end |
| 114 | + |
| 115 | + it 'updates a customization template with an appropriate role' do |
| 116 | + api_basic_authorize collection_action_identifier(:customization_templates, :edit) |
| 117 | + |
| 118 | + post(api_customization_template_url(nil, template), :params => {:action => 'edit', :description => 'description updated'}) |
| 119 | + |
| 120 | + expect(template.reload.description).to eq('description updated') |
| 121 | + expect(response).to have_http_status(:ok) |
| 122 | + expect(response.parsed_body).to include('href' => api_customization_template_url(nil, template)) |
| 123 | + end |
| 124 | + |
| 125 | + it 'deletes a customization template with an appropriate role' do |
| 126 | + api_basic_authorize collection_action_identifier(:customization_templates, :delete) |
| 127 | + |
| 128 | + expect do |
| 129 | + post(api_customization_template_url(nil, template), :params => {:action => 'delete'}) |
| 130 | + end.to change(CustomizationTemplate, :count).by(-1) |
| 131 | + |
| 132 | + expect(response).to have_http_status(:ok) |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + describe 'PUT /api/customization_templates/:id' do |
| 137 | + it 'updates a customization template with an appropriate role' do |
| 138 | + api_basic_authorize(action_identifier(:customization_templates, :edit)) |
| 139 | + put(api_customization_template_url(nil, template), :params => {:description => 'description updated'}) |
| 140 | + expect(response).to have_http_status(:ok) |
| 141 | + expect(template.reload.description).to eq('description updated') |
| 142 | + end |
| 143 | + |
| 144 | + it 'forbids updating a customization template without an appropriate role' do |
| 145 | + api_basic_authorize |
| 146 | + put(api_customization_template_url(nil, template), :params => {:description => 'description updated'}) |
| 147 | + expect(response).to have_http_status(:forbidden) |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + describe 'PATCH /api/customization_templates/:id' do |
| 152 | + it 'updates a customization template with an appropriate role' do |
| 153 | + api_basic_authorize(action_identifier(:customization_templates, :edit)) |
| 154 | + patch(api_customization_template_url(nil, template), :params => {:description => 'description updated'}) |
| 155 | + expect(response).to have_http_status(:ok) |
| 156 | + expect(template.reload.description).to eq('description updated') |
| 157 | + end |
| 158 | + |
| 159 | + it 'forbids updating a customization template without an appropriate role' do |
| 160 | + api_basic_authorize |
| 161 | + patch(api_customization_template_url(nil, template), :params => {:description => 'description updated'}) |
| 162 | + expect(response).to have_http_status(:forbidden) |
| 163 | + end |
| 164 | + end |
| 165 | + |
| 166 | + describe 'DELETE /api/customization_templates/:id' do |
| 167 | + it "deletes a customization template with an appropriate role" do |
| 168 | + api_basic_authorize(action_identifier(:customization_templates, :delete)) |
| 169 | + delete(api_customization_template_url(nil, template)) |
| 170 | + expect(response).to have_http_status(:no_content) |
| 171 | + end |
| 172 | + |
| 173 | + it 'forbids deleting a customization template without an appropriate role' do |
| 174 | + api_basic_authorize |
| 175 | + delete(api_customization_template_url(nil, template)) |
| 176 | + expect(response).to have_http_status(:forbidden) |
| 177 | + end |
| 178 | + end |
45 | 179 | end |
0 commit comments