wedding-planner/spec/queries/expenses/total_query_spec.rb
Manuel Bustillo da8f3c7618
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m31s
Add copyright notice / copyright_notice (pull_request) Successful in 1m34s
Run unit tests / unit_tests (pull_request) Successful in 3m55s
Define an endpoint with a global summary of expenses and attendance
2024-12-11 09:01:35 +01:00

73 lines
2.6 KiB
Ruby

# Copyright (C) 2024 Manuel Bustillo
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