diff --git a/spec/requests/api/article_categories_spec.rb b/spec/requests/api/article_categories_spec.rb index 937f2690..c8b60984 100644 --- a/spec/requests/api/article_categories_spec.rb +++ b/spec/requests/api/article_categories_spec.rb @@ -47,7 +47,7 @@ describe 'Article Categories', type: :request do let(:id) { create(:article_category, name: 'dairy').id } run_test! end - it_handles_invalid_token_with_id(:article_category) + it_handles_invalid_token_with_id it_cannot_find_object end end diff --git a/spec/requests/api/financial_transaction_classes_spec.rb b/spec/requests/api/financial_transaction_classes_spec.rb index 9e0bd1a6..2e3b76c4 100644 --- a/spec/requests/api/financial_transaction_classes_spec.rb +++ b/spec/requests/api/financial_transaction_classes_spec.rb @@ -50,7 +50,7 @@ describe 'Financial Transaction Classes', type: :request do run_test! end - it_handles_invalid_token_with_id :financial_transaction + it_handles_invalid_token_with_id it_cannot_find_object 'financial transaction class not found' end end diff --git a/spec/requests/api/financial_transaction_types_spec.rb b/spec/requests/api/financial_transaction_types_spec.rb index 94caacf4..6ad8b07b 100644 --- a/spec/requests/api/financial_transaction_types_spec.rb +++ b/spec/requests/api/financial_transaction_types_spec.rb @@ -48,7 +48,7 @@ describe 'Financial Transaction types', type: :request do run_test! end - it_handles_invalid_token_with_id :financial_transaction_type + it_handles_invalid_token_with_id it_cannot_find_object 'financial transaction type not found' end end diff --git a/spec/requests/api/financial_transactions_spec.rb b/spec/requests/api/financial_transactions_spec.rb index aa9afaeb..e683ea0b 100644 --- a/spec/requests/api/financial_transactions_spec.rb +++ b/spec/requests/api/financial_transactions_spec.rb @@ -51,8 +51,8 @@ describe 'Financial Transaction', type: :request do let(:id) { FinancialTransaction.create(user: user).id } run_test! end - it_handles_invalid_token_with_id :financial_transaction - it_handles_invalid_scope_with_id :financial_transaction + it_handles_invalid_token_with_id + it_handles_invalid_scope_with_id it_cannot_find_object 'financial transaction not found' end end diff --git a/spec/requests/api/orders_spec.rb b/spec/requests/api/orders_spec.rb index 05eea3e2..500b1aa0 100644 --- a/spec/requests/api/orders_spec.rb +++ b/spec/requests/api/orders_spec.rb @@ -42,17 +42,20 @@ describe 'Orders', type: :request do id_url_param let(:order) { create(:order) } - let(:id) { order.id } response '200', 'success' do schema type: :object, properties: { '$ref': '#/components/schemas/Order' } + let(:id) { order.id } run_test! do |response| expect(JSON.parse(response.body)['order']['id']).to eq order.id end end + + it_handles_invalid_token_and_scope + it_cannot_find_object 'order not found' end end end diff --git a/spec/requests/api/user/financial_transactions_spec.rb b/spec/requests/api/user/financial_transactions_spec.rb index 1eca1895..d5ff820c 100644 --- a/spec/requests/api/user/financial_transactions_spec.rb +++ b/spec/requests/api/user/financial_transactions_spec.rb @@ -36,8 +36,8 @@ describe 'User', type: :request do run_test! end - it_handles_invalid_token_with_id :financial_transaction - it_handles_invalid_scope_with_id(:financial_transaction, 'user has no ordergroup, is below minimum balance, self service is disabled, or missing scope') + it_handles_invalid_token_with_id + it_handles_invalid_scope_with_id 'user has no ordergroup, is below minimum balance, self service is disabled, or missing scope' response '404', 'financial transaction type not found' do schema '$ref' => '#/components/schemas/Error404' @@ -106,8 +106,8 @@ describe 'User', type: :request do end end - it_handles_invalid_token_with_id :financial_transaction - it_handles_invalid_scope_with_id :financial_transaction, 'user has no ordergroup or missing scope' + it_handles_invalid_token_with_id + it_handles_invalid_scope_with_id 'user has no ordergroup or missing scope' it_cannot_find_object 'financial transaction not found' end end diff --git a/spec/requests/api/user/group_order_articles_spec.rb b/spec/requests/api/user/group_order_articles_spec.rb index e451fb10..7a6e5ecf 100644 --- a/spec/requests/api/user/group_order_articles_spec.rb +++ b/spec/requests/api/user/group_order_articles_spec.rb @@ -80,12 +80,8 @@ describe 'User', type: :request do run_test! end - # 401 - it_handles_invalid_token_with_id(:group_order_article) - - # 403 - # description: user has no ordergroup, is below minimum balance, self service is disabled, or missing scope - it_handles_invalid_scope_with_id(:group_order_article, 'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope') + it_handles_invalid_token_with_id + it_handles_invalid_scope_with_id 'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope' # 404 response '404', 'order article not found in open orders' do @@ -125,32 +121,11 @@ describe 'User', type: :request do end end - # 401 - response 401, 'not logged-in' do - let(:Authorization) { 'abc' } - schema '$ref' => '#/components/schemas/Error401' - run_test! - end - # 403 - response 403, 'user has no ordergroup or missing scope' do - let(:api_scopes) { ['none'] } - schema '$ref' => '#/components/schemas/Error403' - run_test! - end - # 404 - response '404', 'group order article not found' do - schema type: :object, properties: { - group_order_article: { - type: :object, - items: { - '$ref': '#/components/schemas/GroupOrderArticle' - } - } - } - let(:id) { 'invalid' } - run_test! - end + it_handles_invalid_scope_with_id + it_handles_invalid_token_with_id + it_cannot_find_object 'group order article not found' end + patch 'update a group order article (but delete if quantity and tolerance are zero)' do tags 'User', 'GroupOrderArticle' consumes 'application/json' @@ -235,12 +210,7 @@ describe 'User', type: :request do run_test! end - # 401 - response 401, 'not logged-in' do - let(:Authorization) { 'abc' } - schema '$ref' => '#/components/schemas/Error401' - run_test! - end + it_handles_invalid_token_with_id # 403 response 403, 'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope' do @@ -249,8 +219,7 @@ describe 'User', type: :request do run_test! end - # 404 - it_cannot_find_object('order article not found in open orders') + it_cannot_find_object 'order article not found in open orders' end end end diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index 233f6584..0727356b 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -18,10 +18,10 @@ module ApiHelper end end - def self.it_handles_invalid_token_with_id(class_sym) + def self.it_handles_invalid_token_with_id context 'with invalid access token' do let(:Authorization) { 'abc' } - let(:id) { create(class_sym).id } + let(:id) { 42 } # id doesn't matter here response 401, 'not logged-in' do schema '$ref' => '#/components/schemas/Error401' @@ -41,10 +41,10 @@ module ApiHelper end end - def self.it_handles_invalid_scope_with_id(class_sym, description = 'missing scope') + def self.it_handles_invalid_scope_with_id(description = 'missing scope') context 'with invalid scope' do let(:api_scopes) { ['none'] } - let(:id) { create(class_sym).id } + let(:id) { 42 } # id doesn't matter here response 403, description do schema '$ref' => '#/components/schemas/Error403' @@ -56,7 +56,6 @@ module ApiHelper def self.it_cannot_find_object(description = 'not found') let(:id) { 'invalid' } - response 404, description do schema '$ref' => '#/components/schemas/Error404' run_test!