summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/addresses_controller/destroy_spec.rb2
-rw-r--r--spec/requests/cards_controller/create_spec.rb33
-rw-r--r--spec/requests/cards_controller/destroy_spec.rb15
-rw-r--r--spec/requests/cards_controller/index_spec.rb18
-rw-r--r--spec/requests/cards_controller/update_spec.rb33
5 files changed, 100 insertions, 1 deletions
diff --git a/spec/requests/addresses_controller/destroy_spec.rb b/spec/requests/addresses_controller/destroy_spec.rb
index df43329..bf33067 100644
--- a/spec/requests/addresses_controller/destroy_spec.rb
+++ b/spec/requests/addresses_controller/destroy_spec.rb
@@ -2,7 +2,7 @@
require 'rails_helper'
-RSpec.describe 'DELETE /api/products/product_id', type: :request do
+RSpec.describe 'DELETE /api/account/addresses/address_id', type: :request do
let(:user) { create(:user_account, role: 'regular') }
let(:token) { jwt(user) }
let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
diff --git a/spec/requests/cards_controller/create_spec.rb b/spec/requests/cards_controller/create_spec.rb
new file mode 100644
index 0000000..465288b
--- /dev/null
+++ b/spec/requests/cards_controller/create_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'POST /account/cards', type: :request do
+ let(:card) { build(:card, user_account: nil) }
+ let(:user) { create(:user_account, role: 'regular') }
+ let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
+ let(:token) { jwt(user) }
+ let(:params) do
+ { number: card.number, expiration_year: card.expiration_year, expiration_month: card.expiration_month,
+ expiration_day: card.expiration_day, security_code: card.security_code }
+ end
+
+ it_behaves_like 'a POST request' do
+ let(:route) { '/api/account/cards' }
+ let(:expected_error_messages) do
+ ['Number is the wrong length (should be 16 characters)',
+ 'Expiration year must be greater than 1970',
+ 'Expiration month is not included in the list',
+ 'Expiration day is not included in the list',
+ "Security code can't be blank"]
+ end
+ let(:desired_error_status) { 422 }
+ let(:expected_text) do
+ [card.number, card.expiration_year, card.expiration_month, card.expiration_day, card.security_code]
+ end
+ let(:wrong_params) do
+ { number: SecureRandom.hex(24), expiration_year: -20, expiration_month: 13,
+ expiration_day: 33, security_code: '' }
+ end
+ end
+end
diff --git a/spec/requests/cards_controller/destroy_spec.rb b/spec/requests/cards_controller/destroy_spec.rb
new file mode 100644
index 0000000..5ade11f
--- /dev/null
+++ b/spec/requests/cards_controller/destroy_spec.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'DELETE /api/account/cards/card_id', type: :request do
+ let(:user) { create(:user_account, role: 'regular') }
+ let(:token) { jwt(user) }
+ let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
+ let(:card) { create(:card, user_account: user) }
+
+ it_behaves_like 'a DELETE request' do
+ let(:resource) { "/api/account/cards/#{card.id}" }
+ let(:nonexistent_resource) { "/api/account/cards/#{SecureRandom.hex(8)}" }
+ end
+end
diff --git a/spec/requests/cards_controller/index_spec.rb b/spec/requests/cards_controller/index_spec.rb
index e69de29..d88b28c 100644
--- a/spec/requests/cards_controller/index_spec.rb
+++ b/spec/requests/cards_controller/index_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'GET /api/account/cards', type: :request do
+ let(:user) { create(:user_account, role: 'regular') }
+ let(:token) { jwt(user) }
+
+ before(:each) do
+ create_list(:card, 3, user_account: user)
+ end
+
+ it_behaves_like 'a GET index request' do
+ let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
+ let(:route) { '/api/account/cards' }
+ let(:pagination_size) { 3 }
+ end
+end
diff --git a/spec/requests/cards_controller/update_spec.rb b/spec/requests/cards_controller/update_spec.rb
new file mode 100644
index 0000000..fdff170
--- /dev/null
+++ b/spec/requests/cards_controller/update_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'PUT /api/account/addresses', type: :request do
+ let(:user) { create(:user_account, role: 'regular') }
+ let(:card) { create(:card, user_account: user) }
+ let(:new_card) { build(:card) }
+ let(:token) { jwt(user) }
+ let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
+ let(:params) do
+ { number: new_card.number, expiration_year: new_card.expiration_year, expiration_month: new_card.expiration_month,
+ expiration_day: new_card.expiration_day, security_code: new_card.security_code }
+ end
+
+ it_behaves_like 'a PUT request' do
+ let(:route) { "/api/account/cards/#{card.id}" }
+ let(:wrong_route) { "/api/account/cards/#{SecureRandom.hex(8)}" }
+ let(:expected_error_messages) do
+ ['Number is the wrong length (should be 16 characters)',
+ 'Expiration year must be greater than 1970',
+ 'Expiration month is not included in the list',
+ 'Expiration day is not included in the list',
+ "Security code can't be blank"]
+ end
+ let(:expected_text) do
+ [new_card.number, new_card.expiration_year, new_card.expiration_month, new_card.expiration_day, new_card.security_code]
+ end
+ let(:wrong_params) do
+ { number: SecureRandom.hex(24), expiration_year: -20, expiration_month: 13, expiration_day: 33, security_code: ''}
+ end
+ end
+end \ No newline at end of file