From 0c348277489ef3743498d024378722e814c94552 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Thu, 18 Jul 2024 14:43:46 +0200 Subject: [PATCH 01/25] feat: add migration for IntegrationErrorDetails --- db/schema.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/db/schema.rb b/db/schema.rb index 2fabef2b337..bdf2a35cf5e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -619,6 +619,17 @@ t.index ["integration_id"], name: "index_integration_customers_on_integration_id" end + create_table "integration_error_details", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "owner_type", null: false + t.uuid "owner_id", null: false + t.uuid "integration_id", null: false + t.jsonb "details", default: {}, null: false + t.datetime "deleted_at" + t.index ["deleted_at"], name: "index_integration_error_details_on_deleted_at" + t.index ["integration_id"], name: "index_integration_error_details_on_integration_id" + t.index ["owner_type", "owner_id"], name: "index_integration_error_details_on_owner" + end + create_table "integration_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "integration_id", null: false t.integer "item_type", null: false @@ -1151,6 +1162,7 @@ add_foreign_key "integration_collection_mappings", "integrations" add_foreign_key "integration_customers", "customers" add_foreign_key "integration_customers", "integrations" + add_foreign_key "integration_error_details", "integrations" add_foreign_key "integration_items", "integrations" add_foreign_key "integration_mappings", "integrations" add_foreign_key "integration_resources", "integrations" From bcacbccde87decaddde9a748361e1f268b4917af Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 08:47:49 +0200 Subject: [PATCH 02/25] feat: add polymorphic relation on integration_error_details to the integration --- db/schema.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index bdf2a35cf5e..6525fa6194f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -622,11 +622,14 @@ create_table "integration_error_details", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "owner_type", null: false t.uuid "owner_id", null: false + t.string "integration_type", null: false t.uuid "integration_id", null: false t.jsonb "details", default: {}, null: false t.datetime "deleted_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["deleted_at"], name: "index_integration_error_details_on_deleted_at" - t.index ["integration_id"], name: "index_integration_error_details_on_integration_id" + t.index ["integration_type", "integration_id"], name: "index_integration_error_details_on_integration" t.index ["owner_type", "owner_id"], name: "index_integration_error_details_on_owner" end @@ -1162,7 +1165,6 @@ add_foreign_key "integration_collection_mappings", "integrations" add_foreign_key "integration_customers", "customers" add_foreign_key "integration_customers", "integrations" - add_foreign_key "integration_error_details", "integrations" add_foreign_key "integration_items", "integrations" add_foreign_key "integration_mappings", "integrations" add_foreign_key "integration_resources", "integrations" From a4b58d2e7704effb1549a66e71f4e98cad3443ad Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 09:07:13 +0200 Subject: [PATCH 03/25] feat: found better name for the abstraction --- db/schema.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 6525fa6194f..a1caed3f8dc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -622,14 +622,14 @@ create_table "integration_error_details", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "owner_type", null: false t.uuid "owner_id", null: false - t.string "integration_type", null: false - t.uuid "integration_id", null: false + t.string "error_producer_type", null: false + t.uuid "error_producer_id", null: false t.jsonb "details", default: {}, null: false t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["deleted_at"], name: "index_integration_error_details_on_deleted_at" - t.index ["integration_type", "integration_id"], name: "index_integration_error_details_on_integration" + t.index ["error_producer_type", "error_producer_id"], name: "index_integration_error_details_on_error_producer" t.index ["owner_type", "owner_id"], name: "index_integration_error_details_on_owner" end From 396276b21b25b3ef41a9ffa5d04f2b816f2593dc Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 15:44:13 +0200 Subject: [PATCH 04/25] feat: more discussion on abstractions at error_details --- db/schema.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index a1caed3f8dc..2fabef2b337 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -619,20 +619,6 @@ t.index ["integration_id"], name: "index_integration_customers_on_integration_id" end - create_table "integration_error_details", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "owner_type", null: false - t.uuid "owner_id", null: false - t.string "error_producer_type", null: false - t.uuid "error_producer_id", null: false - t.jsonb "details", default: {}, null: false - t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["deleted_at"], name: "index_integration_error_details_on_deleted_at" - t.index ["error_producer_type", "error_producer_id"], name: "index_integration_error_details_on_error_producer" - t.index ["owner_type", "owner_id"], name: "index_integration_error_details_on_owner" - end - create_table "integration_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "integration_id", null: false t.integer "item_type", null: false From 08b9fcd4746e11a4e4c40c3e7d32029a6d0ef088 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Thu, 18 Jul 2024 18:24:20 +0200 Subject: [PATCH 05/25] feat: add model for integration_error_details --- app/models/integration_error_detail.rb | 7 +++++++ spec/factories/integration_error_details.rb | 5 +++++ spec/models/integration_error_detail_spec.rb | 6 ++++++ spec/models/invoice_spec.rb | 2 ++ 4 files changed, 20 insertions(+) create mode 100644 app/models/integration_error_detail.rb create mode 100644 spec/factories/integration_error_details.rb create mode 100644 spec/models/integration_error_detail_spec.rb diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb new file mode 100644 index 00000000000..4c737f0cc8e --- /dev/null +++ b/app/models/integration_error_detail.rb @@ -0,0 +1,7 @@ +class IntegrationErrorDetail < ApplicationRecord + include Discard::Model + self.discard_column = :deleted_at + + belongs_to :integration, class_name: 'Integrations::BaseIntegration' + belongs_to :owner, polymorphic: true +end diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb new file mode 100644 index 00000000000..66e52e67376 --- /dev/null +++ b/spec/factories/integration_error_details.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :integration_error_detail do + + end +end diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb new file mode 100644 index 00000000000..bf062639233 --- /dev/null +++ b/spec/models/integration_error_detail_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +RSpec.describe IntegrationErrorDetail, type: :model do + it { is_expected.to belong_to(:integration) } + it { is_expected.to belong_to(:owner) } +end diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 6d230e0d8fb..496ba42769d 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -18,6 +18,8 @@ expect(described_class::STATUS).to match(draft: 0, finalized: 1, voided: 2, generating: 3, failed: 4, open: 5) end + it { is_expected.to have_many(:integration_error_details) } + describe 'validation' do describe 'of payment dispute lost absence' do context 'when invoice is not voided' do From a94ae7e5ec692b68f8aeac610cb2cd8af14dfdba Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 19 Jul 2024 14:33:33 +0200 Subject: [PATCH 06/25] feat: WIP adding test setup for new model --- app/models/integration_error_detail.rb | 2 ++ spec/factories/integration_error_details.rb | 4 +++- spec/models/integration_error_detail_spec.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb index 4c737f0cc8e..31e97a74bf9 100644 --- a/app/models/integration_error_detail.rb +++ b/app/models/integration_error_detail.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class IntegrationErrorDetail < ApplicationRecord include Discard::Model self.discard_column = :deleted_at diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb index 66e52e67376..3ed451a6ada 100644 --- a/spec/factories/integration_error_details.rb +++ b/spec/factories/integration_error_details.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + FactoryBot.define do factory :integration_error_detail do - + integration end end diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb index bf062639233..9bbe1d55601 100644 --- a/spec/models/integration_error_detail_spec.rb +++ b/spec/models/integration_error_detail_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe IntegrationErrorDetail, type: :model do From a15c3d4f0aa67264b2e426440b2b79e4c5b2c984 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 09:31:47 +0200 Subject: [PATCH 07/25] feat: rename integration relation on integration_error_details to error_producer --- app/models/integration_error_detail.rb | 2 +- app/models/integrations/base_integration.rb | 1 + spec/models/integrations/base_integration_spec.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb index 31e97a74bf9..b3c34a956b5 100644 --- a/app/models/integration_error_detail.rb +++ b/app/models/integration_error_detail.rb @@ -4,6 +4,6 @@ class IntegrationErrorDetail < ApplicationRecord include Discard::Model self.discard_column = :deleted_at - belongs_to :integration, class_name: 'Integrations::BaseIntegration' + belongs_to :error_producer, polymorphic: true belongs_to :owner, polymorphic: true end diff --git a/app/models/integrations/base_integration.rb b/app/models/integrations/base_integration.rb index 5d184003041..3a5d4c9c4bc 100644 --- a/app/models/integrations/base_integration.rb +++ b/app/models/integrations/base_integration.rb @@ -24,6 +24,7 @@ class BaseIntegration < ApplicationRecord class_name: 'IntegrationCustomers::BaseCustomer', foreign_key: :integration_id, dependent: :destroy + has_many :integration_error_details, as: :error_producer validates :code, uniqueness: {scope: :organization_id} validates :name, presence: true diff --git a/spec/models/integrations/base_integration_spec.rb b/spec/models/integrations/base_integration_spec.rb index 437e1c9e9f3..f2a65586384 100644 --- a/spec/models/integrations/base_integration_spec.rb +++ b/spec/models/integrations/base_integration_spec.rb @@ -18,6 +18,7 @@ it { is_expected.to have_many(:integration_customers).dependent(:destroy) } it { is_expected.to have_many(:integration_items).dependent(:destroy) } it { is_expected.to have_many(:integration_resources).dependent(:destroy) } + it { is_expected.to have_many(:integration_error_details) } describe '.secrets_json' do it { expect(integration.secrets_json).to eq(secrets) } From eb112e8fd45f8989dd0bf1c5f3d8e3008dcbe1fc Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 11:14:59 +0200 Subject: [PATCH 08/25] feat: better definition of integration_error_details factory --- spec/factories/integration_error_details.rb | 3 ++- spec/models/integration_error_detail_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb index 3ed451a6ada..402573b9747 100644 --- a/spec/factories/integration_error_details.rb +++ b/spec/factories/integration_error_details.rb @@ -2,6 +2,7 @@ FactoryBot.define do factory :integration_error_detail do - integration + association :owner, factory: %i[invoice].sample + association :error_producer, factory: :anrok_integration end end diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb index 9bbe1d55601..05f5ae618ca 100644 --- a/spec/models/integration_error_detail_spec.rb +++ b/spec/models/integration_error_detail_spec.rb @@ -3,6 +3,6 @@ require 'rails_helper' RSpec.describe IntegrationErrorDetail, type: :model do - it { is_expected.to belong_to(:integration) } + it { is_expected.to belong_to(:error_producer) } it { is_expected.to belong_to(:owner) } end From 806e07a6698d78a23563b228da566d11e7630228 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 16:06:38 +0200 Subject: [PATCH 09/25] feat: rename integration_error_detail model to error_detail --- app/models/integration_error_detail.rb | 9 --------- app/models/integrations/base_integration.rb | 2 +- spec/factories/integration_error_details.rb | 8 -------- spec/models/integration_error_detail_spec.rb | 8 -------- spec/models/integrations/base_integration_spec.rb | 2 +- 5 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 app/models/integration_error_detail.rb delete mode 100644 spec/factories/integration_error_details.rb delete mode 100644 spec/models/integration_error_detail_spec.rb diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb deleted file mode 100644 index b3c34a956b5..00000000000 --- a/app/models/integration_error_detail.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class IntegrationErrorDetail < ApplicationRecord - include Discard::Model - self.discard_column = :deleted_at - - belongs_to :error_producer, polymorphic: true - belongs_to :owner, polymorphic: true -end diff --git a/app/models/integrations/base_integration.rb b/app/models/integrations/base_integration.rb index 3a5d4c9c4bc..15310f5c4ea 100644 --- a/app/models/integrations/base_integration.rb +++ b/app/models/integrations/base_integration.rb @@ -24,7 +24,7 @@ class BaseIntegration < ApplicationRecord class_name: 'IntegrationCustomers::BaseCustomer', foreign_key: :integration_id, dependent: :destroy - has_many :integration_error_details, as: :error_producer + has_many :error_details, as: :integration validates :code, uniqueness: {scope: :organization_id} validates :name, presence: true diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb deleted file mode 100644 index 402573b9747..00000000000 --- a/spec/factories/integration_error_details.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :integration_error_detail do - association :owner, factory: %i[invoice].sample - association :error_producer, factory: :anrok_integration - end -end diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb deleted file mode 100644 index 05f5ae618ca..00000000000 --- a/spec/models/integration_error_detail_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe IntegrationErrorDetail, type: :model do - it { is_expected.to belong_to(:error_producer) } - it { is_expected.to belong_to(:owner) } -end diff --git a/spec/models/integrations/base_integration_spec.rb b/spec/models/integrations/base_integration_spec.rb index f2a65586384..e5c7826a10c 100644 --- a/spec/models/integrations/base_integration_spec.rb +++ b/spec/models/integrations/base_integration_spec.rb @@ -18,7 +18,7 @@ it { is_expected.to have_many(:integration_customers).dependent(:destroy) } it { is_expected.to have_many(:integration_items).dependent(:destroy) } it { is_expected.to have_many(:integration_resources).dependent(:destroy) } - it { is_expected.to have_many(:integration_error_details) } + it { is_expected.to have_many(:error_details) } describe '.secrets_json' do it { expect(integration.secrets_json).to eq(secrets) } From 13abfaf4d7cb0603abdab5460e8fa5cbe660803c Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 11:08:14 +0200 Subject: [PATCH 10/25] feat: update error_detail model to belong to organization --- spec/models/organization_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 360d913a80e..f9743260d4f 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -21,6 +21,7 @@ it { is_expected.to have_many(:netsuite_integrations) } it { is_expected.to have_many(:xero_integrations) } it { is_expected.to have_many(:data_exports) } + it { is_expected.to have_many(:error_details) } it { is_expected.to validate_inclusion_of(:default_currency).in_array(described_class.currency_list) } From 4bbef33eea82f33489aa68efdbcac54d2bbf26a0 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 17:39:58 +0200 Subject: [PATCH 11/25] feat: remove integration association from error_detail --- app/models/integrations/base_integration.rb | 1 - spec/models/integrations/base_integration_spec.rb | 1 - spec/models/organization_spec.rb | 1 - 3 files changed, 3 deletions(-) diff --git a/app/models/integrations/base_integration.rb b/app/models/integrations/base_integration.rb index 15310f5c4ea..5d184003041 100644 --- a/app/models/integrations/base_integration.rb +++ b/app/models/integrations/base_integration.rb @@ -24,7 +24,6 @@ class BaseIntegration < ApplicationRecord class_name: 'IntegrationCustomers::BaseCustomer', foreign_key: :integration_id, dependent: :destroy - has_many :error_details, as: :integration validates :code, uniqueness: {scope: :organization_id} validates :name, presence: true diff --git a/spec/models/integrations/base_integration_spec.rb b/spec/models/integrations/base_integration_spec.rb index e5c7826a10c..437e1c9e9f3 100644 --- a/spec/models/integrations/base_integration_spec.rb +++ b/spec/models/integrations/base_integration_spec.rb @@ -18,7 +18,6 @@ it { is_expected.to have_many(:integration_customers).dependent(:destroy) } it { is_expected.to have_many(:integration_items).dependent(:destroy) } it { is_expected.to have_many(:integration_resources).dependent(:destroy) } - it { is_expected.to have_many(:error_details) } describe '.secrets_json' do it { expect(integration.secrets_json).to eq(secrets) } diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index f9743260d4f..360d913a80e 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -21,7 +21,6 @@ it { is_expected.to have_many(:netsuite_integrations) } it { is_expected.to have_many(:xero_integrations) } it { is_expected.to have_many(:data_exports) } - it { is_expected.to have_many(:error_details) } it { is_expected.to validate_inclusion_of(:default_currency).in_array(described_class.currency_list) } From 55b30256b7747fe5cdb8d914248f451db699d9a4 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 24 Jul 2024 11:01:03 +0200 Subject: [PATCH 12/25] change error_code type on error_detail to integer --- ...6_change_error_code_type_on_error_details.rb | 17 +++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240724085326_change_error_code_type_on_error_details.rb diff --git a/db/migrate/20240724085326_change_error_code_type_on_error_details.rb b/db/migrate/20240724085326_change_error_code_type_on_error_details.rb new file mode 100644 index 00000000000..d37835485f5 --- /dev/null +++ b/db/migrate/20240724085326_change_error_code_type_on_error_details.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ChangeErrorCodeTypeOnErrorDetails < ActiveRecord::Migration[7.1] + def up + change_table :error_details, bulk: true do |t| + t.remove :error_code + t.integer :error_code, null: false, default: 0, index: true + end + end + + def down + change_table :error_details, bulk: true do |t| + t.remove :error_code + t.string :error_code, index: true, null: false, default: 'not_provided' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2fabef2b337..6bdf231dadc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_23_150221) do +ActiveRecord::Schema[7.1].define(version: 2024_07_24_085326) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" From 89b18b2e3521e9708595a9dea0dd7049d7285d15 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 24 Jul 2024 13:30:19 +0200 Subject: [PATCH 13/25] unite two migrations --- ...e_integration_reference_from_error_detail.rb | 1 + ...6_change_error_code_type_on_error_details.rb | 17 ----------------- db/schema.rb | 2 +- 3 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 db/migrate/20240724085326_change_error_code_type_on_error_details.rb diff --git a/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb b/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb index 984728e1a1f..01983c4ae90 100644 --- a/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb +++ b/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb @@ -17,3 +17,4 @@ def down end end end + diff --git a/db/migrate/20240724085326_change_error_code_type_on_error_details.rb b/db/migrate/20240724085326_change_error_code_type_on_error_details.rb deleted file mode 100644 index d37835485f5..00000000000 --- a/db/migrate/20240724085326_change_error_code_type_on_error_details.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class ChangeErrorCodeTypeOnErrorDetails < ActiveRecord::Migration[7.1] - def up - change_table :error_details, bulk: true do |t| - t.remove :error_code - t.integer :error_code, null: false, default: 0, index: true - end - end - - def down - change_table :error_details, bulk: true do |t| - t.remove :error_code - t.string :error_code, index: true, null: false, default: 'not_provided' - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 6bdf231dadc..2fabef2b337 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_24_085326) do +ActiveRecord::Schema[7.1].define(version: 2024_07_23_150221) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" From 6324999793dca8e964e7747e17a9b60049f8c689 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 24 Jul 2024 13:34:55 +0200 Subject: [PATCH 14/25] unite two migrations --- ...40723150221_remove_integration_reference_from_error_detail.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb b/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb index 01983c4ae90..984728e1a1f 100644 --- a/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb +++ b/db/migrate/20240723150221_remove_integration_reference_from_error_detail.rb @@ -17,4 +17,3 @@ def down end end end - From 9c1fabc75f874713053ddc70d61d41c340cc753e Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 19 Jul 2024 14:33:33 +0200 Subject: [PATCH 15/25] feat: WIP adding test setup for new model --- app/models/integration_error_detail.rb | 0 spec/factories/integration_error_details.rb | 0 spec/models/integration_error_detail_spec.rb | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/models/integration_error_detail.rb create mode 100644 spec/factories/integration_error_details.rb create mode 100644 spec/models/integration_error_detail_spec.rb diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb new file mode 100644 index 00000000000..e69de29bb2d From b0c3fb637d5b77050d4132af01ac37de4cccf83c Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 13:04:36 +0200 Subject: [PATCH 16/25] feat: WIP - add create integration_error_detail service --- .../integration_error_details/base_service.rb | 23 +++++++++++ .../create_service.rb | 36 +++++++++++++++++ .../create_service_spec.rb | 40 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 app/services/integration_error_details/base_service.rb create mode 100644 app/services/integration_error_details/create_service.rb create mode 100644 spec/services/integration_error_details/create_service_spec.rb diff --git a/app/services/integration_error_details/base_service.rb b/app/services/integration_error_details/base_service.rb new file mode 100644 index 00000000000..d1b5d8268bb --- /dev/null +++ b/app/services/integration_error_details/base_service.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module IntegrationErrorDetails + class BaseService < BaseService + def initialize(params:, error_producer:, owner:) + @params = params + @error_producer = error_producer + @owner = owner + + super + end + + def call + result.not_found_failure!(resource: 'error_producer') unless error_producer + result.not_found_failure!(resource: 'owner') unless owner + result + end + + private + + attr_reader :params, :error_producer, :owner + end +end diff --git a/app/services/integration_error_details/create_service.rb b/app/services/integration_error_details/create_service.rb new file mode 100644 index 00000000000..cf00c1d8e0a --- /dev/null +++ b/app/services/integration_error_details/create_service.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module IntegrationErrorDetails + class CreateService < BaseService + def initialize(params:, error_producer:, owner:) + @error_producer = error_producer + @owner = owner + super(params:, error_producer:, owner:) + end + + def call + result = super + return result if result.error + + res = create_integration_error_details! + return res if res&.error + + res + end + + private + + attr_reader :error_producer, :owner + + def create_integration_error_details! + new_integration_error = IntegrationErrorDetail.create!( + error_producer:, + owner:, + details: params[:details] + ) + + result.integration_error_details = new_integration_error + result + end + end +end diff --git a/spec/services/integration_error_details/create_service_spec.rb b/spec/services/integration_error_details/create_service_spec.rb new file mode 100644 index 00000000000..e2f7342bed0 --- /dev/null +++ b/spec/services/integration_error_details/create_service_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe IntegrationErrorDetails::CreateService, type: :service do + let(:membership) { create(:membership) } + let(:organization) { membership.organization } + let(:customer) { create(:customer, organization:) } + let(:error_producer) { create(:anrok_integration, organization:) } + let(:owner) { create(:invoice, organization:, customer:) } + + describe '#call' do + subject(:service_call) { described_class.call(params:, error_producer:, owner:) } + + let(:params) do + { + details: {'error_code' => 'taxDateTooFarInFuture'} + } + end + + context 'when all required data present' do + it 'creates an integration_error_detail' do + expect { service_call }.to change(IntegrationErrorDetail, :count).by(1) + end + + it 'returns created integration_error_detail' do + result = service_call + + aggregate_failures do + expect(result).to be_success + expect(result.integration_error_details.owner_id).to eq(owner.id) + expect(result.integration_error_details.owner_type).to eq(owner.class.to_s) + expect(result.integration_error_details.error_producer_id).to eq(error_producer.id) + expect(result.integration_error_details.error_producer.class.to_s).to eq(error_producer.class.to_s) + expect(result.integration_error_details.details).to eq(params[:details]) + end + end + end + end +end From 8f598362df8d3e06dbdce56d963b697a475ba8f0 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 16:51:31 +0200 Subject: [PATCH 17/25] feat: more tests for the new service --- app/services/error_details/base_service.rb | 22 ++++++ app/services/error_details/create_service.rb | 36 +++++++++ .../integration_error_details/base_service.rb | 23 ------ .../create_service.rb | 36 --------- .../error_details/create_service_spec.rb | 77 +++++++++++++++++++ .../create_service_spec.rb | 40 ---------- 6 files changed, 135 insertions(+), 99 deletions(-) create mode 100644 app/services/error_details/base_service.rb create mode 100644 app/services/error_details/create_service.rb delete mode 100644 app/services/integration_error_details/base_service.rb delete mode 100644 app/services/integration_error_details/create_service.rb create mode 100644 spec/services/error_details/create_service_spec.rb delete mode 100644 spec/services/integration_error_details/create_service_spec.rb diff --git a/app/services/error_details/base_service.rb b/app/services/error_details/base_service.rb new file mode 100644 index 00000000000..2569588efb6 --- /dev/null +++ b/app/services/error_details/base_service.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module ErrorDetails + class BaseService < BaseService + def initialize(params:, integration: nil, owner:) + @params = params + @integration = integration + @owner = owner + + super + end + + def call + result.not_found_failure!(resource: 'owner') unless owner + result + end + + private + + attr_reader :params, :integration, :owner + end +end diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb new file mode 100644 index 00000000000..4bc7b3a390a --- /dev/null +++ b/app/services/error_details/create_service.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module ErrorDetails + class CreateService < BaseService + def initialize(params:, integration: nil, owner:) + @integration = integration + @owner = owner + super(params:, integration:, owner:) + end + + def call + result = super + return result if result.error + + res = create_error_details! + return res if res&.error + + res + end + + private + + attr_reader :integration, :owner + + def create_error_details! + new_error = ErrorDetail.create!( + integration:, + owner:, + details: params[:details] + ) + + result.error_details = new_error + result + end + end +end diff --git a/app/services/integration_error_details/base_service.rb b/app/services/integration_error_details/base_service.rb deleted file mode 100644 index d1b5d8268bb..00000000000 --- a/app/services/integration_error_details/base_service.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module IntegrationErrorDetails - class BaseService < BaseService - def initialize(params:, error_producer:, owner:) - @params = params - @error_producer = error_producer - @owner = owner - - super - end - - def call - result.not_found_failure!(resource: 'error_producer') unless error_producer - result.not_found_failure!(resource: 'owner') unless owner - result - end - - private - - attr_reader :params, :error_producer, :owner - end -end diff --git a/app/services/integration_error_details/create_service.rb b/app/services/integration_error_details/create_service.rb deleted file mode 100644 index cf00c1d8e0a..00000000000 --- a/app/services/integration_error_details/create_service.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -module IntegrationErrorDetails - class CreateService < BaseService - def initialize(params:, error_producer:, owner:) - @error_producer = error_producer - @owner = owner - super(params:, error_producer:, owner:) - end - - def call - result = super - return result if result.error - - res = create_integration_error_details! - return res if res&.error - - res - end - - private - - attr_reader :error_producer, :owner - - def create_integration_error_details! - new_integration_error = IntegrationErrorDetail.create!( - error_producer:, - owner:, - details: params[:details] - ) - - result.integration_error_details = new_integration_error - result - end - end -end diff --git a/spec/services/error_details/create_service_spec.rb b/spec/services/error_details/create_service_spec.rb new file mode 100644 index 00000000000..478c6d21ff2 --- /dev/null +++ b/spec/services/error_details/create_service_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ErrorDetails::CreateService, type: :service do + let(:membership) { create(:membership) } + let(:organization) { membership.organization } + let(:customer) { create(:customer, organization:) } + let(:integration) { create(:anrok_integration, organization:) } + let(:owner) { create(:invoice, organization:, customer:) } + + describe '#call' do + subject(:service_call) { described_class.call(params:, integration:, owner:) } + + let(:params) do + { + details: {'error_code' => 'taxDateTooFarInFuture'} + } + end + + context 'when all both - owner and integration are provided' do + it 'creates an integration_error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(1) + end + + it 'returns created integration_error_detail' do + result = service_call + + aggregate_failures do + expect(result).to be_success + expect(result.error_details.owner_id).to eq(owner.id) + expect(result.error_details.owner_type).to eq(owner.class.to_s) + expect(result.error_details.integration_id).to eq(integration.id) + expect(result.error_details.integration.class.to_s).to eq(integration.class.to_s) + expect(result.error_details.details).to eq(params[:details]) + end + end + end + + context 'when no integration association is provided' do + subject(:service_call) { described_class.call(params:, owner:) } + + it 'creates an integration_error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(1) + end + + it 'returns created integration_error_detail' do + result = service_call + + aggregate_failures do + expect(result).to be_success + expect(result.error_details.owner_id).to eq(owner.id) + expect(result.error_details.owner_type).to eq(owner.class.to_s) + expect(result.error_details.integration_id).to eq(nil) + expect(result.error_details.integration_type).to eq(nil) + expect(result.error_details.details).to eq(params[:details]) + end + end + end + + context 'when no owner is provided' do + subject(:service_call) { described_class.call(params:, integration:, owner: nil) } + + it 'does not create an integration_error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(0) + end + + it 'returns created integration_error_detail' do + result = service_call + aggregate_failures do + expect(result.error).to be_a(BaseService::NotFoundFailure) + expect(result.error.message).to include('owner_not_found') + end + end + end + end +end diff --git a/spec/services/integration_error_details/create_service_spec.rb b/spec/services/integration_error_details/create_service_spec.rb deleted file mode 100644 index e2f7342bed0..00000000000 --- a/spec/services/integration_error_details/create_service_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe IntegrationErrorDetails::CreateService, type: :service do - let(:membership) { create(:membership) } - let(:organization) { membership.organization } - let(:customer) { create(:customer, organization:) } - let(:error_producer) { create(:anrok_integration, organization:) } - let(:owner) { create(:invoice, organization:, customer:) } - - describe '#call' do - subject(:service_call) { described_class.call(params:, error_producer:, owner:) } - - let(:params) do - { - details: {'error_code' => 'taxDateTooFarInFuture'} - } - end - - context 'when all required data present' do - it 'creates an integration_error_detail' do - expect { service_call }.to change(IntegrationErrorDetail, :count).by(1) - end - - it 'returns created integration_error_detail' do - result = service_call - - aggregate_failures do - expect(result).to be_success - expect(result.integration_error_details.owner_id).to eq(owner.id) - expect(result.integration_error_details.owner_type).to eq(owner.class.to_s) - expect(result.integration_error_details.error_producer_id).to eq(error_producer.id) - expect(result.integration_error_details.error_producer.class.to_s).to eq(error_producer.class.to_s) - expect(result.integration_error_details.details).to eq(params[:details]) - end - end - end - end -end From 5931cdcdb731c5b858a0b2f1a0350860a99f6f32 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 22 Jul 2024 16:53:07 +0200 Subject: [PATCH 18/25] feat: remove not needed duplications --- app/services/error_details/create_service.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb index 4bc7b3a390a..d2e4a9c8fc5 100644 --- a/app/services/error_details/create_service.rb +++ b/app/services/error_details/create_service.rb @@ -3,8 +3,6 @@ module ErrorDetails class CreateService < BaseService def initialize(params:, integration: nil, owner:) - @integration = integration - @owner = owner super(params:, integration:, owner:) end @@ -20,8 +18,6 @@ def call private - attr_reader :integration, :owner - def create_error_details! new_error = ErrorDetail.create!( integration:, From 7eada194a58ac4a5279c00fe884d5964967f9856 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 11:20:24 +0200 Subject: [PATCH 19/25] feat: delete accidentally added empty files --- spec/factories/integration_error_details.rb | 0 spec/models/integration_error_detail_spec.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 spec/factories/integration_error_details.rb delete mode 100644 spec/models/integration_error_detail_spec.rb diff --git a/spec/factories/integration_error_details.rb b/spec/factories/integration_error_details.rb deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/spec/models/integration_error_detail_spec.rb b/spec/models/integration_error_detail_spec.rb deleted file mode 100644 index e69de29bb2d..00000000000 From 36fd2f115fbe6b611698cb3810f3554fb4c637db Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 12:37:50 +0200 Subject: [PATCH 20/25] feat: add relation to organization for error_detail --- app/models/integration_error_detail.rb | 0 app/services/error_details/base_service.rb | 6 +- app/services/error_details/create_service.rb | 10 +- .../error_details/create_service_spec.rb | 105 +++++++++++------- 4 files changed, 78 insertions(+), 43 deletions(-) delete mode 100644 app/models/integration_error_detail.rb diff --git a/app/models/integration_error_detail.rb b/app/models/integration_error_detail.rb deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/app/services/error_details/base_service.rb b/app/services/error_details/base_service.rb index 2569588efb6..eb2572830cd 100644 --- a/app/services/error_details/base_service.rb +++ b/app/services/error_details/base_service.rb @@ -2,21 +2,23 @@ module ErrorDetails class BaseService < BaseService - def initialize(params:, integration: nil, owner:) + def initialize(params:, owner:, organization:, integration: nil) @params = params @integration = integration @owner = owner + @organization = organization super end def call result.not_found_failure!(resource: 'owner') unless owner + result.not_found_failure!(resource: 'organization') unless organization result end private - attr_reader :params, :integration, :owner + attr_reader :params, :integration, :owner, :organization end end diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb index d2e4a9c8fc5..40a9796bbc4 100644 --- a/app/services/error_details/create_service.rb +++ b/app/services/error_details/create_service.rb @@ -2,8 +2,8 @@ module ErrorDetails class CreateService < BaseService - def initialize(params:, integration: nil, owner:) - super(params:, integration:, owner:) + def initialize(params:, owner:, organization:, integration: nil) + super(params:, integration:, owner:, organization:) end def call @@ -19,14 +19,18 @@ def call private def create_error_details! - new_error = ErrorDetail.create!( + new_error = ErrorDetail.create( integration:, owner:, + organization:, + error_code: params[:error_code], details: params[:details] ) result.error_details = new_error result + rescue ArgumentError => e + result.validation_failure!(errors: e.message) end end end diff --git a/spec/services/error_details/create_service_spec.rb b/spec/services/error_details/create_service_spec.rb index 478c6d21ff2..bfbdd6fb2af 100644 --- a/spec/services/error_details/create_service_spec.rb +++ b/spec/services/error_details/create_service_spec.rb @@ -10,66 +10,95 @@ let(:owner) { create(:invoice, organization:, customer:) } describe '#call' do - subject(:service_call) { described_class.call(params:, integration:, owner:) } + subject(:service_call) { described_class.call(params:, integration:, owner:, organization:) } let(:params) do { + error_code: 'not_provided', details: {'error_code' => 'taxDateTooFarInFuture'} } end - context 'when all both - owner and integration are provided' do - it 'creates an integration_error_detail' do - expect { service_call }.to change(ErrorDetail, :count).by(1) - end + context 'when created succesfully' do + context 'when all - owner, organization and integration are provided' do + it 'creates an error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(1) + end - it 'returns created integration_error_detail' do - result = service_call + it 'returns created error_detail' do + result = service_call - aggregate_failures do - expect(result).to be_success - expect(result.error_details.owner_id).to eq(owner.id) - expect(result.error_details.owner_type).to eq(owner.class.to_s) - expect(result.error_details.integration_id).to eq(integration.id) - expect(result.error_details.integration.class.to_s).to eq(integration.class.to_s) - expect(result.error_details.details).to eq(params[:details]) + aggregate_failures do + expect(result).to be_success + expect(result.error_details.owner_id).to eq(owner.id) + expect(result.error_details.owner_type).to eq(owner.class.to_s) + expect(result.error_details.integration_id).to eq(integration.id) + expect(result.error_details.integration.class.to_s).to eq(integration.class.to_s) + expect(result.error_details.organization_id).to eq(organization.id) + expect(result.error_details.details).to eq(params[:details]) + end end end - end - context 'when no integration association is provided' do - subject(:service_call) { described_class.call(params:, owner:) } + context 'when no integration association is provided' do + subject(:service_call) { described_class.call(params:, owner:, organization:) } - it 'creates an integration_error_detail' do - expect { service_call }.to change(ErrorDetail, :count).by(1) - end + it 'creates an error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(1) + end - it 'returns created integration_error_detail' do - result = service_call + it 'returns created error_detail' do + result = service_call - aggregate_failures do - expect(result).to be_success - expect(result.error_details.owner_id).to eq(owner.id) - expect(result.error_details.owner_type).to eq(owner.class.to_s) - expect(result.error_details.integration_id).to eq(nil) - expect(result.error_details.integration_type).to eq(nil) - expect(result.error_details.details).to eq(params[:details]) + aggregate_failures do + expect(result).to be_success + expect(result.error_details.owner_id).to eq(owner.id) + expect(result.error_details.owner_type).to eq(owner.class.to_s) + expect(result.error_details.integration_id).to eq(nil) + expect(result.error_details.integration_type).to eq(nil) + expect(result.error_details.details).to eq(params[:details]) + end end end end - context 'when no owner is provided' do - subject(:service_call) { described_class.call(params:, integration:, owner: nil) } + context 'when not created succesfully' do + context 'when no owner is provided' do + subject(:service_call) { described_class.call(params:, integration:, owner: nil, organization:) } + + it 'does not create an error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(0) + end - it 'does not create an integration_error_detail' do - expect { service_call }.to change(ErrorDetail, :count).by(0) + it 'returns error for error_detail' do + result = service_call + aggregate_failures do + expect(result.error).to be_a(BaseService::NotFoundFailure) + expect(result.error.message).to include('owner_not_found') + end + end end - it 'returns created integration_error_detail' do - result = service_call - aggregate_failures do - expect(result.error).to be_a(BaseService::NotFoundFailure) - expect(result.error.message).to include('owner_not_found') + context 'when error code is not registered in enum' do + subject(:service_call) { described_class.call(params:, integration:, owner:, organization:) } + + let(:params) do + { + error_code: 'this_error_code_will_never_achieve_its_goal', + details: {'error_code' => 'taxDateTooFarInFuture'} + } + end + + it 'does not create an error_detail' do + expect { service_call }.to change(ErrorDetail, :count).by(0) + end + + it 'returns error for error_detail' do + result = service_call + aggregate_failures do + expect(result.error).to be_a(BaseService::ValidationFailure) + expect(result.error.message).to include("'this_error_code_will_never_achieve_its_goal' is not a valid error_code") + end end end end From 353e474cf5177e8c97a16273f0ee8a84914df575 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 14:45:13 +0200 Subject: [PATCH 21/25] pr review comments --- app/services/error_details/create_service.rb | 12 +++--------- spec/services/error_details/create_service_spec.rb | 1 + 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb index 40a9796bbc4..c3c6f972ff4 100644 --- a/app/services/error_details/create_service.rb +++ b/app/services/error_details/create_service.rb @@ -2,24 +2,18 @@ module ErrorDetails class CreateService < BaseService - def initialize(params:, owner:, organization:, integration: nil) - super(params:, integration:, owner:, organization:) - end def call result = super - return result if result.error - - res = create_error_details! - return res if res&.error + return result unless result.success? - res + create_error_details! end private def create_error_details! - new_error = ErrorDetail.create( + new_error = ErrorDetail.create!( integration:, owner:, organization:, diff --git a/spec/services/error_details/create_service_spec.rb b/spec/services/error_details/create_service_spec.rb index bfbdd6fb2af..2feb2e5ee22 100644 --- a/spec/services/error_details/create_service_spec.rb +++ b/spec/services/error_details/create_service_spec.rb @@ -57,6 +57,7 @@ expect(result.error_details.integration_id).to eq(nil) expect(result.error_details.integration_type).to eq(nil) expect(result.error_details.details).to eq(params[:details]) + expect(result.error_details.error_code).to eq('not_provided') end end end From ada49c745d4b38f03a59772bf2028e12b36213de Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 14:51:17 +0200 Subject: [PATCH 22/25] add record invalid rescue on error details creation --- app/services/error_details/create_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb index c3c6f972ff4..6b4de53727d 100644 --- a/app/services/error_details/create_service.rb +++ b/app/services/error_details/create_service.rb @@ -2,7 +2,6 @@ module ErrorDetails class CreateService < BaseService - def call result = super return result unless result.success? @@ -25,6 +24,8 @@ def create_error_details! result rescue ArgumentError => e result.validation_failure!(errors: e.message) + rescue ActiveRecord::RecordInvalid => e + result.record_validation_failure!(record: e.record) end end end From 0e51768c92554b08e55633b6d6dc9b48fde91e27 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 23 Jul 2024 18:18:30 +0200 Subject: [PATCH 23/25] feat: remove integration form event_detail --- app/services/error_details/base_service.rb | 3 +- app/services/error_details/create_service.rb | 1 - .../error_details/create_service_spec.rb | 35 +++---------------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/app/services/error_details/base_service.rb b/app/services/error_details/base_service.rb index eb2572830cd..627f15e9ea1 100644 --- a/app/services/error_details/base_service.rb +++ b/app/services/error_details/base_service.rb @@ -2,9 +2,8 @@ module ErrorDetails class BaseService < BaseService - def initialize(params:, owner:, organization:, integration: nil) + def initialize(params:, owner:, organization:) @params = params - @integration = integration @owner = owner @organization = organization diff --git a/app/services/error_details/create_service.rb b/app/services/error_details/create_service.rb index 6b4de53727d..951d96b6800 100644 --- a/app/services/error_details/create_service.rb +++ b/app/services/error_details/create_service.rb @@ -13,7 +13,6 @@ def call def create_error_details! new_error = ErrorDetail.create!( - integration:, owner:, organization:, error_code: params[:error_code], diff --git a/spec/services/error_details/create_service_spec.rb b/spec/services/error_details/create_service_spec.rb index 2feb2e5ee22..bd39a5b754f 100644 --- a/spec/services/error_details/create_service_spec.rb +++ b/spec/services/error_details/create_service_spec.rb @@ -6,11 +6,10 @@ let(:membership) { create(:membership) } let(:organization) { membership.organization } let(:customer) { create(:customer, organization:) } - let(:integration) { create(:anrok_integration, organization:) } let(:owner) { create(:invoice, organization:, customer:) } describe '#call' do - subject(:service_call) { described_class.call(params:, integration:, owner:, organization:) } + subject(:service_call) { described_class.call(params:, owner:, organization:) } let(:params) do { @@ -20,7 +19,7 @@ end context 'when created succesfully' do - context 'when all - owner, organization and integration are provided' do + context 'when all - owner and organization are provided' do it 'creates an error_detail' do expect { service_call }.to change(ErrorDetail, :count).by(1) end @@ -32,40 +31,16 @@ expect(result).to be_success expect(result.error_details.owner_id).to eq(owner.id) expect(result.error_details.owner_type).to eq(owner.class.to_s) - expect(result.error_details.integration_id).to eq(integration.id) - expect(result.error_details.integration.class.to_s).to eq(integration.class.to_s) expect(result.error_details.organization_id).to eq(organization.id) expect(result.error_details.details).to eq(params[:details]) end end end - - context 'when no integration association is provided' do - subject(:service_call) { described_class.call(params:, owner:, organization:) } - - it 'creates an error_detail' do - expect { service_call }.to change(ErrorDetail, :count).by(1) - end - - it 'returns created error_detail' do - result = service_call - - aggregate_failures do - expect(result).to be_success - expect(result.error_details.owner_id).to eq(owner.id) - expect(result.error_details.owner_type).to eq(owner.class.to_s) - expect(result.error_details.integration_id).to eq(nil) - expect(result.error_details.integration_type).to eq(nil) - expect(result.error_details.details).to eq(params[:details]) - expect(result.error_details.error_code).to eq('not_provided') - end - end - end end context 'when not created succesfully' do context 'when no owner is provided' do - subject(:service_call) { described_class.call(params:, integration:, owner: nil, organization:) } + subject(:service_call) { described_class.call(params:, organization:, owner: nil) } it 'does not create an error_detail' do expect { service_call }.to change(ErrorDetail, :count).by(0) @@ -81,12 +56,12 @@ end context 'when error code is not registered in enum' do - subject(:service_call) { described_class.call(params:, integration:, owner:, organization:) } + subject(:service_call) { described_class.call(params:, owner:, organization:) } let(:params) do { error_code: 'this_error_code_will_never_achieve_its_goal', - details: {'error_code' => 'taxDateTooFarInFuture'} + details: {'error_received' => 'taxDateTooFarInFuture'} } end From 3154c9e153edf1d86676fb9103cd98af4f7d9a4c Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 24 Jul 2024 13:33:32 +0200 Subject: [PATCH 24/25] remove integration from attr reader for base error_detail service --- app/services/error_details/base_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/error_details/base_service.rb b/app/services/error_details/base_service.rb index 627f15e9ea1..59aba5f4e20 100644 --- a/app/services/error_details/base_service.rb +++ b/app/services/error_details/base_service.rb @@ -18,6 +18,6 @@ def call private - attr_reader :params, :integration, :owner, :organization + attr_reader :params, :owner, :organization end end From 5df6e767e652c4fa4fb4b773e8a388a25ef3c32c Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 24 Jul 2024 16:27:08 +0200 Subject: [PATCH 25/25] remove accidentally added check on integration_error_details relation --- spec/models/invoice_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 496ba42769d..6d230e0d8fb 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -18,8 +18,6 @@ expect(described_class::STATUS).to match(draft: 0, finalized: 1, voided: 2, generating: 3, failed: 4, open: 5) end - it { is_expected.to have_many(:integration_error_details) } - describe 'validation' do describe 'of payment dispute lost absence' do context 'when invoice is not voided' do