Skip to content

Commit 3da2a7a

Browse files
committed
chore: add group type checks and associations for contacts and conversations
1 parent 65cfeb6 commit 3da2a7a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

spec/models/contact_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,35 @@
196196
end
197197
end
198198
end
199+
200+
describe 'group_type' do
201+
it 'provides type check methods' do
202+
individual_contact = create(:contact, group_type: :individual)
203+
group_contact = create(:contact, group_type: :group)
204+
205+
expect(individual_contact).to be_group_type_individual
206+
expect(group_contact).to be_group_type_group
207+
end
208+
end
209+
210+
describe 'conversation_group_memberships association' do
211+
it 'returns associated group memberships' do
212+
contact = create(:contact)
213+
membership = create(:conversation_group_member, contact: contact)
214+
215+
expect(contact.conversation_group_memberships).to eq([membership])
216+
end
217+
end
218+
219+
describe 'group_conversations association' do
220+
it 'returns conversations through group_memberships' do
221+
contact = create(:contact)
222+
conversation1 = create(:conversation, conversation_type: :group, account: contact.account)
223+
conversation2 = create(:conversation, conversation_type: :group, account: contact.account)
224+
create(:conversation_group_member, contact: contact, conversation: conversation1)
225+
create(:conversation_group_member, contact: contact, conversation: conversation2)
226+
227+
expect(contact.group_conversations).to contain_exactly(conversation1, conversation2)
228+
end
229+
end
199230
end

spec/models/conversation_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,4 +1084,43 @@ def create_bot_message(conversation, created_at: Time.current)
10841084
end
10851085
end
10861086
end
1087+
1088+
describe 'conversation_type' do
1089+
it 'provides type check methods' do
1090+
individual_conversation = create(:conversation, conversation_type: :individual)
1091+
group_conversation = create(:conversation, conversation_type: :group)
1092+
1093+
expect(individual_conversation).to be_conversation_type_individual
1094+
expect(group_conversation).to be_conversation_type_group
1095+
end
1096+
end
1097+
1098+
describe 'group_members association' do
1099+
it 'returns associated group members' do
1100+
conversation = create(:conversation, conversation_type: :group)
1101+
group_member = create(:conversation_group_member, conversation: conversation)
1102+
1103+
expect(conversation.group_members).to eq([group_member])
1104+
end
1105+
end
1106+
1107+
describe 'group_contacts association' do
1108+
it 'returns contacts through group_members' do
1109+
conversation = create(:conversation, conversation_type: :group)
1110+
contact = create(:contact, account: conversation.account)
1111+
create(:conversation_group_member, conversation: conversation, contact: contact)
1112+
1113+
expect(conversation.group_contacts).to eq([contact])
1114+
end
1115+
1116+
it 'returns multiple contacts for group conversations' do
1117+
conversation = create(:conversation, conversation_type: :group)
1118+
contact1 = create(:contact, account: conversation.account)
1119+
contact2 = create(:contact, account: conversation.account)
1120+
create(:conversation_group_member, conversation: conversation, contact: contact1)
1121+
create(:conversation_group_member, conversation: conversation, contact: contact2)
1122+
1123+
expect(conversation.group_contacts).to contain_exactly(contact1, contact2)
1124+
end
1125+
end
10871126
end

0 commit comments

Comments
 (0)