Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add models and unit test #16320

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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/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
Expand Down Expand Up @@ -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/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
Expand Down Expand Up @@ -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/va-api-engineers @department-of-veterans-affairs/backend-review-group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add your github team as reviewers. Which team will be responsible for these files? If you don't have a team, pleas create one. https://github.com/orgs/department-of-veterans-affairs/teams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmtolmach I see @department-of-veterans-affairs/champva-engineering in our github teams but in CODEOWNERS, its not recognized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmtolmach Can you help out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I've added champva-engineering to the vets-api repo as collaborators with write access so the warnings are gone 👍

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
Expand Down
24 changes: 24 additions & 0 deletions app/models/pega_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class PegaTable < ApplicationRecord
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the file name and model to just be "Pega" to match the format of other models? @cloudmagic80

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe PegaData for a bit more clarity since we are storing the response in there right?

# 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
21 changes: 21 additions & 0 deletions spec/factories/pega_tables.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions spec/models/pega_table_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading