Skip to content

Commit

Permalink
FIX replace with space if partner primary contact name/email/phone is…
Browse files Browse the repository at this point in the history
… blank

* Add rspec
* Other comparison pdfs change because previously blank phone # skipped line,
  now blank phone # adds a blank line
* Move instance_method call inside function
  • Loading branch information
jimmyli97 committed Dec 3, 2024
1 parent 29e59df commit 4c6cd65
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/pdfs/distribution_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def compute_and_render

text "Partner Primary Contact:", style: :bold, align: :right
font_size 12
text profile.primary_contact_name, align: :right
text (profile.primary_contact_name.presence || " "), align: :right
font_size 10
text profile.primary_contact_email, align: :right
text profile.primary_contact_phone, align: :right
text (profile.primary_contact_email.presence || " "), align: :right
text (profile.primary_contact_phone.presence || " "), align: :right

if (profile.address1.present? || profile.program_address1.present?) &&
(@distribution.delivery? || @distribution.shipped?)
Expand Down
26 changes: 16 additions & 10 deletions lib/test_helpers/pdf_comparison_test_factory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module PDFComparisonTestFactory
StorageCreation = Data.define(:organization, :storage_location, :items)
FilePaths = Data.define(:expected_pickup_file_path, :expected_same_address_file_path, :expected_different_address_file_path, :expected_incomplete_address_file_path)
FilePaths = Data.define(:expected_pickup_file_path, :expected_same_address_file_path, :expected_different_address_file_path, :expected_incomplete_address_file_path, :expected_no_contact_file_path)

def create_organization_storage_items
org = Organization.create!(
Expand Down Expand Up @@ -39,17 +39,18 @@ def get_file_paths
expected_same_address_file_path = Rails.root.join("spec", "fixtures", "files", "distribution_same_address.pdf")
expected_different_address_file_path = Rails.root.join("spec", "fixtures", "files", "distribution_program_address.pdf")
expected_incomplete_address_file_path = Rails.root.join("spec", "fixtures", "files", "distribution_incomplete_address.pdf")
FilePaths.new(expected_pickup_file_path, expected_same_address_file_path, expected_different_address_file_path, expected_incomplete_address_file_path)
expected_no_contact_file_path = Rails.root.join("spec", "fixtures", "files", "distribution_no_contact.pdf")
FilePaths.new(expected_pickup_file_path, expected_same_address_file_path, expected_different_address_file_path, expected_incomplete_address_file_path, expected_no_contact_file_path)
end

private def create_profile(partner:, program_address1:, program_address2:, program_city:, program_state:, program_zip:,
address1: "Example Address 1", city: "Example City", state: "Example State", zip: "12345")
address1: "Example Address 1", city: "Example City", state: "Example State", zip: "12345", primary_contact_name: "Jaqueline Kihn DDS", primary_contact_email: "[email protected]")

