-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'user-mentions' into staging
- Loading branch information
Showing
3 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Mentionable, type: :module do | ||
let(:chat_message) { create(:chat_message, content: content) } | ||
|
||
describe Mentionable::MentionsStruct do | ||
subject { Mentionable::MentionsStruct.new(instance: chat_message) } | ||
|
||
context 'when content contains HTML' do | ||
let(:content) { '<p>Hello, <a href="https://preprod.entourage.social/app/users/123">User</a></p>' } | ||
|
||
it 'detects HTML content' do | ||
expect(subject.contains_html?).to be true | ||
end | ||
|
||
it 'detects an anchor with href' do | ||
expect(subject.contains_anchor_with_href?).to be true | ||
end | ||
|
||
it 'detects a user link' do | ||
expect(subject.contains_user_link?).to be true | ||
end | ||
|
||
it 'extracts user UUIDs' do | ||
expect(subject.extract_user_uuid).to eq(['123']) | ||
end | ||
|
||
it 'removes HTML for no_html' do | ||
expect(subject.no_html).to eq('Hello, User') | ||
end | ||
end | ||
|
||
context 'when content does not contain HTML' do | ||
let(:content) { 'Hello, User' } | ||
|
||
it 'does not detect HTML content' do | ||
expect(subject.contains_html?).to be false | ||
end | ||
|
||
it 'does not detect an anchor with href' do | ||
expect(subject.contains_anchor_with_href?).to be false | ||
end | ||
|
||
it 'does not detect a user link' do | ||
expect(subject.contains_user_link?).to be false | ||
end | ||
|
||
it 'extracts no user UUIDs' do | ||
expect(subject.extract_user_uuid).to eq([]) | ||
end | ||
end | ||
end | ||
|
||
describe '#has_mentions?' do | ||
subject { chat_message } | ||
|
||
context 'when there are user mentions' do | ||
let(:content) { '<a href="https://preprod.entourage.social/app/users/456">John</a>' } | ||
|
||
it { } | ||
end | ||
|
||
context 'when there are no user mentions' do | ||
let(:content) { '<a href="https://preprod.entourage.social/app/groups/123">Group</a>' } | ||
|
||
it { expect(subject.has_mentions?).to be false } | ||
end | ||
end | ||
|
||
describe '#has_mentions!' do | ||
subject { chat_message } | ||
|
||
context 'when there are user mentions' do | ||
let(:content) { '<a href="https://preprod.entourage.social/app/users/789">Doe</a>' } | ||
|
||
it 'triggers a push notification' do | ||
expect(PushNotificationTrigger).to receive(:new) | ||
.with(subject, :mention, {}) | ||
.and_call_original | ||
|
||
subject.send(:has_mentions!) | ||
end | ||
end | ||
|
||
context 'when there are no user mentions' do | ||
let(:content) { 'No user mentions here.' } | ||
|
||
it 'does not trigger a push notification' do | ||
expect(PushNotificationTrigger).not_to receive(:new).with(subject, :mention, {}) | ||
|
||
subject.send(:has_mentions!) | ||
end | ||
end | ||
end | ||
end |