Manuel Bustillo
e20a366410
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 56s
Add copyright notice / copyright_notice (pull_request) Successful in 1m36s
Run unit tests / unit_tests (pull_request) Successful in 3m56s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 28m26s
75 lines
2.7 KiB
Ruby
75 lines
2.7 KiB
Ruby
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
module Expenses
|
|
RSpec.describe TotalQuery do
|
|
describe '#call' do
|
|
let(:wedding) { create(:wedding) }
|
|
let(:response) { described_class.new(wedding:).call }
|
|
|
|
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)
|
|
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)
|
|
end
|
|
end
|
|
|
|
context 'when there are only fixed expenses' do
|
|
before do
|
|
create(:expense, :fixed, wedding:, amount: 100)
|
|
create(:expense, :fixed, wedding:, amount: 200)
|
|
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)
|
|
end
|
|
end
|
|
|
|
context 'when there are only variable expenses' do
|
|
before do
|
|
create(:expense, :per_person, wedding:, amount: 100)
|
|
create(:expense, :per_person, wedding:, amount: 200)
|
|
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)
|
|
end
|
|
end
|
|
|
|
context 'when there are both fixed and variable expenses' do
|
|
before do
|
|
create(:expense, :fixed, wedding:, amount: 100)
|
|
create(:expense, :fixed, wedding:, amount: 200)
|
|
create(:expense, :per_person, wedding:, amount: 50)
|
|
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)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|