Partners::Profile.create!(
partner_id: partner.id,
essentials_bank_id: partner.organization.id,
primary_contact_name: "Jaqueline Kihn DDS",
primary_contact_email: "[email protected]",
primary_contact_name: primary_contact_name,
primary_contact_email: primary_contact_email,
address1: address1,
address2: "",
city: city,
Expand Down Expand Up @@ -79,6 +80,10 @@ def create_profile_with_incomplete_address(partner)
create_profile(partner: partner, program_address1: "Example Program Address 1", program_address2: "", program_city: "", program_state: "", program_zip: "")
end

def create_profile_no_contact_with_program_address(partner)
create_profile(partner: partner, program_address1: "Example Program Address 1", program_address2: "", program_city: "Example Program City", program_state: "Example Program State", program_zip: 54321, primary_contact_name: "", primary_contact_email: "")
end

def create_line_items_request(distribution, partner, storage_creation)
LineItem.create!(itemizable: distribution, item: storage_creation.items[0], quantity: 50)
LineItem.create!(itemizable: distribution, item: storage_creation.items[1], quantity: 100)
Expand Down Expand Up @@ -109,7 +114,7 @@ def create_dist(partner, storage_creation, delivery_method)

private def create_comparison_pdf(storage_creation, profile_create_method, expected_file_path, delivery_method)
partner = create_partner(storage_creation.organization)
profile = profile_create_method.bind_call(Class.new.extend(PDFComparisonTestFactory), partner)
profile = PDFComparisonTestFactory.instance_method(profile_create_method).bind_call(Class.new.extend(PDFComparisonTestFactory), partner)
dist = create_dist(partner, storage_creation, delivery_method)
pdf_file = DistributionPdf.new(storage_creation.organization, dist).compute_and_render
File.binwrite(expected_file_path, pdf_file)
Expand All @@ -124,10 +129,11 @@ def create_comparison_pdfs
storage_creation = create_organization_storage_items
file_paths = get_file_paths

create_comparison_pdf(storage_creation, PDFComparisonTestFactory.instance_method(:create_profile_no_address), file_paths.expected_pickup_file_path, :pick_up)
create_comparison_pdf(storage_creation, PDFComparisonTestFactory.instance_method(:create_profile_without_program_address), file_paths.expected_same_address_file_path, :shipped)
create_comparison_pdf(storage_creation, PDFComparisonTestFactory.instance_method(:create_profile_with_program_address), file_paths.expected_different_address_file_path, :delivery)
create_comparison_pdf(storage_creation, PDFComparisonTestFactory.instance_method(:create_profile_with_incomplete_address), file_paths.expected_incomplete_address_file_path, :delivery)
create_comparison_pdf(storage_creation, :create_profile_no_address, file_paths.expected_pickup_file_path, :pick_up)
create_comparison_pdf(storage_creation, :create_profile_without_program_address, file_paths.expected_same_address_file_path, :shipped)
create_comparison_pdf(storage_creation, :create_profile_with_program_address, file_paths.expected_different_address_file_path, :delivery)
create_comparison_pdf(storage_creation, :create_profile_with_incomplete_address, file_paths.expected_incomplete_address_file_path, :delivery)
create_comparison_pdf(storage_creation, :create_profile_no_contact_with_program_address, file_paths.expected_no_contact_file_path, :delivery)

storage_creation.storage_location.destroy!
storage_creation.items[0].destroy!
Expand Down
Binary file modified spec/fixtures/files/distribution_incomplete_address.pdf
Binary file not shown.
Binary file not shown.
Binary file modified spec/fixtures/files/distribution_pickup.pdf
Binary file not shown.
Binary file modified spec/fixtures/files/distribution_program_address.pdf
Binary file not shown.
Binary file modified spec/fixtures/files/distribution_same_address.pdf
Binary file not shown.
13 changes: 8 additions & 5 deletions spec/pdfs/distribution_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
let(:expected_pickup_file_path) { file_paths.expected_pickup_file_path }
let(:expected_same_address_file_path) { file_paths.expected_same_address_file_path }
let(:expected_incomplete_address_file_path) { file_paths.expected_incomplete_address_file_path }
let(:expected_no_contact_file_path) { file_paths.expected_no_contact_file_path }

context "when the partner has no addresses" do
before(:each) do
Expand Down Expand Up @@ -186,11 +187,13 @@
compare_pdf(organization, create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path)
end
end
context "when the partner delivery address is incomplete" do
it "formats output correctly" do
create_profile_with_incomplete_address(partner)
compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_incomplete_address_file_path)
end
it "formats output correctly when the partner delivery address is incomplete" do
create_profile_with_incomplete_address(partner)
compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_incomplete_address_file_path)
end
it "formats output correctly when the partner profile contact info does not exist" do
create_profile_no_contact_with_program_address(partner)
compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_no_contact_file_path)
end
end
end

0 comments on commit 4c6cd65

Please sign in to comment.