diff --git a/spec/requests/api/financial_transaction_classes_spec.rb b/spec/requests/api/financial_transaction_classes_spec.rb index 2b832ea7..b8efd567 100644 --- a/spec/requests/api/financial_transaction_classes_spec.rb +++ b/spec/requests/api/financial_transaction_classes_spec.rb @@ -11,6 +11,7 @@ describe 'Financial Transaction Classes', type: :request do parameter name: "page[size]", in: :query, type: :integer, required: false let!(:financial_transaction_class) { create(:financial_transaction_class) } + response '200', 'success' do schema type: :object, properties: { meta: { @@ -33,7 +34,7 @@ describe 'Financial Transaction Classes', type: :request do end path '/financial_transaction_classes/{id}' do - get 'Retrieves an financial transaction class' do + get 'Retrieves a financial transaction class' do tags 'Category' produces 'application/json' parameter name: :id, in: :path, type: :string @@ -52,7 +53,7 @@ describe 'Financial Transaction Classes', type: :request do end response '401', 'not logged in' do - schema type: :object, properties: { + schema type: :object, properties: { financial_transaction_classes: { type: :array, items: { @@ -61,7 +62,7 @@ describe 'Financial Transaction Classes', type: :request do } } let(:Authorization) { 'abc' } - let(:id) { FinancialTransactionClass.create(name: 'dairy').id } + let(:id) { FinancialTransactionClass.create(name: 'TestTransaction').id } run_test! end diff --git a/spec/requests/api/financial_transaction_types_spec.rb b/spec/requests/api/financial_transaction_types_spec.rb new file mode 100644 index 00000000..3e5efdaa --- /dev/null +++ b/spec/requests/api/financial_transaction_types_spec.rb @@ -0,0 +1,82 @@ +require 'swagger_helper' + +describe 'Financial Transaction types', type: :request do + include ApiHelper + + path '/financial_transaction_types' do + get 'financial transaction types' do + tags 'Category' + produces 'application/json' + parameter name: "page[number]", in: :query, type: :integer, required: false + parameter name: "page[size]", in: :query, type: :integer, required: false + + let!(:financial_transaction_type) { create(:financial_transaction_type) } + response '200', 'success' do + schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/pagination' + }, + financial_transaction_type: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionType' + } + } + } + + let(:page) { { number: 1, size: 20 } } + run_test! + end + + it_handles_invalid_token + end + end + + path '/financial_transaction_types/{id}' do + get 'Retrieves a financial transaction type' do + tags 'Category' + produces 'application/json' + parameter name: :id, in: :path, type: :string + + response '200', 'financial transaction type found' do + schema type: :object, properties: { + financial_transaction_types: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionType' + } + } + } + let(:id) { FinancialTransactionType.create(name: 'TestType').id } + run_test! + end + + response '401', 'not logged in' do + schema type: :object, properties: { + financial_transaction_types: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionType' + } + } + } + let(:Authorization) { 'abc' } + let(:id) { FinancialTransactionType.create(name: 'TestType').id } + run_test! + end + + response '404', 'financial transaction type not found' do + schema type: :object, properties: { + financial_transaction_types: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionType' + } + } + } + let(:id) { 'invalid' } + run_test! + end + end + end +end diff --git a/spec/requests/api/financial_transactions_spec.rb b/spec/requests/api/financial_transactions_spec.rb new file mode 100644 index 00000000..6c27a9a8 --- /dev/null +++ b/spec/requests/api/financial_transactions_spec.rb @@ -0,0 +1,84 @@ +require 'swagger_helper' + +describe 'Financial Transaction', type: :request do + include ApiHelper + + path '/financial_transactions' do + get 'financial transactions' do + tags 'Financial Transaction' + produces 'application/json' + parameter name: "page[number]", in: :query, type: :integer, required: false + parameter name: "page[size]", in: :query, type: :integer, required: false + + let!(:financial_transaction) { create(:financial_transaction) } + let(:api_scopes) { ['finance:read', 'finance:write'] } + + response '200', 'success' do + schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/pagination' + }, + financial_transaction: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransaction' + } + } + } + + let(:page) { { number: 1, size: 20 } } + run_test! + end + + it_handles_invalid_token + end + end + + path '/financial_transactions/{id}' do + get 'Retrieves a financial transaction ' do + tags 'Category' + produces 'application/json' + parameter name: :id, in: :path, type: :string + + response '200', 'financial transaction found' do + schema type: :object, properties: { + financial_transaction: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransaction' + } + } + } + let(:id) { FinancialTransaction.create(user: user).id } + run_test! + end + + response '401', 'not logged in' do + schema type: :object, properties: { + financial_transaction: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransaction' + } + } + } + let(:Authorization) { 'abc' } + let(:id) { FinancialTransaction.create(name: 'TestTransaction').id } + run_test! + end + + response '404', 'financial transaction not found' do + schema type: :object, properties: { + financial_transaction: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransaction' + } + } + } + let(:id) { 'invalid' } + run_test! + end + end + end +end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index 7fed0c91..5f066aec 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -46,6 +46,18 @@ RSpec.configure do |config| }, required: %w[id name] }, + FinancialTransaction: { + type: :object, + properties: { + id: { + type: :integer + }, + name: { + type: :string + } + }, + required: %w[id financial_transaction_type] + }, FinancialTransactionClass: { type: :object, properties: { @@ -58,6 +70,18 @@ RSpec.configure do |config| }, required: %w[id name] }, + FinancialTransactionType: { + type: :object, + properties: { + id: { + type: :integer + }, + name: { + type: :string + } + }, + required: %w[id name financial_transaction_class] + }, Meta: { type: :object, properties: {