|
1 | 1 | RSpec.describe "Reports::ManufacturerDonationsSummary", type: :request do |
2 | 2 | let(:organization) { create(:organization) } |
3 | 3 | let(:user) { create(:user, organization: organization) } |
| 4 | + let(:manufacturer1) { create(:manufacturer, organization: organization, name: "Manufacturer 1") } |
| 5 | + let(:manufacturer2) { create(:manufacturer, organization: organization, name: "Manufacturer 2") } |
| 6 | + let(:manufacturer3) { create(:manufacturer, organization: organization, name: "Manufacturer 3") } |
4 | 7 |
|
5 | 8 | describe "while signed in" do |
6 | 9 | before do |
|
9 | 12 |
|
10 | 13 | describe "GET #index" do |
11 | 14 | subject do |
12 | | - get reports_manufacturer_donations_summary_path(format: response_format) |
| 15 | + get reports_manufacturer_donations_summary_path(format: "html") |
13 | 16 | response |
14 | 17 | end |
15 | | - let(:response_format) { "html" } |
16 | 18 |
|
17 | 19 | it { is_expected.to have_http_status(:success) } |
18 | 20 | end |
| 21 | + |
| 22 | + context "when visiting the summary page" do |
| 23 | + it "has a link to create a new donation" do |
| 24 | + get reports_manufacturer_donations_summary_path |
| 25 | + |
| 26 | + expect(response.body).to include("New Donation") |
| 27 | + expect(response.body).to include("#{@url_prefix}/donations/new") |
| 28 | + end |
| 29 | + |
| 30 | + context "with manufacturer donations in the last year" do |
| 31 | + let(:formatted_date_range) { date_range.map { _1.to_formatted_s(:date_picker) }.join(" - ") } |
| 32 | + let(:date_range) { [1.year.ago, 0.days.ago] } |
| 33 | + let!(:donations) do |
| 34 | + [ |
| 35 | + create(:donation, :with_items, item_quantity: 2, issued_at: 5.days.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer1), |
| 36 | + create(:donation, :with_items, item_quantity: 3, issued_at: 3.months.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer1), |
| 37 | + create(:donation, :with_items, item_quantity: 7, issued_at: 2.years.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer2), |
| 38 | + create(:donation, :with_items, item_quantity: 1, issued_at: 0.days.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer2), |
| 39 | + create(:donation, :with_items, item_quantity: 13, issued_at: 20.days.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer3), |
| 40 | + create(:donation, :with_items, item_quantity: 17, issued_at: 5.years.ago, organization: organization, source: "Manufacturer", manufacturer: manufacturer3) |
| 41 | + ] |
| 42 | + end |
| 43 | + |
| 44 | + it "shows correct total received donations" do |
| 45 | + get reports_manufacturer_donations_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}} |
| 46 | + |
| 47 | + expect(response.body).to match(%r{<span class="total_received_donations">\s*19\s*</span>}) |
| 48 | + end |
| 49 | + |
| 50 | + it "shows correct individual donations for each manufacturer" do |
| 51 | + get reports_manufacturer_donations_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}} |
| 52 | + |
| 53 | + expect(response.body).to match(%r{Manufacturer 1 \(5\)}) |
| 54 | + expect(response.body).to match(%r{Manufacturer 2 \(1\)}) |
| 55 | + expect(response.body).to match(%r{Manufacturer 3 \(13\)}) |
| 56 | + end |
| 57 | + |
| 58 | + it "shows top manufacturers in desc. order" do |
| 59 | + get reports_manufacturer_donations_summary_path(user.organization), params: {filters: {date_range: formatted_date_range}} |
| 60 | + |
| 61 | + expect(response.body).to match(%r{Manufacturer 3 .* Manufacturer 1 .*Manufacturer 2}m) |
| 62 | + end |
| 63 | + end |
| 64 | + end |
19 | 65 | end |
20 | 66 |
|
21 | 67 | describe "while not signed in" do |
|
0 commit comments