@@ -4,7 +4,7 @@ module PDFComparisonTestFactory
44 extend ActiveSupport ::Testing ::TimeHelpers
55
66 StorageCreation = Data . define ( :organization , :storage_location , :items )
7- 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 )
7+ 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 )
88
99 def self . get_logo_file
1010 Rack ::Test ::UploadedFile . new ( Rails . root . join ( "spec/fixtures/files/logo.jpg" ) , "image/jpeg" )
@@ -42,17 +42,30 @@ def self.create_partner(organization)
4242 Partner . create! ( name : "Leslie Sue" , organization : organization , email : "leslie1@gmail.com" )
4343 end
4444
45+ def self . create_partner_with_quota ( organization )
46+ Partner . create! ( name : "Leslie Sue" , organization : organization , email : "leslie1@gmail.com" , quota : 100 )
47+ end
48+
4549 def self . get_file_paths
4650 expected_pickup_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_pickup.pdf" )
4751 expected_same_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_same_address.pdf" )
4852 expected_different_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_program_address.pdf" )
4953 expected_incomplete_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_incomplete_address.pdf" )
5054 expected_no_contact_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_no_contact.pdf" )
51- 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 )
55+ expected_picklist_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "picklist.pdf" )
56+
57+ FilePaths . new (
58+ expected_pickup_file_path ,
59+ expected_same_address_file_path ,
60+ expected_different_address_file_path ,
61+ expected_incomplete_address_file_path ,
62+ expected_no_contact_file_path ,
63+ expected_picklist_file_path
64+ )
5265 end
5366
5467 private_class_method def self . create_profile ( partner :, program_address1 :, program_address2 :, program_city :, program_state :, program_zip :,
55- address1 : "Example Address 1" , city : "Example City" , state : "Example State" , zip : "12345" , primary_contact_name : "Jaqueline Kihn DDS" , primary_contact_email : "van@durgan.example" )
68+ 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 )
5669 Partners ::Profile . create! (
5770 partner_id : partner . id ,
5871 essentials_bank_id : partner . organization . id ,
@@ -67,7 +80,10 @@ def self.get_file_paths
6780 program_address2 : program_address2 ,
6881 program_city : program_city ,
6982 program_state : program_state ,
70- program_zip_code : program_zip
83+ program_zip_code : program_zip ,
84+ pick_up_name : pick_up_name ,
85+ pick_up_email : pick_up_email ,
86+ pick_up_phone : pick_up_phone
7187 )
7288 end
7389
@@ -91,9 +107,26 @@ def self.create_profile_no_contact_with_program_address(partner)
91107 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 : "" )
92108 end
93109
94- def self . create_line_items_request ( distribution , partner , storage_creation )
110+ def self . create_profile_with_pickup_person ( partner )
111+ create_profile (
112+ partner : partner ,
113+ pick_up_name : "Pickup Person" ,
114+ pick_up_email : "pickup@example.com" ,
115+ pick_up_phone : "1234567890" ,
116+ program_address1 : "Example Program Address 1" ,
117+ program_address2 : "" ,
118+ program_city : "Example Program City" ,
119+ program_state : "Example Program State" ,
120+ program_zip : 54321
121+ )
122+ end
123+
124+ def self . create_line_items_for_distribution ( distribution , storage_creation )
95125 LineItem . create! ( itemizable : distribution , item : storage_creation . items [ 0 ] , quantity : 50 )
96126 LineItem . create! ( itemizable : distribution , item : storage_creation . items [ 1 ] , quantity : 100 )
127+ end
128+
129+ def self . create_line_items_request ( partner :, storage_creation :, distribution : nil )
97130 storage_creation . organization . request_units . find_or_create_by! ( name : "pack" )
98131 ItemUnit . find_or_create_by! ( item : storage_creation . items [ 3 ] , name : "pack" )
99132 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 )
@@ -108,30 +141,48 @@ def self.create_line_items_request(distribution, partner, storage_creation)
108141 { "item_id" => storage_creation . items [ 2 ] . id , "quantity" => 50 } ,
109142 { "item_id" => storage_creation . items [ 3 ] . id , "quantity" => 120 , "request_unit" => "pack" }
110143 ] ,
111- item_requests : [ req1 , req2 , req3 ]
144+ item_requests : [ req1 , req2 , req3 ] ,
145+ created_at : Time . zone . local ( 2024 , 12 , 30 , 0 , 0 , 0 )
112146 )
113147 end
114148
115149 def self . create_dist ( partner , storage_creation , delivery_method )
116150 Time . zone = "America/Los_Angeles"
117151 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 )
118- create_line_items_request ( dist , partner , storage_creation )
152+ create_line_items_for_distribution ( dist , storage_creation )
153+ create_line_items_request ( distribution : dist , partner : partner , storage_creation : storage_creation )
119154 dist
120155 end
121156
122- def self . render_pdf_at_year_end ( organization , distribution )
157+ def self . render_distribution_pdf_at_year_end ( organization , distribution )
123158 travel_to ( Time . zone . local ( 2024 , 12 , 30 , 0 , 0 , 0 ) ) do
124159 return DistributionPdf . new ( organization , distribution ) . compute_and_render
125160 end
126161 end
127162
128- private_class_method def self . create_comparison_pdf ( storage_creation , profile_create_method , expected_file_path , delivery_method )
163+ def self . render_picklist_pdf ( organization , requests )
164+ PicklistsPdf . new ( organization , requests ) . compute_and_render
165+ end
166+
167+ private_class_method def self . create_distribution_comparison_pdf ( storage_creation , profile_create_method , expected_file_path , delivery_method )
129168 # Partner creation must be rolled back otherwise Items requested YTD will accumulate
130169 ActiveRecord ::Base . transaction ( requires_new : true ) do
131170 partner = create_partner ( storage_creation . organization )
132171 PDFComparisonTestFactory . public_send ( profile_create_method , partner )
133172 dist = create_dist ( partner , storage_creation , delivery_method )
134- pdf_file = render_pdf_at_year_end ( storage_creation . organization , dist )
173+ pdf_file = render_distribution_pdf_at_year_end ( storage_creation . organization , dist )
174+ File . binwrite ( expected_file_path , pdf_file )
175+ raise ActiveRecord ::Rollback
176+ end
177+ end
178+
179+ private_class_method def self . create_picklist_comparison_pdf ( storage_creation , partner_create_method , profile_create_method , expected_file_path )
180+ # Partner creation must be rolled back otherwise Items requested YTD will accumulate
181+ ActiveRecord ::Base . transaction ( requires_new : true ) do
182+ partner = PDFComparisonTestFactory . public_send ( partner_create_method , storage_creation . organization )
183+ PDFComparisonTestFactory . public_send ( profile_create_method , partner )
184+ request = create_line_items_request ( partner : partner , storage_creation : storage_creation )
185+ pdf_file = render_picklist_pdf ( storage_creation . organization , [ request ] )
135186 File . binwrite ( expected_file_path , pdf_file )
136187 raise ActiveRecord ::Rollback
137188 end
@@ -152,11 +203,13 @@ def self.create_comparison_pdfs
152203 ActiveRecord ::Base . transaction do
153204 storage_creation = create_organization_storage_items ( logo )
154205
155- create_comparison_pdf ( storage_creation , :create_profile_no_address , file_paths . expected_pickup_file_path , :pick_up )
156- create_comparison_pdf ( storage_creation , :create_profile_without_program_address , file_paths . expected_same_address_file_path , :shipped )
157- create_comparison_pdf ( storage_creation , :create_profile_with_program_address , file_paths . expected_different_address_file_path , :delivery )
158- create_comparison_pdf ( storage_creation , :create_profile_with_incomplete_address , file_paths . expected_incomplete_address_file_path , :delivery )
159- create_comparison_pdf ( storage_creation , :create_profile_no_contact_with_program_address , file_paths . expected_no_contact_file_path , :delivery )
206+ create_distribution_comparison_pdf ( storage_creation , :create_profile_no_address , file_paths . expected_pickup_file_path , :pick_up )
207+ create_distribution_comparison_pdf ( storage_creation , :create_profile_without_program_address , file_paths . expected_same_address_file_path , :shipped )
208+ create_distribution_comparison_pdf ( storage_creation , :create_profile_with_program_address , file_paths . expected_different_address_file_path , :delivery )
209+ create_distribution_comparison_pdf ( storage_creation , :create_profile_with_incomplete_address , file_paths . expected_incomplete_address_file_path , :delivery )
210+ create_distribution_comparison_pdf ( storage_creation , :create_profile_no_contact_with_program_address , file_paths . expected_no_contact_file_path , :delivery )
211+
212+ create_picklist_comparison_pdf ( storage_creation , :create_partner_with_quota , :create_profile_with_pickup_person , file_paths . expected_picklist_file_path )
160213
161214 raise ActiveRecord ::Rollback
162215 end
0 commit comments