28_introduce_rswag #35

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

View file

@ -17,10 +17,7 @@ describe 'User', type: :request do
tags "Financial Transaction" tags "Financial Transaction"
consumes 'application/json' consumes 'application/json'
produces 'application/json' produces 'application/json'
parameter name: "per_page", in: :query, type: :integer, required: false
parameter name: "page", in: :query, type: :integer, required: false
let(:page) { 1 }
let(:per_page) { 20 }
parameter name: :financial_transaction, in: :body, schema: { parameter name: :financial_transaction, in: :body, schema: {
type: :object, type: :object,
properties: { properties: {
@ -29,62 +26,46 @@ describe 'User', type: :request do
note: { type: :string } note: { type: :string }
} }
} }
let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } } let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } }
response '200', 'success' do response '200', 'success' do
schema type: :object, properties: { schema type: :object, properties: {
financial_transaction_for_create: { financial_transaction: { '$ref': '#/components/schemas/FinancialTransaction' }
type: :object,
items: {
'$ref': '#/components/schemas/FinancialTransactionForCreate'
}
}
} }
run_test! run_test!
end end
# 401 it_handles_invalid_token_with_id :financial_transaction
it_handles_invalid_token_with_id(:financial_transaction)
# 403
# description: user has no ordergroup, is below minimum balance, self service is disabled, or missing scope
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(:financial_transaction, 'user has no ordergroup, is below minimum balance, self service is disabled, or missing scope')
# TODO: fix 404 and 422 response '404', 'financial transaction type not found' do
# 404 schema '$ref' => '#/components/schemas/Error404'
# Type not found let(:financial_transaction) { { amount: 3, financial_transaction_type_id: 'invalid', note: 'lirum larum' } }
# description: financial transaction type not found run_test!
# Should be 404, but is 200 with validation errors.. end
# Rswag::Specs::UnexpectedResponse:
# Expected response code '404' to match '200'
# Response body: {"error":"not_found","error_description":"Couldn't find FinancialTransactionType with 'id'=invalid"}
# let(:financial_transaction) { { amount: 3, financial_transaction_type_id: 'invalid', note: 'lirum larum' } }
# response '404', 'invalid parameter value' do
# schema '$ref' => '#/components/schemas/Error404'
# run_test!
# end
# 422 # TODO: fix controller to actually send a 422 for invalid params?
# Expected response code '200' to match '422'
# Response body: {"financial_transaction":{"id":316,"user_id":599,"user_name":"Lisbeth ","amount":-3.0,"note":"-2","created_at":"2022-12-12T13:05:32.000+01:00","financial_transaction_type_id":346,"financial_transaction_type_name":"aut est iste #9"}}
#
# response '422', 'invalid parameter value' do # response '422', 'invalid parameter value' do
# # schema '$ref' => '#/components/schemas/Error422'
# let(:financial_transaction) { { amount: -3, financial_transaction_type_id: create(:financial_transaction_type).id, note: -2 } } # let(:financial_transaction) { { amount: -3, financial_transaction_type_id: create(:financial_transaction_type).id, note: -2 } }
# schema '$ref' => '#/components/schemas/Error422'
# run_test! # run_test!
# end # end
end end
get "financial transactions of the member's ordergroup" do get "financial transactions of the member's ordergroup" do
tags 'User', 'Financial Transaction' tags 'User', 'Financial Transaction'
produces 'application/json' produces 'application/json'
parameter name: "per_page", in: :query, type: :integer, required: false
parameter name: "page", in: :query, type: :integer, required: false
response '200', 'success' do response '200', 'success' do
schema type: :object, properties: { schema type: :object, properties: {
meta: { meta: { '$ref': '#/components/schemas/Meta' },
type: :object,
items:
{
'$ref': '#/components/schemas/Meta'
}
},
financial_transaction: { financial_transaction: {
type: :array, type: :array,
items: { items: {
@ -98,7 +79,7 @@ describe 'User', type: :request do
expect(data['financial_transactions'].first['id']).to eq(ft.id) expect(data['financial_transactions'].first['id']).to eq(ft.id)
end end
end end
# responses 401 & 403
it_handles_invalid_token_and_scope it_handles_invalid_token_and_scope
end end
end end
@ -125,23 +106,9 @@ describe 'User', type: :request do
end end
end end
# 401 it_handles_invalid_token_with_id :financial_transaction
it_handles_invalid_token_with_id(:financial_transaction) it_handles_invalid_scope_with_id :financial_transaction, 'user has no ordergroup or missing scope'
# 403 it_cannot_find_object 'financial transaction not found'
it_handles_invalid_scope_with_id(:financial_transaction, 'user has no ordergroup or missing scope')
# 404
response '404', 'financial transaction not found' do
schema type: :object, properties: {
financial_transaction: {
type: :object,
items: {
'$ref': '#/components/schemas/FinancialTransaction'
}
}
}
let(:id) { 'invalid' }
run_test!
end
end end
end end
end end

View file

@ -174,6 +174,9 @@ RSpec.configure do |config|
required: %w[id name] required: %w[id name]
}, },
FinancialTransaction: { FinancialTransaction: {
allOf: [
{ '$ref': '#/components/schemas/FinancialTransactionForCreate' },
{
type: :object, type: :object,
properties: { properties: {
id: { id: {
@ -208,11 +211,13 @@ RSpec.configure do |config|
}, },
created_at: { created_at: {
type: :string, type: :string,
format: :datetime, format: 'date-time',
description: 'when the transaction was entered' description: 'when the transaction was entered'
} }
}, },
required: %w[amount note user_id] required: %w[id user_id user_name financial_transaction_type_name created_at]
}
]
}, },
FinancialTransactionForCreate: { FinancialTransactionForCreate: {
type: :object, type: :object,