|
56 | 56 | end |
57 | 57 | end |
58 | 58 |
|
| 59 | + describe ".batch_successful_sales_counts", :sidekiq_inline, :elasticsearch_wait_for_refresh do |
| 60 | + it "returns per-product sales counts in a single query" do |
| 61 | + product1 = create(:product, price_cents: 500) |
| 62 | + product2 = create(:product, price_cents: 500) |
| 63 | + create_list(:purchase, 2, link: product1) |
| 64 | + create(:purchase, link: product1, stripe_refunded: true) |
| 65 | + create(:purchase, link: product2) |
| 66 | + |
| 67 | + counts = Link.batch_successful_sales_counts(products: [product1, product2]) |
| 68 | + expect(counts[product1.id]).to eq(2) |
| 69 | + expect(counts[product2.id]).to eq(1) |
| 70 | + end |
| 71 | + |
| 72 | + it "returns an empty hash when products is blank" do |
| 73 | + expect(Link.batch_successful_sales_counts(products: [])).to eq({}) |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + describe ".batch_total_usd_cents", :sidekiq_inline, :elasticsearch_wait_for_refresh do |
| 78 | + it "returns per-product net revenue in a single query" do |
| 79 | + product1 = create(:product, price_cents: 500) |
| 80 | + product2 = create(:product, price_cents: 300) |
| 81 | + create_list(:purchase, 2, link: product1) |
| 82 | + create(:purchase, link: product1, stripe_refunded: true) |
| 83 | + create(:purchase, link: product2) |
| 84 | + |
| 85 | + totals = Link.batch_total_usd_cents(products: [product1, product2]) |
| 86 | + expect(totals[product1.id]).to eq(1000) |
| 87 | + expect(totals[product2.id]).to eq(300) |
| 88 | + end |
| 89 | + |
| 90 | + it "returns an empty hash when products is blank" do |
| 91 | + expect(Link.batch_total_usd_cents(products: [])).to eq({}) |
| 92 | + end |
| 93 | + end |
| 94 | + |
59 | 95 | describe "#total_usd_cents", :sidekiq_inline, :elasticsearch_wait_for_refresh do |
60 | 96 | it "returns net revenue" do |
61 | 97 | product = create(:product) |
|
0 commit comments