Skip to content

Commit

Permalink
Use order and add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Aug 20, 2024
1 parent f12984f commit 427666d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/domain/people/data_quality_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def initialize(person)
check("error", "first_name", "ist leer", invalid: @person.first_name.blank?)
check("error", "last_name", "ist leer", invalid: @person.last_name.blank?)
end

highest_severity = @person.data_quality_issues.order(severity: :desc).first&.severity
@person.update!(data_quality: highest_severity || "ok")
end

private
Expand Down
12 changes: 10 additions & 2 deletions spec/models/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,15 @@ def create_role(**attrs)
person.update!(company_name: nil, first_name: nil)
end.to change(person.data_quality_issues, :count).by(1)
expect(person.data_quality_issues.first.message).to eq("Vorname ist leer")
expect(person.data_quality).to eq("error")
end

it "validates the last name" do
expect do
person.update!(company_name: nil, last_name: nil)
end.to change(person.data_quality_issues, :count).by(1)
expect(person.data_quality_issues.first.message).to eq("Nachname ist leer")
expect(person.data_quality).to eq("error")
end
end

Expand All @@ -317,10 +319,14 @@ def create_role(**attrs)
person.update!(birthday: nil)
end.to change(person.data_quality_issues, :count).by(1)
expect(person.data_quality_issues.first.message).to eq("Geburtstag ist leer")
expect(person.data_quality).to eq("error")

person.update!(birthday: Time.zone.today)
expect do
person.update!(birthday: Time.zone.today)
end.not_to change(person.data_quality_issues, :count)
expect(person.data_quality_issues.first.message)
.to eq("Geburtstag liegt weniger als 6 Jahre vor dem SAC-Eintritt")
expect(person.data_quality).to eq("warning")
end

it "validates the street, zip_code, and town" do
Expand All @@ -329,6 +335,7 @@ def create_role(**attrs)
end.to change(person.data_quality_issues, :count).by(3)
expect(person.data_quality_issues.map(&:message))
.to include("Strasse ist leer", "PLZ ist leer", "Ort ist leer")
expect(person.data_quality).to eq("error")
end

it "validates the email and phone_numbers" do
Expand All @@ -337,7 +344,8 @@ def create_role(**attrs)
person.update!(email: nil)
end.to change(person.data_quality_issues, :count).by(2)
expect(person.data_quality_issues.map(&:message))
.to include("Haupt-E-Mail ist leer", "Telefonnummern sind leer")
.to include("Telefonnummern sind leer", "Haupt-E-Mail ist leer")
expect(person.data_quality).to eq("warning")
end
end
end
Expand Down

0 comments on commit 427666d

Please sign in to comment.