From 3222e79a345590c4ef8772a202e6a094a2c5930a Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Mon, 12 Dec 2022 12:18:04 +0100 Subject: [PATCH] refactor: nullable values, financial transaction types --- .../api/financial_transaction_types_spec.rb | 35 +++--------- spec/swagger_helper.rb | 53 ++++++++++++++++--- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/spec/requests/api/financial_transaction_types_spec.rb b/spec/requests/api/financial_transaction_types_spec.rb index 68eda4da..2e737f7e 100644 --- a/spec/requests/api/financial_transaction_types_spec.rb +++ b/spec/requests/api/financial_transaction_types_spec.rb @@ -9,11 +9,12 @@ describe 'Financial Transaction types', type: :request do 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) { 10 } let(:financial_transaction_type) { create(:financial_transaction_type) } response '200', 'success' do schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/Meta' + }, financial_transaction_type: { type: :array, items: { @@ -43,36 +44,12 @@ describe 'Financial Transaction types', type: :request do } } } - let(:id) { FinancialTransactionType.create(name: 'TestType').id } + let(:id) { create(:financial_transaction_type).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 + it_handles_invalid_token_with_id :financial_transaction_type + it_cannot_find_object 'financial transaction type not found' end end end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index 0eeb05ac..d0f5bfc2 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -50,17 +50,20 @@ RSpec.configure do |config| description: 'when the order was opened' }, ends: { - type: ['string', 'null'], + type: :string, + nullable: true, format: 'date-time', description: 'when the order will close or was closed' }, boxfill: { - type: ['string', 'null'], + type: :string, + nullable: true, format: 'date-time', description: 'when the order will enter or entered the boxfill phase' }, pickup: { - type: ['string', 'null'], + type: :string, + nullable: true, format: :date, description: 'pickup date' }, @@ -88,7 +91,8 @@ RSpec.configure do |config| description: 'id of supplier, or 0 for stock articles' }, supplier_name: { - type: %w[string null], + type: :string, + nullable: true, description: 'name of the supplier, or null for stock articles' }, unit: { @@ -100,15 +104,18 @@ RSpec.configure do |config| description: 'units can only be ordered from the supplier in multiples of unit_quantity' }, note: { - type: %w[string null], + type: :string, + nullable: true, description: 'generic note' }, manufacturer: { - type: %w[string null], + type: :string, + nullable: true, description: 'manufacturer' }, origin: { - type: %w[string null], + type: :string, + nullable: true, description: 'origin, preferably (starting with a) 2-letter ISO country code' }, article_category_id: { @@ -187,10 +194,12 @@ RSpec.configure do |config| }, 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: { @@ -244,9 +253,37 @@ RSpec.configure do |config| }, name: { type: :string + }, + name_short: { + type: :string, + nullable: true, + description: 'short name (used for bank transfers)' + }, + bank_account_id: { + type: :integer, + nullable: true, + description: 'id of the bank account used for this transaction type' + }, + bank_account_name: { + type: :string, + nullable: true, + description: 'name of the bank account used for this transaction type' + }, + bank_account_iban: { + type: :string, + nullable: true, + description: 'IBAN of the bank account used for this transaction type' + }, + financial_transaction_class_id: { + type: :integer, + description: 'id of the class of the transaction' + }, + financial_transaction_class_name: { + type: :string, + description: 'name of the class of the transaction' } }, - required: %w[id name financial_transaction_class] + required: %w[id name financial_transaction_class_id financial_transaction_class_name] }, GroupOrderArticleForUpdate: { type: :object,