28_introduce_rswag #35

Merged
philipp merged 46 commits from 28_introduce_rswag into develop 2023-01-05 13:45:47 +01:00
8 changed files with 25 additions and 54 deletions
Showing only changes of commit edd6e2451d - Show all commits

View file

@ -47,7 +47,7 @@ describe 'Article Categories', type: :request do
let(:id) { create(:article_category, name: 'dairy').id } let(:id) { create(:article_category, name: 'dairy').id }
run_test! run_test!
end end
it_handles_invalid_token_with_id(:article_category) it_handles_invalid_token_with_id
it_cannot_find_object it_cannot_find_object
end end
end end

View file

@ -50,7 +50,7 @@ describe 'Financial Transaction Classes', type: :request do
run_test! run_test!
end end
it_handles_invalid_token_with_id :financial_transaction it_handles_invalid_token_with_id
it_cannot_find_object 'financial transaction class not found' it_cannot_find_object 'financial transaction class not found'
end end
end end

View file

@ -48,7 +48,7 @@ describe 'Financial Transaction types', type: :request do
run_test! run_test!
end 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' it_cannot_find_object 'financial transaction type not found'
end end
end end

View file

@ -51,8 +51,8 @@ describe 'Financial Transaction', type: :request do
let(:id) { FinancialTransaction.create(user: user).id } let(:id) { FinancialTransaction.create(user: user).id }
run_test! run_test!
end end
it_handles_invalid_token_with_id :financial_transaction it_handles_invalid_token_with_id
it_handles_invalid_scope_with_id :financial_transaction it_handles_invalid_scope_with_id
it_cannot_find_object 'financial transaction not found' it_cannot_find_object 'financial transaction not found'
end end
end end

View file

@ -42,17 +42,20 @@ describe 'Orders', type: :request do
id_url_param id_url_param
let(:order) { create(:order) } let(:order) { create(:order) }
let(:id) { order.id }
response '200', 'success' do response '200', 'success' do
schema type: :object, properties: { schema type: :object, properties: {
'$ref': '#/components/schemas/Order' '$ref': '#/components/schemas/Order'
} }
let(:id) { order.id }
run_test! do |response| run_test! do |response|
expect(JSON.parse(response.body)['order']['id']).to eq order.id expect(JSON.parse(response.body)['order']['id']).to eq order.id
end end
end end
it_handles_invalid_token_and_scope
it_cannot_find_object 'order not found'
end end
end end
end end

View file

@ -36,8 +36,8 @@ describe 'User', type: :request do
run_test! run_test!
end end
it_handles_invalid_token_with_id :financial_transaction it_handles_invalid_token_with_id
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_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 response '404', 'financial transaction type not found' do
schema '$ref' => '#/components/schemas/Error404' schema '$ref' => '#/components/schemas/Error404'
@ -106,8 +106,8 @@ describe 'User', type: :request do
end end
end end
it_handles_invalid_token_with_id :financial_transaction it_handles_invalid_token_with_id
it_handles_invalid_scope_with_id :financial_transaction, 'user has no ordergroup or missing scope' it_handles_invalid_scope_with_id 'user has no ordergroup or missing scope'
it_cannot_find_object 'financial transaction not found' it_cannot_find_object 'financial transaction not found'
end end
end end

View file

@ -80,12 +80,8 @@ describe 'User', type: :request do
run_test! run_test!
end end
# 401 it_handles_invalid_token_with_id
it_handles_invalid_token_with_id(:group_order_article) 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'
# 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')
# 404 # 404
response '404', 'order article not found in open orders' do response '404', 'order article not found in open orders' do
@ -125,32 +121,11 @@ describe 'User', type: :request do
end end
end end
# 401 it_handles_invalid_scope_with_id
response 401, 'not logged-in' do it_handles_invalid_token_with_id
let(:Authorization) { 'abc' } it_cannot_find_object 'group order article not found'
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
end end
patch 'update a group order article (but delete if quantity and tolerance are zero)' do patch 'update a group order article (but delete if quantity and tolerance are zero)' do
tags 'User', 'GroupOrderArticle' tags 'User', 'GroupOrderArticle'
consumes 'application/json' consumes 'application/json'
@ -235,12 +210,7 @@ describe 'User', type: :request do
run_test! run_test!
end end
# 401 it_handles_invalid_token_with_id
response 401, 'not logged-in' do
let(:Authorization) { 'abc' }
schema '$ref' => '#/components/schemas/Error401'
run_test!
end
# 403 # 403
response 403, 'user has no ordergroup, order not open, is below minimum balance, has not enough apple points, or missing scope' do 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! run_test!
end 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 end
end end

View file

@ -18,10 +18,10 @@ module ApiHelper
end end
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 context 'with invalid access token' do
let(:Authorization) { 'abc' } let(:Authorization) { 'abc' }
let(:id) { create(class_sym).id } let(:id) { 42 } # id doesn't matter here
response 401, 'not logged-in' do response 401, 'not logged-in' do
schema '$ref' => '#/components/schemas/Error401' schema '$ref' => '#/components/schemas/Error401'
@ -41,10 +41,10 @@ module ApiHelper
end end
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 context 'with invalid scope' do
let(:api_scopes) { ['none'] } let(:api_scopes) { ['none'] }
let(:id) { create(class_sym).id } let(:id) { 42 } # id doesn't matter here
response 403, description do response 403, description do
schema '$ref' => '#/components/schemas/Error403' schema '$ref' => '#/components/schemas/Error403'
@ -56,7 +56,6 @@ module ApiHelper
def self.it_cannot_find_object(description = 'not found') def self.it_cannot_find_object(description = 'not found')
let(:id) { 'invalid' } let(:id) { 'invalid' }
response 404, description do response 404, description do
schema '$ref' => '#/components/schemas/Error404' schema '$ref' => '#/components/schemas/Error404'
run_test! run_test!