diff --git a/spec/app_config.yml b/spec/app_config.yml
index 2e146be9..a9bd72b0 100644
--- a/spec/app_config.yml
+++ b/spec/app_config.yml
@@ -6,6 +6,7 @@
default: &defaults
multi_coop_install: false
+ use_self_service: true
default_scope: 'f'
name: FC Minimal
diff --git a/spec/requests/api/user/financial_transactions_spec.rb b/spec/requests/api/user/financial_transactions_spec.rb
new file mode 100644
index 00000000..699c0347
--- /dev/null
+++ b/spec/requests/api/user/financial_transactions_spec.rb
@@ -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
diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb
index 5b97414a..7780db8a 100644
--- a/spec/support/api_helper.rb
+++ b/spec/support/api_helper.rb
@@ -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!
diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb
index 9f1d1f7e..8c26d089 100644
--- a/spec/swagger_helper.rb
+++ b/spec/swagger_helper.rb
@@ -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 null 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 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'
+ }
+ },
+ 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]