@@ -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" )
@@ -41,17 +41,30 @@ def self.create_partner(organization)
4141 Partner . create! ( name : "Leslie Sue" , organization : organization , email : "leslie1@gmail.com" )
4242 end
4343
44+ def self . create_partner_with_quota ( organization )
45+ Partner . create! ( name : "Leslie Sue" , organization : organization , email : "leslie1@gmail.com" , quota : 100 )
46+ end
47+
4448 def self . get_file_paths
4549 expected_pickup_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_pickup.pdf" )
4650 expected_same_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_same_address.pdf" )
4751 expected_different_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_program_address.pdf" )
4852 expected_incomplete_address_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_incomplete_address.pdf" )
4953 expected_no_contact_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "distribution_no_contact.pdf" )
50- 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 )
54+ expected_picklist_file_path = Rails . root . join ( "spec" , "fixtures" , "files" , "picklist.pdf" )
55+
56+ FilePaths . new (
57+ expected_pickup_file_path ,
58+ expected_same_address_file_path ,
59+ expected_different_address_file_path ,
60+ expected_incomplete_address_file_path ,
61+ expected_no_contact_file_path ,
62+ expected_picklist_file_path
63+ )
5164 end
5265
5366 private_class_method def self . create_profile ( partner :, program_address1 :, program_address2 :, program_city :, program_state :, program_zip :,
54- address1 : "Example Address 1" , city : "Example City" , state : "Example State" , zip : "12345" , primary_contact_name : "Jaqueline Kihn DDS" , primary_contact_email : "van@durgan.example" )
67+ 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 )
5568 Partners ::Profile . create! (
5669 partner_id : partner . id ,
5770 essentials_bank_id : partner . organization . id ,
@@ -66,7 +79,10 @@ def self.get_file_paths
6679 program_address2 : program_address2 ,
6780 program_city : program_city ,
6881 program_state : program_state ,
69- program_zip_code : program_zip
82+ program_zip_code : program_zip ,
83+ pick_up_name : pick_up_name ,
84+ pick_up_email : pick_up_email ,
85+ pick_up_phone : pick_up_phone
7086 )
7187 end
7288
@@ -90,9 +106,26 @@ def self.create_profile_no_contact_with_program_address(partner)
90106 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 : "" )
91107 end
92108
93- def self . create_line_items_request ( distribution , partner , storage_creation )
109+ def self . create_profile_with_pickup_person ( partner )
110+ create_profile (
111+ partner : partner ,
112+ pick_up_name : "Pickup Person" ,
113+ pick_up_email : "pickup@example.com" ,
114+ pick_up_phone : "1234567890" ,
115+ program_address1 : "Example Program Address 1" ,
116+ program_address2 : "" ,
117+ program_city : "Example Program City" ,
118+ program_state : "Example Program State" ,
119+ program_zip : 54321
120+ )
121+ end
122+
123+ def self . create_line_items_for_distribution ( distribution , storage_creation )
94124 LineItem . create! ( itemizable : distribution , item : storage_creation . items [ 0 ] , quantity : 50 )
95125 LineItem . create! ( itemizable : distribution , item : storage_creation . items [ 1 ] , quantity : 100 )
126+ end
127+
128+ def self . create_line_items_request ( partner :, storage_creation :, distribution : nil )
96129 storage_creation . organization . request_units . find_or_create_by! ( name : "pack" )
97130 ItemUnit . find_or_create_by! ( item : storage_creation . items [ 3 ] , name : "pack" )
98131 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)
107140 { "item_id" => storage_creation . items [ 2 ] . id , "quantity" => 50 } ,
108141 { "item_id" => storage_creation . items [ 3 ] . id , "quantity" => 120 , "request_unit" => "pack" }
109142 ] ,
110- item_requests : [ req1 , req2 , req3 ]
143+ item_requests : [ req1 , req2 , req3 ] ,
144+ created_at : Time . zone . local ( 2024 , 12 , 30 , 0 , 0 , 0 )
111145 )
112146 end
113147
114148 def self . create_dist ( partner , storage_creation , delivery_method )
115149 Time . zone = "America/Los_Angeles"
116150 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 )
117- create_line_items_request ( dist , partner , storage_creation )
151+ create_line_items_for_distribution ( dist , storage_creation )
152+ create_line_items_request ( distribution : dist , partner : partner , storage_creation : storage_creation )
118153 dist
119154 end
120155
121- def self . render_pdf_at_year_end ( organization , distribution )
156+ def self . render_distribution_pdf_at_year_end ( organization , distribution )
122157 travel_to ( Time . zone . local ( 2024 , 12 , 30 , 0 , 0 , 0 ) ) do
123158 return DistributionPdf . new ( organization , distribution ) . compute_and_render
124159 end
125160 end
126161
127- private_class_method def self . create_comparison_pdf ( storage_creation , profile_create_method , expected_file_path , delivery_method )
162+ def self . render_picklist_pdf ( organization , requests )
163+ PicklistsPdf . new ( organization , requests ) . compute_and_render
164+ end
165+
166+ private_class_method def self . create_distribution_comparison_pdf ( storage_creation , profile_create_method , expected_file_path , delivery_method )
128167 # Partner creation must be rolled back otherwise Items requested YTD will accumulate
129168 ActiveRecord ::Base . transaction ( requires_new : true ) do
130169 partner = create_partner ( storage_creation . organization )
131170 PDFComparisonTestFactory . public_send ( profile_create_method , partner )
132171 dist = create_dist ( partner , storage_creation , delivery_method )
133- pdf_file = render_pdf_at_year_end ( storage_creation . organization , dist )
172+ pdf_file = render_distribution_pdf_at_year_end ( storage_creation . organization , dist )
173+ File . binwrite ( expected_file_path , pdf_file )
174+ raise ActiveRecord ::Rollback
175+ end
176+ end
177+
178+ private_class_method def self . create_picklist_comparison_pdf ( storage_creation , partner_create_method , profile_create_method , expected_file_path )
179+ # Partner creation must be rolled back otherwise Items requested YTD will accumulate
180+ ActiveRecord ::Base . transaction ( requires_new : true ) do
181+ partner = PDFComparisonTestFactory . public_send ( partner_create_method , storage_creation . organization )
182+ PDFComparisonTestFactory . public_send ( profile_create_method , partner )
183+ request = create_line_items_request ( partner : partner , storage_creation : storage_creation )
184+ pdf_file = render_picklist_pdf ( storage_creation . organization , [ request ] )
134185 File . binwrite ( expected_file_path , pdf_file )
135186 raise ActiveRecord ::Rollback
136187 end
@@ -151,11 +202,13 @@ def self.create_comparison_pdfs
151202 ActiveRecord ::Base . transaction do
152203 storage_creation = create_organization_storage_items ( logo )
153204
154- create_comparison_pdf ( storage_creation , :create_profile_no_address , file_paths . expected_pickup_file_path , :pick_up )
155- create_comparison_pdf ( storage_creation , :create_profile_without_program_address , file_paths . expected_same_address_file_path , :shipped )
156- create_comparison_pdf ( storage_creation , :create_profile_with_program_address , file_paths . expected_different_address_file_path , :delivery )
157- create_comparison_pdf ( storage_creation , :create_profile_with_incomplete_address , file_paths . expected_incomplete_address_file_path , :delivery )
158- create_comparison_pdf ( storage_creation , :create_profile_no_contact_with_program_address , file_paths . expected_no_contact_file_path , :delivery )
205+ create_distribution_comparison_pdf ( storage_creation , :create_profile_no_address , file_paths . expected_pickup_file_path , :pick_up )
206+ create_distribution_comparison_pdf ( storage_creation , :create_profile_without_program_address , file_paths . expected_same_address_file_path , :shipped )
207+ create_distribution_comparison_pdf ( storage_creation , :create_profile_with_program_address , file_paths . expected_different_address_file_path , :delivery )
208+ create_distribution_comparison_pdf ( storage_creation , :create_profile_with_incomplete_address , file_paths . expected_incomplete_address_file_path , :delivery )
209+ create_distribution_comparison_pdf ( storage_creation , :create_profile_no_contact_with_program_address , file_paths . expected_no_contact_file_path , :delivery )
210+
211+ create_picklist_comparison_pdf ( storage_creation , :create_partner_with_quota , :create_profile_with_pickup_person , file_paths . expected_picklist_file_path )
159212
160213 raise ActiveRecord ::Rollback
161214 end
0 commit comments