summaryrefslogtreecommitdiff
path: root/spec/requests/products_controller/update_spec.rb
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-30 17:29:40 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-30 17:29:40 -0600
commit2ae0cd8a8dc6d630ee1a7a84ddf6111609dbdeb7 (patch)
treebbcaadbea3da32ee974d28cfb37c1af4be018215 /spec/requests/products_controller/update_spec.rb
parentefc5eb10894fc95487c55628b94024e97cd60139 (diff)
Mejora la estructura de los specs
Diffstat (limited to 'spec/requests/products_controller/update_spec.rb')
-rw-r--r--spec/requests/products_controller/update_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/requests/products_controller/update_spec.rb b/spec/requests/products_controller/update_spec.rb
new file mode 100644
index 0000000..f916d6a
--- /dev/null
+++ b/spec/requests/products_controller/update_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'PUT /api/products/product_id', type: :request do
+ let(:user) { create(:user_account, role: 'master') }
+ let(:product) { create(:product, public_id: SecureRandom.hex(12)) }
+ let(:new_product) { build(:product) }
+ let(:picture) { fixture_file_upload('800px-Stray_cat_on_wall.jpg', 'image/png') }
+ let(:token) { jwt(user) }
+ let(:categories) do
+ c = ''
+ new_product.categories.each { |category| c += "#{category}," }
+ c
+ end
+
+ it_behaves_like 'a PUT request' do
+ let(:headers) { { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token['token']}" } }
+ let(:route) { "/api/products/#{product.public_id}" }
+ let(:wrong_route) { "/api/products/#{SecureRandom.hex(8)}" }
+ let(:expected_error_messages) do
+ ["Name can't be blank", 'Unitary price must be greater than 0', 'Bulk price must be greater than 0',
+ 'Available quantity must be greater than 0', 'Company must exist']
+ end
+ let(:desired_error_status) { 422 }
+ let(:expected_text) do
+ new_product.categories.concat([new_product.name, new_product.unitary_price.to_i.to_s,
+ new_product.bulk_price.to_i.to_s, new_product.available_quantity.to_s,
+ new_product.company.short_name, 'picture', 'http'])
+ end
+ let(:params) do
+ { name: new_product.name, unitary_price: new_product.unitary_price, bulk_price: new_product.bulk_price, picture:,
+ available_quantity: new_product.available_quantity, categories:, company_id: new_product.company_id }
+ end
+ let(:wrong_params) do
+ JSON.generate({ name: '', unitary_price: -10, bulk_price: -10, available_quantity: -10,
+ categories: '', company_id: nil })
+ end
+ end
+end