|
4 | 4 | let(:service) { described_class.new(organization.id, type) } |
5 | 5 |
|
6 | 6 | describe "#series" do |
7 | | - let!(:item1) { create(:item, organization: organization, name: "Item 1") } |
8 | | - let!(:item2) { create(:item, organization: organization, name: "Item 2") } |
| 7 | + let(:item1) { create(:item, organization: organization, name: "Item 1") } |
| 8 | + let(:item2) { create(:item, organization: organization, name: "Item 2") } |
| 9 | + let(:donation1) { create(:donation, organization:, issued_at: Date.current) } |
| 10 | + let(:donation2) { create(:donation, organization:, issued_at: 2.months.ago) } |
9 | 11 | let!(:line_items) do |
10 | 12 | (0..11).map do |n| |
11 | | - create(:line_item, item: item1, itemizable_type: type, quantity: 10 * (n + 1), created_at: n.months.ago) |
| 13 | + create(:line_item, item: item1, itemizable_type: type, itemizable_id: donation1.id, quantity: 10, created_at: n.months.ago) |
12 | 14 | end |
13 | 15 | end |
14 | | - let!(:line_item2) { create(:line_item, item: item2, itemizable_type: type, quantity: 60, created_at: 6.months.ago) } |
15 | | - let!(:line_item3) { create(:line_item, item: item2, itemizable_type: type, quantity: 30, created_at: 3.months.ago) } |
| 16 | + let!(:line_item2) { create(:line_item, item: item2, itemizable_type: type, itemizable_id: donation2.id, quantity: 60, created_at: 6.months.ago) } |
| 17 | + let!(:line_item3) { create(:line_item, item: item2, itemizable_type: type, itemizable_id: donation2.id, quantity: 30, created_at: 3.months.ago) } |
16 | 18 |
|
17 | 19 | it "returns an array of items with their monthly data" do |
18 | 20 | expected_result = [ |
19 | | - {name: "Item 1", data: [120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10], visible: false}, |
20 | | - {name: "Item 2", data: [0, 0, 0, 0, 0, 60, 0, 0, 30, 0, 0, 0], visible: false} |
| 21 | + {name: "Item 1", data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120], visible: false}, |
| 22 | + {name: "Item 2", data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0], visible: false} |
21 | 23 | ] |
22 | 24 | expect(service.series).to eq(expected_result) |
23 | 25 | end |
| 26 | + |
| 27 | + it "the last data point is the quantity for the current month" do |
| 28 | + item1_quantities = service.series.first[:data] |
| 29 | + expect(item1_quantities.last).to be(line_items.pluck(:quantity).sum) |
| 30 | + end |
24 | 31 | end |
25 | 32 | end |
0 commit comments