|
1 |
| -require_relative("../support/distribution_pdf_helper") |
2 | 1 | require_relative("../../lib/test_helpers/pdf_comparison_test_factory")
|
3 | 2 |
|
4 |
| -RSpec.configure do |c| |
5 |
| - c.include DistributionPDFHelper |
6 |
| - c.include PDFComparisonTestFactory |
7 |
| -end |
8 |
| - |
9 | 3 | describe DistributionPdf do
|
10 |
| - let(:storage_creation) { create_organization_storage_items } |
| 4 | + let(:storage_creation) { PDFComparisonTestFactory.create_organization_storage_items } |
11 | 5 | let(:organization) { storage_creation.organization }
|
12 | 6 | let(:storage_location) { storage_creation.storage_location }
|
13 | 7 |
|
|
23 | 17 | let(:partner) { create(:partner) }
|
24 | 18 |
|
25 | 19 | before(:each) do
|
26 |
| - create_line_items_request(distribution, partner, storage_creation) |
| 20 | + PDFComparisonTestFactory.create_line_items_request(distribution, partner, storage_creation) |
27 | 21 | end
|
28 | 22 |
|
29 | 23 | specify "#request_data with custom units feature" do
|
|
137 | 131 | end
|
138 | 132 |
|
139 | 133 | describe "address pdf output" do
|
140 |
| - let(:partner) { create_partner(organization) } |
141 |
| - let(:file_paths) { get_file_paths } |
| 134 | + def compare_pdf(distribution, expected_file_path) |
| 135 | + pdf = DistributionPdf.new(organization, distribution) |
| 136 | + begin |
| 137 | + pdf_file = pdf.compute_and_render |
| 138 | + |
| 139 | + # Run the following from Rails sandbox console (bin/rails/console --sandbox) to regenerate these comparison PDFs: |
| 140 | + # => load "lib/test_helpers/pdf_comparison_test_factory.rb" |
| 141 | + # => Rails::ConsoleMethods.send(:prepend, PDFComparisonTestFactory) |
| 142 | + # => create_comparison_pdfs |
| 143 | + expect(pdf_file).to eq(IO.binread(expected_file_path)) |
| 144 | + rescue RSpec::Expectations::ExpectationNotMetError => e |
| 145 | + File.binwrite(Rails.root.join("tmp", "failed_match_distribution_" + distribution.delivery_method.to_s + "_" + Time.current.to_s + ".pdf"), pdf_file) |
| 146 | + raise e.class, "PDF does not match, written to tmp/", cause: nil |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + let(:partner) { PDFComparisonTestFactory.create_partner(organization) } |
| 151 | + let(:file_paths) { PDFComparisonTestFactory.get_file_paths } |
142 | 152 | let(:expected_different_address_file_path) { file_paths.expected_different_address_file_path }
|
143 | 153 | let(:expected_pickup_file_path) { file_paths.expected_pickup_file_path }
|
144 | 154 | let(:expected_same_address_file_path) { file_paths.expected_same_address_file_path }
|
|
147 | 157 |
|
148 | 158 | context "when the partner has no addresses" do
|
149 | 159 | before(:each) do
|
150 |
| - create_profile_no_address(partner) |
| 160 | + PDFComparisonTestFactory.create_profile_no_address(partner) |
151 | 161 | end
|
152 | 162 | it "doesn't print any address if the delivery type is pickup" do
|
153 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
| 163 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
154 | 164 | end
|
155 | 165 | it "doesn't print any address if the delivery type is delivery" do
|
156 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_pickup_file_path) |
| 166 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :delivery), expected_pickup_file_path) |
157 | 167 | end
|
158 | 168 | it "doesn't print any address if the delivery type is shipped" do
|
159 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :shipped), expected_pickup_file_path) |
| 169 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :shipped), expected_pickup_file_path) |
160 | 170 | end
|
161 | 171 | end
|
162 | 172 | context "when the partner doesn't have a different program address" do
|
163 | 173 | before(:each) do
|
164 |
| - create_profile_without_program_address(partner) |
| 174 | + PDFComparisonTestFactory.create_profile_without_program_address(partner) |
165 | 175 | end
|
166 | 176 | it "prints the address if the delivery type is delivery" do
|
167 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_same_address_file_path) |
| 177 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :delivery), expected_same_address_file_path) |
168 | 178 | end
|
169 | 179 | it "prints the address if the delivery type is shipped" do
|
170 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :shipped), expected_same_address_file_path) |
| 180 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :shipped), expected_same_address_file_path) |
171 | 181 | end
|
172 | 182 | it "doesn't print the address if the delivery type is pickup" do
|
173 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
| 183 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
174 | 184 | end
|
175 | 185 | end
|
176 | 186 | context "when the partner has a different program/delivery address" do
|
177 | 187 | before(:each) do
|
178 |
| - create_profile_with_program_address(partner) |
| 188 | + PDFComparisonTestFactory.create_profile_with_program_address(partner) |
179 | 189 | end
|
180 | 190 | it "prints the delivery address if the delivery type is delivery" do
|
181 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_different_address_file_path) |
| 191 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :delivery), expected_different_address_file_path) |
182 | 192 | end
|
183 | 193 | it "prints the delivery address if the delivery type is shipped" do
|
184 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :shipped), expected_different_address_file_path) |
| 194 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :shipped), expected_different_address_file_path) |
185 | 195 | end
|
186 | 196 | it "doesn't print any address if the delivery type is pickup" do
|
187 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
| 197 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :pick_up), expected_pickup_file_path) |
188 | 198 | end
|
189 | 199 | end
|
190 | 200 | it "formats output correctly when the partner delivery address is incomplete" do
|
191 |
| - create_profile_with_incomplete_address(partner) |
192 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_incomplete_address_file_path) |
| 201 | + PDFComparisonTestFactory.create_profile_with_incomplete_address(partner) |
| 202 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :delivery), expected_incomplete_address_file_path) |
193 | 203 | end
|
194 | 204 | it "formats output correctly when the partner profile contact info does not exist" do
|
195 |
| - create_profile_no_contact_with_program_address(partner) |
196 |
| - compare_pdf(organization, create_dist(partner, storage_creation, :delivery), expected_no_contact_file_path) |
| 205 | + PDFComparisonTestFactory.create_profile_no_contact_with_program_address(partner) |
| 206 | + compare_pdf(PDFComparisonTestFactory.create_dist(partner, storage_creation, :delivery), expected_no_contact_file_path) |
197 | 207 | end
|
198 | 208 | end
|
199 | 209 | end
|
0 commit comments