wedding-planner/spec/queries/expenses/total_query_spec.rb

77 lines
2.7 KiB
Ruby
Raw Normal View History

2025-01-13 20:38:47 +00:00
# Copyright (C) 2024 Manuel Bustillo
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
2024-10-31 23:34:15 +00:00
# frozen_string_literal: true
2024-10-28 22:38:47 +01:00
require 'rails_helper'
module Expenses
RSpec.describe TotalQuery do
describe '#call' do
let(:wedding) { create(:wedding) }
let(:response) { described_class.new(wedding:).call }
2024-10-28 22:38:47 +01:00
before do
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
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
context 'when there are only fixed expenses' do
2024-10-28 22:38:47 +01:00
before do
create(:expense, :fixed, wedding:, amount: 100)
create(:expense, :fixed, wedding:, amount: 200)
2024-10-28 22:38:47 +01:00
end
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
context 'when there are only variable expenses' do
2024-10-28 22:38:47 +01:00
before do
create(:expense, :per_person, wedding:, amount: 100)
create(:expense, :per_person, wedding:, amount: 200)
2024-10-28 22:38:47 +01:00
end
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
context 'when there are both fixed and variable expenses' do
2024-10-28 22:38:47 +01:00
before do
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
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