-
Notifications
You must be signed in to change notification settings - Fork 66
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
add models and unit test #16320
Changes from 9 commits
b2fc433
a05453c
8552d7e
3f58f4c
537e00c
b245977
6c56205
0803971
27d56f9
c56c58c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class PegaTable < ApplicationRecord | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