diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 821318c752c..54bf4e03375 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -276,6 +276,7 @@ app/models/mpi_data.rb @department-of-veterans-affairs/octo-identity app/models/old_email.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/onsite_notification.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/payment_history.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers +app/models/pega_table.rb @department-of-veterans-affairs/champva-engineering @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/persistent_attachment.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/pensions @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/persistent_attachments/dependency_claim.rb @department-of-veterans-affairs/benefits-dependents-management @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/persistent_attachments/lgy_claim.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -1103,6 +1104,7 @@ spec/factories/nca_facilities.rb @department-of-veterans-affairs/vfs-facilities- spec/factories/onsite_notifications.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/factories/organizations.rb @department-of-veterans-affairs/accredited-representation-management @department-of-veterans-affairs/backend-review-group spec/factories/pagerduty_services.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +spec/factories/pega_tables.rb @department-of-veterans-affairs/champva-engineering @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/factories/pension_claim.rb @department-of-veterans-affairs/pensions @department-of-veterans-affairs/backend-review-group spec/factories/persistent_attachments @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/pensions @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/factories/ppiu_payment_account.rb @department-of-veterans-affairs/vfs-health-modernization-initiative @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -1441,6 +1443,7 @@ spec/models/message_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messa spec/models/mhv_opt_in_flag_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/mpi_data_spec.rb @department-of-veterans-affairs/octo-identity spec/models/onsite_notification_spec.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +spec/models/pega_table_spec.rb @department-of-veterans-affairs/champva-engineering @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/persistent_attachments @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/pensions @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/preneeds @department-of-veterans-affairs/mbs-core-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/prescription_spec.rb @department-of-veterans-affairs/vfs-mhv-medications @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group diff --git a/app/models/pega_table.rb b/app/models/pega_table.rb new file mode 100644 index 00000000000..49c6ab86321 --- /dev/null +++ b/app/models/pega_table.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class PegaTable < ApplicationRecord + # Validate presence of essential fields + validates :uuid, presence: true + validates :veteranfirstname, presence: true + validates :veteranlastname, presence: true + validates :response, presence: true + + validate :validate_response_format + + private + + def validate_response_format + return if response.blank? + + response_hash = JSON.parse(response) + unless response_hash['status'].present? && [200, 403, 500].include?(response_hash['status'].to_i) + errors.add(:response, 'must contain a valid HTTP status code (200, 403, 500)') + end + rescue JSON::ParserError + errors.add(:response, 'must be a valid JSON format') + end +end diff --git a/spec/factories/pega_tables.rb b/spec/factories/pega_tables.rb new file mode 100644 index 00000000000..4020ad74c5e --- /dev/null +++ b/spec/factories/pega_tables.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :pega_table do + uuid { 'c47bec59-02c7-43e4-a0f7-acf287a32a97' } + veteranfirstname { 'John' } + veteranlastname { 'Doe' } + + trait :with_valid_response do + response { '{"status": 200}' } + end + + trait :with_invalid_response do + response { '{"status": 400}' } + end + + trait :with_invalid_json_response do + response { 'invalid_json' } + end + end +end diff --git a/spec/models/pega_table_spec.rb b/spec/models/pega_table_spec.rb new file mode 100644 index 00000000000..59cd84513d9 --- /dev/null +++ b/spec/models/pega_table_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe PegaTable, type: :model do + describe 'validations' do + it { is_expected.to validate_presence_of(:uuid) } + it { is_expected.to validate_presence_of(:veteranfirstname) } + it { is_expected.to validate_presence_of(:veteranlastname) } + it { is_expected.to validate_presence_of(:response) } + + context 'custom validations' do + it 'ensures response contains a valid HTTP status code' do + # Test case for valid status code (200) + pega_table = build(:pega_table, :with_valid_response) + expect(pega_table).to be_valid + + # Test case for invalid status code (400) + pega_table = build(:pega_table, :with_invalid_response) + pega_table.valid? + expect(pega_table.errors[:response]).to include('must contain a valid HTTP status code (200, 403, 500)') + + # Test case for invalid JSON format + pega_table = build(:pega_table, :with_invalid_json_response) + pega_table.valid? + expect(pega_table.errors[:response]).to include('must be a valid JSON format') + end + end + end +end