Skip to content

Commit

Permalink
Add test for tube purpose validation of GenerateSampleManifest UAT ac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
yoldas committed Jan 14, 2025
1 parent 89c9f88 commit c0c17aa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/uat_actions/uat_actions/generate_sample_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class UatActions::GenerateSampleManifest < UatActions
self.description = 'Generate sample manifest with the provided information.'
self.category = :generating_samples

ERROR_TUBE_PURPOSE_DOES_NOT_EXIST = "Tube purpose '%s' does not exist."

form_field :study_name,
:select,
label: 'Study Name',
Expand Down Expand Up @@ -41,6 +43,8 @@ class UatActions::GenerateSampleManifest < UatActions

form_field :with_samples, :check_box, help: 'Create new samples for recipients?', label: 'With Samples?'

validate :validate_tube_purpose_exists

def self.default
new(
study_name: UatActions::StaticRecords.study.name,
Expand All @@ -59,6 +63,17 @@ def perform
true
end

# Validates that the tube purpose exists for the selected tube purpose name.
#
# @return [void]
def validate_tube_purpose_exists
return if tube_purpose_name.blank? # Uses the default.
return if Tube::Purpose.exists?(name: tube_purpose_name)

message = format(ERROR_TUBE_PURPOSE_DOES_NOT_EXIST, tube_purpose_name)
errors.add(:tube_purpose_name, message)
end

def create_sample_manifest
SampleManifest.create!(study:, supplier:, asset_type:, count:, purpose:)
end
Expand Down

0 comments on commit c0c17aa

Please sign in to comment.