-
-
Notifications
You must be signed in to change notification settings - Fork 577
Picklists should be filterable + regression testing #5397
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90cd35b
allow printing only filtered picklists
joepaolicelli 9bb76c5
test for correct unfulfilled picklists button count when filtered
joepaolicelli d31bdb3
fix issues with picklists filtering test
joepaolicelli b2e5ac8
Fix consistent naming
jonny5 72cc26b
Add regression test for Picklist pdf generation
jonny5 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ module PDFComparisonTestFactory | |
| extend ActiveSupport::Testing::TimeHelpers | ||
|
|
||
| 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, :expected_no_contact_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, :expected_picklist_file_path) | ||
|
|
||
| def self.get_logo_file | ||
| Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/files/logo.jpg"), "image/jpeg") | ||
|
|
@@ -41,17 +41,30 @@ def self.create_partner(organization) | |
| Partner.create!(name: "Leslie Sue", organization: organization, email: "leslie1@gmail.com") | ||
| end | ||
|
|
||
| def self.create_partner_with_quota(organization) | ||
| Partner.create!(name: "Leslie Sue", organization: organization, email: "leslie1@gmail.com", quota: 100) | ||
| end | ||
|
|
||
| def self.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") | ||
| 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) | ||
| expected_picklist_file_path = Rails.root.join("spec", "fixtures", "files", "picklist.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, | ||
| expected_picklist_file_path | ||
| ) | ||
| end | ||
|
|
||
| private_class_method def self.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", primary_contact_name: "Jaqueline Kihn DDS", primary_contact_email: "van@durgan.example") | ||
| address1: "Example Address 1", city: "Example City", state: "Example State", zip: "12345", primary_contact_name: "Jaqueline Kihn DDS", primary_contact_email: "van@durgan.example", pick_up_name: nil, pick_up_email: nil, pick_up_phone: nil) | ||
| Partners::Profile.create!( | ||
| partner_id: partner.id, | ||
| essentials_bank_id: partner.organization.id, | ||
|
|
@@ -66,7 +79,10 @@ def self.get_file_paths | |
| program_address2: program_address2, | ||
| program_city: program_city, | ||
| program_state: program_state, | ||
| program_zip_code: program_zip | ||
| program_zip_code: program_zip, | ||
| pick_up_name: pick_up_name, | ||
| pick_up_email: pick_up_email, | ||
| pick_up_phone: pick_up_phone | ||
| ) | ||
| end | ||
|
|
||
|
|
@@ -90,9 +106,26 @@ def self.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 self.create_line_items_request(distribution, partner, storage_creation) | ||
| def self.create_profile_with_pickup_person(partner) | ||
| create_profile( | ||
| partner: partner, | ||
| pick_up_name: "Pickup Person", | ||
| pick_up_email: "pickup@example.com", | ||
| pick_up_phone: "1234567890", | ||
| program_address1: "Example Program Address 1", | ||
| program_address2: "", | ||
| program_city: "Example Program City", | ||
| program_state: "Example Program State", | ||
| program_zip: 54321 | ||
| ) | ||
| end | ||
|
|
||
| def self.create_line_items_for_distribution(distribution, storage_creation) | ||
| LineItem.create!(itemizable: distribution, item: storage_creation.items[0], quantity: 50) | ||
| LineItem.create!(itemizable: distribution, item: storage_creation.items[1], quantity: 100) | ||
| end | ||
|
|
||
| def self.create_line_items_request(partner:, storage_creation:, distribution: nil) | ||
| 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) | ||
|
|
@@ -107,30 +140,48 @@ def self.create_line_items_request(distribution, partner, storage_creation) | |
| {"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] | ||
| item_requests: [req1, req2, req3], | ||
| created_at: Time.zone.local(2024, 12, 30, 0, 0, 0) | ||
| ) | ||
| end | ||
|
|
||
| def self.create_dist(partner, storage_creation, delivery_method) | ||
| Time.zone = "America/Los_Angeles" | ||
| dist = Distribution.create!(id: 123, 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) | ||
| create_line_items_for_distribution(dist, storage_creation) | ||
| create_line_items_request(distribution: dist, partner: partner, storage_creation: storage_creation) | ||
| dist | ||
| end | ||
|
|
||
| def self.render_pdf_at_year_end(organization, distribution) | ||
| def self.render_distribution_pdf_at_year_end(organization, distribution) | ||
| travel_to(Time.zone.local(2024, 12, 30, 0, 0, 0)) do | ||
| return DistributionPdf.new(organization, distribution).compute_and_render | ||
| end | ||
| end | ||
|
|
||
| private_class_method def self.create_comparison_pdf(storage_creation, profile_create_method, expected_file_path, delivery_method) | ||
| def self.render_picklist_pdf(organization, requests) | ||
| PicklistsPdf.new(organization, requests).compute_and_render | ||
| end | ||
|
|
||
| private_class_method def self.create_distribution_comparison_pdf(storage_creation, profile_create_method, expected_file_path, delivery_method) | ||
| # Partner creation must be rolled back otherwise Items requested YTD will accumulate | ||
| ActiveRecord::Base.transaction(requires_new: true) do | ||
| partner = create_partner(storage_creation.organization) | ||
| PDFComparisonTestFactory.public_send(profile_create_method, partner) | ||
| dist = create_dist(partner, storage_creation, delivery_method) | ||
| pdf_file = render_pdf_at_year_end(storage_creation.organization, dist) | ||
| pdf_file = render_distribution_pdf_at_year_end(storage_creation.organization, dist) | ||
| File.binwrite(expected_file_path, pdf_file) | ||
| raise ActiveRecord::Rollback | ||
| end | ||
| end | ||
|
|
||
| private_class_method def self.create_picklist_comparison_pdf(storage_creation, partner_create_method, profile_create_method, expected_file_path) | ||
| # Partner creation must be rolled back otherwise Items requested YTD will accumulate | ||
| ActiveRecord::Base.transaction(requires_new: true) do | ||
| partner = PDFComparisonTestFactory.public_send(partner_create_method, storage_creation.organization) | ||
| PDFComparisonTestFactory.public_send(profile_create_method, partner) | ||
| request = create_line_items_request(partner: partner, storage_creation: storage_creation) | ||
| pdf_file = render_picklist_pdf(storage_creation.organization, [request]) | ||
| File.binwrite(expected_file_path, pdf_file) | ||
| raise ActiveRecord::Rollback | ||
| end | ||
|
|
@@ -151,11 +202,13 @@ def self.create_comparison_pdfs | |
| ActiveRecord::Base.transaction do | ||
| storage_creation = create_organization_storage_items(logo) | ||
|
|
||
| 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) | ||
| create_distribution_comparison_pdf(storage_creation, :create_profile_no_address, file_paths.expected_pickup_file_path, :pick_up) | ||
| create_distribution_comparison_pdf(storage_creation, :create_profile_without_program_address, file_paths.expected_same_address_file_path, :shipped) | ||
| create_distribution_comparison_pdf(storage_creation, :create_profile_with_program_address, file_paths.expected_different_address_file_path, :delivery) | ||
| create_distribution_comparison_pdf(storage_creation, :create_profile_with_incomplete_address, file_paths.expected_incomplete_address_file_path, :delivery) | ||
| create_distribution_comparison_pdf(storage_creation, :create_profile_no_contact_with_program_address, file_paths.expected_no_contact_file_path, :delivery) | ||
|
|
||
| create_picklist_comparison_pdf(storage_creation, :create_partner_with_quota, :create_profile_with_pickup_person, file_paths.expected_picklist_file_path) | ||
|
Collaborator
Author
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. Added one PDF with relevant header data, I didn't see so much conditionality in the pdf that it would vary greatly |
||
|
|
||
| raise ActiveRecord::Rollback | ||
| end | ||
|
|
||
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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
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.
I resisted refactoring this class too much and just renamed the relevant places to scope to distribution/picklist