Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions spec/services/invitation_manager_deduplication_spec.rb

This file was deleted.

64 changes: 64 additions & 0 deletions spec/services/invitation_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,68 @@
expect(invitation.reload.reminded_at).not_to be_nil
end
end

describe 'handling deduplication' do
let(:member_in_both_groups) { Fabricate(:member, accepted_toc_at: Time.zone.now) }

describe '#chapter_students' do
context 'when a member has multiple subscriptions to the same group type' do
before do
students_group1 = Fabricate(:group, name: 'Students', chapter: chapter)
students_group2 = Fabricate(:group, name: 'Students', chapter: chapter)
students_group1.members << member_in_both_groups
students_group2.members << member_in_both_groups
end

it 'returns unique members' do
result = manager.send(:chapter_students, chapter)

expect(result.count).to eq(1)
expect(result).to contain_exactly(member_in_both_groups)
end
end
end

describe '#chapter_coaches' do
context 'when a member has multiple subscriptions to the same group type' do
before do
coaches_group1 = Fabricate(:group, name: 'Coaches', chapter: chapter)
coaches_group2 = Fabricate(:group, name: 'Coaches', chapter: chapter)
coaches_group1.members << member_in_both_groups
coaches_group2.members << member_in_both_groups
end

it 'returns unique members' do
result = manager.send(:chapter_coaches, chapter)

expect(result.count).to eq(1)
expect(result).to contain_exactly(member_in_both_groups)
end
end
end

describe 'sending invitations to members in both students and coaches groups' do
let(:workshop) { Fabricate(:workshop, chapter: chapter) }
let(:students_group) { Fabricate(:group, name: 'Students', chapter: chapter) }
let(:coaches_group) { Fabricate(:group, name: 'Coaches', chapter: chapter) }

before do
students_group.members << member_in_both_groups
coaches_group.members << member_in_both_groups
end

it 'creates one invitation per role when audience is everyone' do
expect do
manager.send_workshop_emails(workshop, 'everyone')
end.to change(WorkshopInvitation, :count).by(2)

student_invitation = WorkshopInvitation.find_by(workshop: workshop, member: member_in_both_groups, role: 'Student')
coach_invitation = WorkshopInvitation.find_by(workshop: workshop, member: member_in_both_groups, role: 'Coach')

expect(student_invitation).to be_present
expect(coach_invitation).to be_present
expect(student_invitation.id).not_to eq(coach_invitation.id)
end
end
end
end