2025-01-13 21:37:02 +01:00
|
|
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
2024-11-13 07:59:07 +00:00
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-13 08:57:20 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
module Groups
|
|
|
|
RSpec.describe SummaryQuery do
|
|
|
|
describe '#call' do
|
2024-12-28 17:36:06 +01:00
|
|
|
subject(:result) { described_class.new.call }
|
2024-11-13 08:57:20 +01:00
|
|
|
|
|
|
|
context 'when there are no groups' do
|
|
|
|
it { is_expected.to eq([]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when groups are defined' do
|
|
|
|
let!(:parent) { create(:group, name: 'Friends', icon: 'icon-1', color: '#FF0000') }
|
|
|
|
let!(:child) { create(:group, name: 'Family', icon: 'icon-2', color: '#00FF00', parent:) }
|
|
|
|
|
|
|
|
context 'when there are no guests' do
|
|
|
|
it 'returns the summary of groups' do
|
2024-12-28 17:36:06 +01:00
|
|
|
expect(result).to contain_exactly(
|
2024-11-13 08:57:20 +01:00
|
|
|
{ 'id' => parent.id,
|
|
|
|
'name' => 'Friends',
|
|
|
|
'icon' => 'icon-1',
|
|
|
|
'parent_id' => nil,
|
|
|
|
'color' => '#FF0000',
|
|
|
|
'total' => 0,
|
|
|
|
'considered' => 0,
|
|
|
|
'invited' => 0,
|
|
|
|
'confirmed' => 0,
|
|
|
|
'declined' => 0,
|
|
|
|
'tentative' => 0 },
|
|
|
|
{ 'id' => child.id,
|
|
|
|
'name' => 'Family',
|
|
|
|
'icon' => 'icon-2',
|
|
|
|
'parent_id' => parent.id,
|
|
|
|
'color' => '#00FF00',
|
|
|
|
'total' => 0,
|
|
|
|
'considered' => 0,
|
|
|
|
'invited' => 0,
|
|
|
|
'confirmed' => 0,
|
|
|
|
'declined' => 0,
|
|
|
|
'tentative' => 0 }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are guests' do
|
|
|
|
before do
|
|
|
|
# Parent group
|
|
|
|
create_list(:guest, 2, group: parent, status: :considered)
|
|
|
|
create_list(:guest, 3, group: parent, status: :invited)
|
|
|
|
create_list(:guest, 4, group: parent, status: :confirmed)
|
|
|
|
create_list(:guest, 5, group: parent, status: :declined)
|
|
|
|
create_list(:guest, 6, group: parent, status: :tentative)
|
|
|
|
|
|
|
|
# Child group
|
|
|
|
create_list(:guest, 7, group: child, status: :considered)
|
|
|
|
create_list(:guest, 8, group: child, status: :invited)
|
|
|
|
create_list(:guest, 9, group: child, status: :confirmed)
|
|
|
|
create_list(:guest, 10, group: child, status: :declined)
|
2024-12-28 17:36:06 +01:00
|
|
|
create_list(:guest, 11, group: child, status: :tentative) # rubocop:disable FactoryBot/ExcessiveCreateList
|
2024-11-13 08:57:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the summary of groups' do
|
2024-12-28 17:36:06 +01:00
|
|
|
expect(result).to contain_exactly(
|
2024-11-13 08:57:20 +01:00
|
|
|
{
|
|
|
|
'id' => parent.id,
|
|
|
|
'name' => 'Friends',
|
|
|
|
'icon' => 'icon-1',
|
|
|
|
'parent_id' => nil,
|
|
|
|
'color' => '#FF0000',
|
|
|
|
'total' => 20,
|
|
|
|
'considered' => 2,
|
|
|
|
'invited' => 3,
|
|
|
|
'confirmed' => 4,
|
|
|
|
'declined' => 5,
|
|
|
|
'tentative' => 6
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id' => child.id,
|
|
|
|
'name' => 'Family',
|
|
|
|
'icon' => 'icon-2',
|
|
|
|
'parent_id' => parent.id,
|
|
|
|
'color' => '#00FF00',
|
|
|
|
'total' => 45,
|
|
|
|
'considered' => 7,
|
|
|
|
'invited' => 8,
|
|
|
|
'confirmed' => 9,
|
|
|
|
'declined' => 10,
|
|
|
|
'tentative' => 11
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|