|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe 'creating a new conversation', :as_platform_manager do |
| 6 | + include BetterTogether::ConversationHelpers |
| 7 | + |
6 | 8 | let!(:user) { create(:better_together_user, :confirmed) } |
7 | 9 |
|
8 | | - scenario 'between a platform manager and normal user' do |
9 | | - visit new_conversation_path(locale: I18n.default_locale) |
10 | | - select "#{user.person.name} - @#{user.person.identifier}", from: 'conversation[participant_ids][]' |
11 | | - fill_in 'conversation[title]', with: Faker::Lorem.sentence(word_count: 3) |
12 | | - click_button 'Create Conversation' |
| 10 | + before do |
| 11 | + # Ensure this person can be messaged by members so they appear in permitted_participants |
| 12 | + user.person.update!(preferences: (user.person.preferences || {}).merge('receive_messages_from_members' => true)) |
| 13 | + end |
| 14 | + |
| 15 | + scenario 'between a platform manager and normal user', :js do |
| 16 | + create_conversation([user.person], first_message: Faker::Lorem.sentence(word_count: 8)) |
13 | 17 | expect(BetterTogether::Conversation.count).to eq(1) |
14 | 18 | end |
15 | 19 |
|
|
20 | 24 |
|
21 | 25 | let(:user2) { create(:better_together_user) } |
22 | 26 |
|
| 27 | + # rubocop:todo RSpec/ExampleLength |
| 28 | + scenario 'can create a conversation with a public person who opted into messages', :js do |
| 29 | + target = create(:better_together_user, :confirmed) |
| 30 | + # Ensure target is public and opted-in to receive messages from members |
| 31 | + target.person.update!(privacy: 'public', |
| 32 | + # rubocop:todo Layout/LineLength |
| 33 | + preferences: (target.person.preferences || {}).merge('receive_messages_from_members' => true)) |
| 34 | + # rubocop:enable Layout/LineLength |
| 35 | + |
| 36 | + expect do |
| 37 | + create_conversation([target.person], first_message: 'Hi there') |
| 38 | + end.to change(BetterTogether::Conversation, :count).by(1) |
| 39 | + end |
| 40 | + # rubocop:enable RSpec/ExampleLength |
| 41 | + |
23 | 42 | it 'cannot create conversations with private users' do |
24 | 43 | visit new_conversation_path(locale: I18n.default_locale) |
25 | 44 | expect('conversation[participant_ids][]').not_to have_content(user2.person.name) # rubocop:todo RSpec/ExpectActual |
|
0 commit comments