diff --git a/spec/requests/api/user/financial_transactions_spec.rb b/spec/requests/api/user/financial_transactions_spec.rb index ad1cdbdf..a0dad6ff 100644 --- a/spec/requests/api/user/financial_transactions_spec.rb +++ b/spec/requests/api/user/financial_transactions_spec.rb @@ -17,10 +17,7 @@ describe 'User', type: :request do tags "Financial Transaction" consumes '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: { type: :object, properties: { @@ -29,62 +26,46 @@ describe 'User', type: :request do note: { type: :string } } } + let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } } response '200', 'success' do schema type: :object, properties: { - financial_transaction_for_create: { - type: :object, - items: { - '$ref': '#/components/schemas/FinancialTransactionForCreate' - } - } + financial_transaction: { '$ref': '#/components/schemas/FinancialTransaction' } } run_test! end - # 401 - 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_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') - # TODO: fix 404 and 422 - # 404 - # Type not found - # description: financial transaction type not found - # Should be 404, but is 200 with validation errors.. - # 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 + response '404', 'financial transaction type not found' do + schema '$ref' => '#/components/schemas/Error404' + let(:financial_transaction) { { amount: 3, financial_transaction_type_id: 'invalid', note: 'lirum larum' } } + 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 + # # schema '$ref' => '#/components/schemas/Error422' # let(:financial_transaction) { { amount: -3, financial_transaction_type_id: create(:financial_transaction_type).id, note: -2 } } - - # schema '$ref' => '#/components/schemas/Error422' # run_test! # end end + get "financial transactions of the member's ordergroup" do tags 'User', 'Financial Transaction' 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 schema type: :object, properties: { - meta: { - type: :object, - items: - { - '$ref': '#/components/schemas/Meta' - } - }, + meta: { '$ref': '#/components/schemas/Meta' }, financial_transaction: { type: :array, items: { @@ -98,7 +79,7 @@ describe 'User', type: :request do expect(data['financial_transactions'].first['id']).to eq(ft.id) end end - # responses 401 & 403 + it_handles_invalid_token_and_scope end end @@ -125,23 +106,9 @@ describe 'User', type: :request do end end - # 401 - it_handles_invalid_token_with_id(:financial_transaction) - # 403 - 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 + it_handles_invalid_token_with_id :financial_transaction + it_handles_invalid_scope_with_id :financial_transaction, 'user has no ordergroup or missing scope' + it_cannot_find_object 'financial transaction not found' end end end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index d0f5bfc2..dd06f2cc 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -174,45 +174,50 @@ RSpec.configure do |config| required: %w[id name] }, FinancialTransaction: { - type: :object, - properties: { - id: { - type: :integer - }, - amount: { - type: :integer, - description: 'amount credited (negative for a debit transaction)' - }, - financial_transaction_type_id: + allOf: [ + { '$ref': '#/components/schemas/FinancialTransactionForCreate' }, { - type: :integer, - description: 'id of the type of the transaction' - }, - note: { - type: :string, - description: 'note entered with the transaction' - }, - user_id: { - type: :integer, - nullable: true, - description: 'id of user who entered the transaction (may be null for deleted users or 0 for a system user)' - }, - user_name: { - type: :string, - nullable: true, - description: 'name of user who entered the transaction (may be null or empty string for deleted users or system users)' - }, - financial_transaction_type_name: { - type: :string, - description: 'name of the type of the transaction' - }, - created_at: { - type: :string, - format: :datetime, - description: 'when the transaction was entered' + type: :object, + properties: { + id: { + type: :integer + }, + amount: { + type: :integer, + description: 'amount credited (negative for a debit transaction)' + }, + financial_transaction_type_id: + { + type: :integer, + description: 'id of the type of the transaction' + }, + note: { + type: :string, + description: 'note entered with the transaction' + }, + user_id: { + type: :integer, + nullable: true, + description: 'id of user who entered the transaction (may be null for deleted users or 0 for a system user)' + }, + user_name: { + type: :string, + nullable: true, + description: 'name of user who entered the transaction (may be null or empty string for deleted users or system users)' + }, + financial_transaction_type_name: { + type: :string, + description: 'name of the type of the transaction' + }, + created_at: { + type: :string, + format: 'date-time', + description: 'when the transaction was entered' + } + }, + required: %w[id user_id user_name financial_transaction_type_name created_at] } - }, - required: %w[amount note user_id] + ] }, FinancialTransactionForCreate: { type: :object,