wip user/financial_transactions - first api post test
This commit is contained in:
parent
ecf5c6e1d4
commit
d8b2aa0a11
4 changed files with 168 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
default: &defaults
|
||||
multi_coop_install: false
|
||||
use_self_service: true
|
||||
default_scope: 'f'
|
||||
|
||||
name: FC Minimal
|
||||
|
|
115
spec/requests/api/user/financial_transactions_spec.rb
Normal file
115
spec/requests/api/user/financial_transactions_spec.rb
Normal file
|
@ -0,0 +1,115 @@
|
|||
require 'swagger_helper'
|
||||
|
||||
describe 'User', type: :request do
|
||||
include ApiHelper
|
||||
|
||||
let(:api_scopes) { ['finance:user'] }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:other_user2) { create :user }
|
||||
let(:ft) { create(:financial_transaction, user: user, ordergroup: user.ordergroup) }
|
||||
|
||||
before do
|
||||
ft
|
||||
end
|
||||
|
||||
path '/user/financial_transactions' do
|
||||
post 'financial transaction to create' do
|
||||
tags 'User', 'FinancialTransaction'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
|
||||
parameter name: :financial_transaction, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
amount: { type: :integer },
|
||||
financial_transaction_type: { type: :integer },
|
||||
note: { type: :string } }
|
||||
}
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
financial_transaction_for_create: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/FinancialTransactionForCreate'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:financial_transaction) { { amount: 3, financial_transaction_type_id: create(:financial_transaction_type).id, note: 'lirum larum' } }
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
|
||||
get 'financial transactions of the members ordergroup' do
|
||||
tags 'User', 'Financial Transaction'
|
||||
produces 'application/json'
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
meta: {
|
||||
type: :object,
|
||||
items:
|
||||
{
|
||||
'$ref': '#/components/schemas/Meta'
|
||||
}
|
||||
},
|
||||
financial_transaction: {
|
||||
type: :array,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/FinancialTransaction'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['financial_transactions'].first['id']).to eq(ft.id)
|
||||
end
|
||||
end
|
||||
# responses 401 & 403
|
||||
it_handles_invalid_token_and_scope
|
||||
end
|
||||
end
|
||||
|
||||
path '/user/financial_transactions/{id}' do
|
||||
get 'find financial transaction by id' do
|
||||
tags 'User', 'FinancialTransaction'
|
||||
produces 'application/json'
|
||||
parameter name: :id, in: :path, type: :string
|
||||
|
||||
response '200', 'success' do
|
||||
schema type: :object, properties: {
|
||||
financial_transaction: {
|
||||
type: :object,
|
||||
items: {
|
||||
'$ref': '#/components/schemas/FinancialTransaction'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:id) { ft.id }
|
||||
run_test! do |response|
|
||||
data = JSON.parse(response.body)
|
||||
expect(data['financial_transaction']['id']).to eq(ft.id)
|
||||
end
|
||||
end
|
||||
|
||||
# 401
|
||||
it_handles_invalid_token_with_id(:financial_transaction)
|
||||
# 403
|
||||
it_handles_invalid_scope_with_id(:financial_transaction)
|
||||
# 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
|
|
@ -45,7 +45,7 @@ module ApiHelper
|
|||
context 'with invalid scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
let(:id) { create(class_sym).id }
|
||||
|
||||
|
||||
response 403, 'missing scope' do
|
||||
schema '$ref' => '#/components/schemas/Error403'
|
||||
run_test!
|
||||
|
|
|
@ -41,6 +41,57 @@ RSpec.configure do |config|
|
|||
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,
|
||||
required: false,
|
||||
description: 'id of user who entered the transaction (may be <tt>null</tt> for deleted users or 0 for a system user)'
|
||||
},
|
||||
user_name: {
|
||||
type: :string,
|
||||
required: false,
|
||||
description: 'name of user who entered the transaction (may be <tt>null</tt> 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'
|
||||
}
|
||||
},
|
||||
required: %w[amount note user_id]
|
||||
},
|
||||
FinancialTransactionForCreate: {
|
||||
type: :object,
|
||||
properties: {
|
||||
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'
|
||||
}
|
||||
},
|
||||
required: %w[amount note user_id]
|
||||
|
|
Loading…
Reference in a new issue