From c6dd8a18a306cffbc1ce1c64222f3ca1109a57da Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 25 Nov 2022 14:52:02 +0100 Subject: [PATCH] rswag financial_transaction_class --- .../api/financial_transaction_classes_spec.rb | 82 +++++++++++++++++++ spec/swagger_helper.rb | 12 +++ 2 files changed, 94 insertions(+) create mode 100644 spec/requests/api/financial_transaction_classes_spec.rb diff --git a/spec/requests/api/financial_transaction_classes_spec.rb b/spec/requests/api/financial_transaction_classes_spec.rb new file mode 100644 index 00000000..2b832ea7 --- /dev/null +++ b/spec/requests/api/financial_transaction_classes_spec.rb @@ -0,0 +1,82 @@ +require 'swagger_helper' + +describe 'Financial Transaction Classes', type: :request do + include ApiHelper + + path '/financial_transaction_classes' do + get 'financial transaction classes' 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_class) { create(:financial_transaction_class) } + response '200', 'success' do + schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/pagination' + }, + financial_transaction_class: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionClass' + } + } + } + + let(:page) { { number: 1, size: 20 } } + run_test! + end + + it_handles_invalid_token + end + end + + path '/financial_transaction_classes/{id}' do + get 'Retrieves an financial transaction class' do + tags 'Category' + produces 'application/json' + parameter name: :id, in: :path, type: :string + + response '200', 'financial transaction class found' do + schema type: :object, properties: { + financial_transaction_classes: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionClass' + } + } + } + let(:id) { FinancialTransactionClass.create(name: 'TestTransaction').id } + run_test! + end + + response '401', 'not logged in' do + schema type: :object, properties: { + financial_transaction_classes: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionClass' + } + } + } + let(:Authorization) { 'abc' } + let(:id) { FinancialTransactionClass.create(name: 'dairy').id } + run_test! + end + + response '404', 'financial transaction class not found' do + schema type: :object, properties: { + financial_transaction_classes: { + type: :array, + items: { + '$ref': '#/components/schemas/FinancialTransactionClass' + } + } + } + let(:id) { 'invalid' } + run_test! + end + end + end +end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index dcabf6c3..7fed0c91 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -46,6 +46,18 @@ RSpec.configure do |config| }, required: %w[id name] }, + FinancialTransactionClass: { + type: :object, + properties: { + id: { + type: :integer + }, + name: { + type: :string + } + }, + required: %w[id name] + }, Meta: { type: :object, properties: {