|
22 | 22 | let(:subscription) { create(:subscription, customer:, plan:) } |
23 | 23 | let(:invoice) { create(:invoice, customer:, organization:) } |
24 | 24 | let(:billable_metric) { create(:billable_metric, organization:) } |
| 25 | + let(:properties) { |
| 26 | + { |
| 27 | + "amount" => "100", |
| 28 | + "presentation_group_keys" => [ |
| 29 | + {"value" => "region", "options" => {"display_in_invoice" => true}}, |
| 30 | + {"value" => "department", "options" => {"display_in_invoice" => true}} |
| 31 | + ] |
| 32 | + } |
| 33 | + } |
25 | 34 |
|
26 | 35 | let(:charge) do |
27 | 36 | create( |
28 | 37 | :standard_charge, |
29 | 38 | plan:, |
30 | 39 | billable_metric:, |
31 | 40 | invoice_display_name: "compute", |
32 | | - properties: { |
33 | | - "amount" => "100", |
34 | | - "presentation_group_keys" => [ |
35 | | - {"value" => "region", "options" => {"display_in_invoice" => true}}, |
36 | | - {"value" => "department", "options" => {"display_in_invoice" => true}} |
37 | | - ] |
38 | | - } |
| 41 | + properties: |
39 | 42 | ) |
40 | 43 | end |
41 | 44 |
|
|
86 | 89 | it "renders each breakdown row's units" do |
87 | 90 | expect(rendered_template).to include("40").and include("35").and include("25").and include("10") |
88 | 91 | end |
| 92 | + |
| 93 | + context "when a presentation key is not displayed in the invoice" do |
| 94 | + let(:properties) do |
| 95 | + { |
| 96 | + "amount" => "100", |
| 97 | + "presentation_group_keys" => [ |
| 98 | + {"value" => "region", "options" => {"display_in_invoice" => false}}, |
| 99 | + {"value" => "department", "options" => {"display_in_invoice" => true}} |
| 100 | + ] |
| 101 | + } |
| 102 | + end |
| 103 | + |
| 104 | + it "renders breakdown labels joined by ', ' in lexicographic order with nil-value rows last" do |
| 105 | + label_order = rendered_template.scan(%r{<td[^>]*>\s*(engineering|sales)?\s*</td>\s*<td[^>]*>\s*(?:75|25|10)\s*</td>}).map(&:first) |
| 106 | + expect(label_order).to eq(["engineering", "sales", nil]) |
| 107 | + end |
| 108 | + |
| 109 | + it "renders each breakdown row's units" do |
| 110 | + expect(rendered_template).to include("75").and include("25").and include("10") |
| 111 | + end |
| 112 | + end |
89 | 113 | end |
90 | 114 |
|
91 | 115 | # Scenario 2 — `fee.grouped_by` is present. |
|
137 | 161 | eu_bare_idx = rendered_template =~ %r{<td[^>]*>\s*eu\s*</td>} |
138 | 162 | expect(eu_engineering_idx).to be < eu_bare_idx |
139 | 163 | end |
| 164 | + |
| 165 | + context "when a presentation key is not displayed in the invoice" do |
| 166 | + let(:properties) do |
| 167 | + { |
| 168 | + "amount" => "100", |
| 169 | + "presentation_group_keys" => [ |
| 170 | + {"value" => "region", "options" => {"display_in_invoice" => false}}, |
| 171 | + {"value" => "department", "options" => {"display_in_invoice" => true}} |
| 172 | + ] |
| 173 | + } |
| 174 | + end |
| 175 | + |
| 176 | + it "renders breakdown labels joined by ', ' in lexicographic order with nil-value rows last" do |
| 177 | + label_order = rendered_template.scan(%r{<td[^>]*>\s*(engineering|sales)?\s*</td>\s*<td[^>]*>\s*(?:40|20|5)\s*</td>}).map(&:first) |
| 178 | + expect(label_order).to eq(["engineering", "sales", nil]) |
| 179 | + end |
| 180 | + |
| 181 | + it "renders each breakdown row's units" do |
| 182 | + expect(rendered_template).to include("40").and include("20").and include("5") |
| 183 | + end |
| 184 | + end |
140 | 185 | end |
141 | 186 |
|
142 | 187 | # Scenario 3 — `fee.charge_filter_id` is present (with `fee.grouped_by` empty). |
|
188 | 233 | it "renders each breakdown row's units" do |
189 | 234 | expect(rendered_template).to include("30").and include("15").and include("5") |
190 | 235 | end |
| 236 | + |
| 237 | + context "when a presentation key is not displayed in the invoice" do |
| 238 | + let(:properties) do |
| 239 | + { |
| 240 | + "amount" => "100", |
| 241 | + "presentation_group_keys" => [ |
| 242 | + {"value" => "region", "options" => {"display_in_invoice" => false}}, |
| 243 | + {"value" => "department", "options" => {"display_in_invoice" => true}} |
| 244 | + ] |
| 245 | + } |
| 246 | + end |
| 247 | + |
| 248 | + it "renders breakdown labels joined by ', ' in lexicographic order with nil-value rows last" do |
| 249 | + label_order = rendered_template.scan(%r{<td[^>]*>\s*(engineering|sales)?\s*</td>\s*<td[^>]*>\s*(?:30|15|5)\s*</td>}).map(&:first) |
| 250 | + expect(label_order).to eq(["engineering", "sales", nil]) |
| 251 | + end |
| 252 | + |
| 253 | + it "renders each breakdown row's units" do |
| 254 | + expect(rendered_template).to include("30").and include("15").and include("5") |
| 255 | + end |
| 256 | + end |
191 | 257 | end |
192 | 258 |
|
193 | 259 | # Scenario 5 — breakdowns only contain keys not in displayable_keys. |
|
219 | 285 | it "does not render any breakdown values" do |
220 | 286 | expect(rendered_template).not_to include("country") |
221 | 287 | end |
| 288 | + |
| 289 | + context "when a presentation key is not displayed in the invoice" do |
| 290 | + let(:properties) do |
| 291 | + { |
| 292 | + "amount" => "100", |
| 293 | + "presentation_group_keys" => [ |
| 294 | + {"value" => "country", "options" => {"display_in_invoice" => false}} |
| 295 | + ] |
| 296 | + } |
| 297 | + end |
| 298 | + |
| 299 | + it "does not render anything" do |
| 300 | + expect(rendered_template).to be_blank |
| 301 | + end |
| 302 | + |
| 303 | + it "does not render the fee title row" do |
| 304 | + expect(rendered_template).not_to match(%r{<td[^>]*>\s*compute\s*</td>}) |
| 305 | + end |
| 306 | + |
| 307 | + it "does not render any breakdown values" do |
| 308 | + expect(rendered_template).not_to include("us") |
| 309 | + expect(rendered_template).not_to include("eu") |
| 310 | + end |
| 311 | + end |
222 | 312 | end |
223 | 313 |
|
224 | 314 | # Scenario 4 — `fee.charge_filter_id` is present together with a non-empty |
|
270 | 360 | it "renders each breakdown row's units" do |
271 | 361 | expect(rendered_template).to include("30").and include("15").and include("5") |
272 | 362 | end |
| 363 | + |
| 364 | + context "when a presentation key is not displayed in the invoice" do |
| 365 | + let(:properties) do |
| 366 | + { |
| 367 | + "amount" => "100", |
| 368 | + "presentation_group_keys" => [ |
| 369 | + {"value" => "region", "options" => {"display_in_invoice" => false}}, |
| 370 | + {"value" => "department", "options" => {"display_in_invoice" => true}} |
| 371 | + ] |
| 372 | + } |
| 373 | + end |
| 374 | + |
| 375 | + it "renders breakdown labels joined by ', ' in lexicographic order with nil-value rows last" do |
| 376 | + label_order = rendered_template.scan(%r{<td[^>]*>\s*(engineering|sales)?\s*</td>\s*<td[^>]*>\s*(?:30|15|5)\s*</td>}).map(&:first) |
| 377 | + expect(label_order).to eq(["engineering", "sales", nil]) |
| 378 | + end |
| 379 | + |
| 380 | + it "renders each breakdown row's units" do |
| 381 | + expect(rendered_template).to include("30").and include("15").and include("5") |
| 382 | + end |
| 383 | + end |
273 | 384 | end |
274 | 385 | end |
0 commit comments