-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Fix #4138 fix delivery address #4540
Open
jimmyli97
wants to merge
23
commits into
rubyforgood:main
Choose a base branch
from
jimmyli97:4138-fix-delivery-address
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4bb8332
REFACTOR group examples, remove rubocop disable lines,
jimmyli97 77b2a55
RED add rspec to test address output in distribution PDFs
jimmyli97 dcdc0f8
GREEN Fix #4138 address output changes based on delivery method
jimmyli97 aa38b4b
BUGFIX pdf now writes when test fails
jimmyli97 f1d7273
RED add rspec for when partner has no addresses
jimmyli97 d64acc4
GREEN don't print address if no address or delivery address
jimmyli97 4557128
Merge branch 'main' into 4138-fix-delivery-address
jimmyli97 0d53723
Add comments clarifying gitignore and comparison pdf helper rspec
jimmyli97 d722bca
Update bundler version
jimmyli97 4516951
REFACTOR replace helper test with environment variable
jimmyli97 ee159ab
Merge branch 'main' into 4138-fix-delivery-address
jimmyli97 cec74ce
Merge branch 'main' into 4138-fix-delivery-address
jimmyli97 c26f94b
update schema date and bundler version
jimmyli97 df4b975
RED remove env variable code, stub out console helper method
jimmyli97 26ece6e
GREEN add Rails console method for generating comparison pdfs, update…
jimmyli97 a21c7f2
Merge branch 'main' into 4138-fix-delivery-address
jimmyli97 6da7702
Replace instance vars with structs and let
jimmyli97 8bc117e
FIX destroy request so db is clean, use destroy! instead so exception…
jimmyli97 ea7e241
Replace FactoryBot with calling ActiveModel.create, move methods to lib/
jimmyli97 39e8cb4
Fix formatting when address is incomplete, add rspecs, create and del…
jimmyli97 29e59df
Merge branch 'main' into 4138-fix-delivery-address
jimmyli97 4c6cd65
FIX replace with space if partner primary contact name/email/phone is…
jimmyli97 b00d1b0
FIX spacing between issued to and delivery address
jimmyli97 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
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
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,140 @@ | ||
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) | ||
|
||
def create_organization_storage_items | ||
org = Organization.create!( | ||
name: "Essentials Bank 1", | ||
short_name: "db", | ||
street: "1500 Remount Road", | ||
city: "Front Royal", | ||
state: "VA", | ||
zipcode: "22630", | ||
email: "[email protected]", | ||
logo: Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/files/logo.jpg"), "image/jpeg") | ||
) | ||
|
||
storage_location = StorageLocation.create!( | ||
name: "Smithsonian Conservation Center", | ||
address: "1500 Remount Road, Front Royal, VA 22630", | ||
organization: org | ||
) | ||
|
||
base_item = BaseItem.find_or_create_by!(name: "10T Diapers", partner_key: "10t_diapers") | ||
|
||
item1 = Item.create!(name: "Item 1", package_size: 50, value_in_cents: 100, organization: org, partner_key: base_item.partner_key) | ||
item2 = Item.create!(name: "Item 2", value_in_cents: 200, organization: org, partner_key: base_item.partner_key) | ||
item3 = Item.create!(name: "Item 3", value_in_cents: 300, organization: org, partner_key: base_item.partner_key) | ||
item4 = Item.create!(name: "Item 4", package_size: 25, value_in_cents: 400, organization: org, partner_key: base_item.partner_key) | ||
|
||
StorageCreation.new(org, storage_location, [item1, item2, item3, item4]) | ||
end | ||
|
||
def create_partner(organization) | ||
Partner.create!(name: "Leslie Sue", organization: organization, email: "[email protected]") | ||
end | ||
|
||
def get_file_paths | ||
expected_pickup_file_path = Rails.root.join("spec", "fixtures", "files", "distribution_pickup.pdf") | ||
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) | ||
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") | ||
|
||
Partners::Profile.create!( | ||
partner_id: partner.id, | ||
essentials_bank_id: partner.organization.id, | ||
primary_contact_name: "Jaqueline Kihn DDS", | ||
primary_contact_email: "[email protected]", | ||
address1: address1, | ||
address2: "", | ||
city: city, | ||
state: state, | ||
zip_code: zip, | ||
program_address1: program_address1, | ||
program_address2: program_address2, | ||
program_city: program_city, | ||
program_state: program_state, | ||
program_zip_code: program_zip | ||
) | ||
end | ||
|
||
def create_profile_no_address(partner) | ||
create_profile(partner: partner, program_address1: "", program_address2: "", program_city: "", program_state: "", program_zip: "", address1: "", city: "", state: "", zip: "") | ||
end | ||
|
||
def create_profile_without_program_address(partner) | ||
create_profile(partner: partner, program_address1: "", program_address2: "", program_city: "", program_state: "", program_zip: "") | ||
end | ||
|
||
def create_profile_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) | ||
end | ||
|
||
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_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) | ||
storage_creation.organization.request_units.find_or_create_by!(name: "pack") | ||
ItemUnit.find_or_create_by!(item: storage_creation.items[3], name: "pack") | ||
req1 = Partners::ItemRequest.new(item: storage_creation.items[1], quantity: 30, name: storage_creation.items[1].name, partner_key: storage_creation.items[1].partner_key) | ||
req2 = Partners::ItemRequest.new(item: storage_creation.items[2], quantity: 50, name: storage_creation.items[2].name, partner_key: storage_creation.items[2].partner_key) | ||
req3 = Partners::ItemRequest.new(item: storage_creation.items[3], quantity: 120, name: storage_creation.items[3].name, partner_key: storage_creation.items[3].partner_key, request_unit: "pack") | ||
Request.create!( | ||
organization: storage_creation.organization, | ||
partner: partner, | ||
distribution: distribution, | ||
request_items: [ | ||
{"item_id" => storage_creation.items[1].id, "quantity" => 30}, | ||
{"item_id" => storage_creation.items[2].id, "quantity" => 50}, | ||
{"item_id" => storage_creation.items[3].id, "quantity" => 120, "request_unit" => "pack"} | ||
], | ||
item_requests: [req1, req2, req3] | ||
) | ||
end | ||
|
||
def create_dist(partner, storage_creation, delivery_method) | ||
Time.zone = "America/Los_Angeles" | ||
dist = Distribution.create!(partner: partner, delivery_method: delivery_method, issued_at: DateTime.new(2024, 7, 4, 0, 0, 0, "-07:00"), organization: storage_creation.organization, storage_location: storage_creation.storage_location) | ||
create_line_items_request(dist, partner, storage_creation) | ||
dist | ||
end | ||
|
||
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) | ||
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) | ||
profile.destroy! | ||
dist.request.destroy! | ||
dist.destroy! | ||
partner.destroy! | ||
end | ||
|
||
# helper function that can be called from Rails console to generate comparison PDFs | ||
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) | ||
|
||
storage_creation.storage_location.destroy! | ||
storage_creation.items[0].destroy! | ||
storage_creation.items[1].destroy! | ||
storage_creation.items[2].destroy! | ||
storage_creation.items[3].request_units.destroy_all | ||
storage_creation.items[3].destroy! | ||
storage_creation.organization.destroy! | ||
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. I guess the transaction/rollback can be moved to this method. |
||
end | ||
end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
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.
Probably better to just wrap this in a transaction and roll it back (i.e. raise an
ActiveRecord::Rollback
) rather than manually callingdestroy
.