-
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
Closed
Closed
add models and unit test #16320
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b2fc433
add models and unit test
cloudmagic80 a05453c
linting
cloudmagic80 8552d7e
linting rubocop down
cloudmagic80 3f58f4c
linting
cloudmagic80 537e00c
lint
cloudmagic80 b245977
lint
cloudmagic80 6c56205
lint
cloudmagic80 0803971
Merge branch 'master' into ivc_database_models2
rmtolmach 27d56f9
add codeowners
cloudmagic80 c56c58c
codeowner updadte
cloudmagic80 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 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?