|
93 | 93 | end |
94 | 94 |
|
95 | 95 | 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 |
97 | 97 | sender_alias = create(:alias, email: "sender@example.com", user: user1) |
98 | 98 | allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([sender_alias]) |
99 | 99 |
|
|
109 | 109 | allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([reply_sender_alias]) |
110 | 110 |
|
111 | 111 | reply_message = nil |
| 112 | + # Activities created for user1 and user2 (not reply_sender since they're the sender) |
112 | 113 | expect { |
113 | 114 | 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) |
115 | 116 |
|
116 | 117 | 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]) |
118 | 119 | end |
119 | 120 |
|
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 |
121 | 122 | sender_alias = create(:alias, email: "sender@example.com", user: user1) |
122 | 123 | allow_any_instance_of(described_class).to receive(:build_from_aliases).and_return([sender_alias]) |
123 | 124 |
|
|
129 | 130 | reply_email = raw_email.gsub("<test123@example.com>", "<reply456@example.com>") |
130 | 131 | reply_email = reply_email.gsub("Subject: Test Subject", "Subject: Re: Test Subject\nIn-Reply-To: <test123@example.com>") |
131 | 132 |
|
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) |
133 | 135 |
|
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 |
136 | 139 |
|
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 |
138 | 143 | expect(other_activity.read_at).to be_nil |
139 | 144 | end |
140 | 145 |
|
|
0 commit comments