2024-10-31 23:34:15 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-10-28 22:38:47 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
module Expenses
|
|
|
|
RSpec.describe TotalQuery do
|
|
|
|
describe '#call' do
|
2024-12-11 09:00:45 +01:00
|
|
|
let(:wedding) { create(:wedding) }
|
|
|
|
let(:response) { described_class.new(wedding:).call }
|
2024-10-28 22:38:47 +01:00
|
|
|
|
|
|
|
before do
|
2024-12-11 09:00:45 +01:00
|
|
|
create_list(:guest, 2, wedding:, status: :confirmed)
|
|
|
|
create_list(:guest, 3, wedding:, status: :considered)
|
|
|
|
create_list(:guest, 4, wedding:, status: :invited)
|
|
|
|
create_list(:guest, 5, wedding:, status: :tentative)
|
|
|
|
create_list(:guest, 6, wedding:, status: :declined)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
context 'when there is no expense' do
|
|
|
|
it 'returns zero in all values', :aggregate_failures do
|
|
|
|
expect(response['total_confirmed']).to be_zero
|
|
|
|
expect(response['total_projected']).to be_zero
|
|
|
|
expect(response['confirmed_guests']).to eq(2)
|
|
|
|
expect(response['projected_guests']).to eq(2 + 4 + 5)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
context 'when there are only fixed expenses' do
|
2024-10-28 22:38:47 +01:00
|
|
|
before do
|
2024-12-11 09:00:45 +01:00
|
|
|
create(:expense, :fixed, wedding:, amount: 100)
|
|
|
|
create(:expense, :fixed, wedding:, amount: 200)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
it 'returns the sum of fixed expenses', :aggregate_failures do
|
|
|
|
expect(response['total_confirmed']).to eq(300)
|
|
|
|
expect(response['total_projected']).to eq(300)
|
|
|
|
expect(response['confirmed_guests']).to eq(2)
|
|
|
|
expect(response['projected_guests']).to eq(2 + 4 + 5)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
context 'when there are only variable expenses' do
|
2024-10-28 22:38:47 +01:00
|
|
|
before do
|
2024-12-11 09:00:45 +01:00
|
|
|
create(:expense, :per_person, wedding:, amount: 100)
|
|
|
|
create(:expense, :per_person, wedding:, amount: 200)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
it 'returns zero in the values and nonzero in the count', :aggregate_failures do
|
|
|
|
expect(response['total_confirmed']).to eq(2 * 300)
|
|
|
|
expect(response['total_projected']).to eq(11 * 300)
|
|
|
|
expect(response['confirmed_guests']).to eq(2)
|
|
|
|
expect(response['projected_guests']).to eq(2 + 4 + 5)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
context 'when there are both fixed and variable expenses' do
|
2024-10-28 22:38:47 +01:00
|
|
|
before do
|
2024-12-11 09:00:45 +01:00
|
|
|
create(:expense, :fixed, wedding:, amount: 100)
|
|
|
|
create(:expense, :fixed, wedding:, amount: 200)
|
|
|
|
create(:expense, :per_person, wedding:, amount: 50)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
|
2024-12-11 09:00:45 +01:00
|
|
|
it 'returns the sum of fixed and variable expenses', :aggregate_failures do
|
|
|
|
expect(response['total_confirmed']).to eq(100 + 200 + 50 * 2)
|
|
|
|
expect(response['total_projected']).to eq(100 + 200 + 11 * 50)
|
|
|
|
expect(response['confirmed_guests']).to eq(2)
|
|
|
|
expect(response['projected_guests']).to eq(2 + 4 + 5)
|
2024-10-28 22:38:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|