Skip to content

Commit 4559000

Browse files
committed
Update spec after sender activity creation changes
1 parent 5b47980 commit 4559000

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

spec/services/email_ingestor_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
end
9494

9595
context "activity creation" do
96-
it "creates activities for users who have starred the topic" do
96+
it "creates activities for users who have starred the topic (excluding sender)" do
9797
sender_alias = create(:alias, email: "sender@example.com", user: user1)
9898
allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([sender_alias])
9999

@@ -109,15 +109,16 @@
109109
allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([reply_sender_alias])
110110

111111
reply_message = nil
112+
# Activities created for user1 and user2 (not reply_sender since they're the sender)
112113
expect {
113114
reply_message = ingestor.ingest_raw(reply_email)
114-
}.to change { Activity.where(activity_type: "topic_message_received").count }.by(3)
115+
}.to change { Activity.where(activity_type: "topic_message_received").count }.by(2)
115116

116117
activities = Activity.where(activity_type: "topic_message_received", subject: reply_message)
117-
expect(activities.pluck(:user_id)).to match_array([user1.id, user2.id, reply_sender.id])
118+
expect(activities.pluck(:user_id)).to match_array([user1.id, user2.id])
118119
end
119120

120-
it "marks sender's activity as read when they have topic starred" do
121+
it "does not create activity for the sender even if they starred the topic" do
121122
sender_alias = create(:alias, email: "sender@example.com", user: user1)
122123
allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([sender_alias])
123124

@@ -129,12 +130,16 @@
129130
reply_email = raw_email.gsub("<test123@example.com>", "<reply456@example.com>")
130131
reply_email = reply_email.gsub("Subject: Test Subject", "Subject: Re: Test Subject\nIn-Reply-To: <test123@example.com>")
131132

132-
ingestor.ingest_raw(reply_email)
133+
# user1 is the sender of the reply (build_from_aliases still returns sender_alias)
134+
reply_message = ingestor.ingest_raw(reply_email)
133135

134-
sender_activity = Activity.find_by(user: user1, activity_type: "topic_message_received")
135-
expect(sender_activity.read_at).to be_present
136+
# Sender (user1) should not get an activity
137+
sender_activity = Activity.find_by(user: user1, activity_type: "topic_message_received", subject: reply_message)
138+
expect(sender_activity).to be_nil
136139

137-
other_activity = Activity.find_by(user: user2, activity_type: "topic_message_received")
140+
# Other starred user (user2) should get an unread activity
141+
other_activity = Activity.find_by(user: user2, activity_type: "topic_message_received", subject: reply_message)
142+
expect(other_activity).to be_present
138143
expect(other_activity.read_at).to be_nil
139144
end
140145

0 commit comments

Comments
 (0)