diff --git a/app/controllers/organizations/signal_controller.rb b/app/controllers/organizations/signal_controller.rb index c7c004344..9c04fcef1 100644 --- a/app/controllers/organizations/signal_controller.rb +++ b/app/controllers/organizations/signal_controller.rb @@ -6,7 +6,7 @@ def captcha_form; end def register response = SignalAdapter::RegisterPhoneNumberService.new(organization_id: @organization.id, register_data: register_data).call - Rails.logger.debug JSON.parse(response.body) + Rails.logger.debug JSON.parse(response.body) if response.body.present? case response when Net::HTTPSuccess redirect_to organization_signal_verify_path @@ -21,7 +21,7 @@ def verify_form; end def verify token = params[:organization][:signal][:token] response = SignalAdapter::VerifyPhoneNumberService.new(organization_id: @organization.id, token: token).call - Rails.logger.debug JSON.parse(response.body) + Rails.logger.debug JSON.parse(response.body) if response.body.present? case response when Net::HTTPSuccess SignalAdapter::SetTrustModeJob.perform_later(signal_server_phone_number: @organization.signal_server_phone_number) diff --git a/spec/adapters/postmark_adapter/outbound_spec.rb b/spec/adapters/postmark_adapter/outbound_spec.rb index 7dd01cb9d..09073ad57 100644 --- a/spec/adapters/postmark_adapter/outbound_spec.rb +++ b/spec/adapters/postmark_adapter/outbound_spec.rb @@ -52,7 +52,7 @@ describe 'with(message: message, organization: message.organization)' do let(:adapter) { described_class.with(message: message, organization: message.organization) } - let(:organization) { create(:organization, email_from_address: '100eyes-test-account@example.org', project_name: 'TestingProject') } + let!(:organization) { create(:organization, email_from_address: '100eyes-test-account@example.org', project_name: 'TestingProject') } let(:request) { create(:request, id: 4711, organization: organization) } let(:recipient) { create(:contributor, email: email_address) } let(:email_address) { 'recipient@example.org' } @@ -291,7 +291,7 @@ context 'no admin' do let(:admin) { nil } - let(:contributor) { create(:contributor) } + let(:contributor) { create(:contributor, organization: organization) } it 'does not enqueue a Mailer' do expect { subject }.not_to have_enqueued_job @@ -309,7 +309,7 @@ context 'user without an admin role' do let(:admin) { build(:user) } - let(:contributor) { create(:contributor) } + let(:contributor) { create(:contributor, organization: organization) } it 'does not enqueue a Mailer' do expect { subject }.not_to have_enqueued_job @@ -318,7 +318,7 @@ context 'admin email equals contributor email' do let(:admin) { create(:user, admin: true, email: 'my-email@example.org') } - let(:contributor) { create(:contributor, email: 'my-email@example.org') } + let(:contributor) { create(:contributor, email: 'my-email@example.org', organization: organization) } it 'does not enqueue a Mailer' do expect { subject }.not_to have_enqueued_job diff --git a/spec/adapters/signal_adapter/outbound/file_spec.rb b/spec/adapters/signal_adapter/outbound/file_spec.rb index 3f6cbd310..d800351c4 100644 --- a/spec/adapters/signal_adapter/outbound/file_spec.rb +++ b/spec/adapters/signal_adapter/outbound/file_spec.rb @@ -6,7 +6,12 @@ RSpec.describe SignalAdapter::Outbound::File do let(:adapter) { described_class.new } let(:contributor) { create(:contributor, signal_phone_number: '+4915112345678', email: nil) } - let(:request) { create(:request, organization: create(:organization, signal_server_phone_number: 'SIGNAL_SERVER_PHONE_NUMBER')) } + let(:organization) do + build(:organization, signal_server_phone_number: 'SIGNAL_SERVER_PHONE_NUMBER').tap do |org| + org.save(validate: false) + end + end + let(:request) { create(:request, organization: organization) } let(:message) { create(:message, :with_file, recipient: contributor, text: 'Hello Signal', request: request) } let(:perform) { -> { adapter.perform(message: message) } } diff --git a/spec/adapters/signal_adapter/outbound/text_spec.rb b/spec/adapters/signal_adapter/outbound/text_spec.rb index 516af151f..411b0d8fa 100644 --- a/spec/adapters/signal_adapter/outbound/text_spec.rb +++ b/spec/adapters/signal_adapter/outbound/text_spec.rb @@ -5,7 +5,11 @@ RSpec.describe SignalAdapter::Outbound::Text do let(:adapter) { described_class.new } - let(:organization) { create(:organization, signal_server_phone_number: 'SIGNAL_SERVER_PHONE_NUMBER') } + let(:organization) do + build(:organization, signal_server_phone_number: 'SIGNAL_SERVER_PHONE_NUMBER').tap do |org| + org.save(validate: false) + end + end let(:contributor) { create(:contributor, signal_phone_number: '+4915112345678', email: nil, organization: organization) } let(:message) { create(:message, :with_file, text: 'Hello Signal') } let(:organization_id) { organization.id } diff --git a/spec/models/contributor_spec.rb b/spec/models/contributor_spec.rb index 4410b1182..82c629d80 100644 --- a/spec/models/contributor_spec.rb +++ b/spec/models/contributor_spec.rb @@ -913,10 +913,13 @@ describe '.send_welcome_message!', telegram_bot: :rails do subject { -> { contributor.send_welcome_message!(organization) } } - let(:organization) do + let!(:organization) do create(:organization, onboarding_success_heading: 'Welcome new contributor!', onboarding_success_text: 'You onboarded successfully.') end - let(:contributor) { create(:contributor, telegram_id: nil, email: nil, threema_id: nil) } + let(:contributor) do + create(:contributor, telegram_id: nil, email: nil, threema_id: nil, signal_phone_number: nil, whats_app_phone_number: nil, + organization: organization) + end it { should_not have_enqueued_job } @@ -925,11 +928,13 @@ { organization_id: organization.id, contributor_id: contributor.id, text: "Welcome new contributor!\nYou onboarded successfully." } end - let(:contributor) { create(:contributor, telegram_id: nil, telegram_onboarding_token: 'ABCDEF', email: nil) } + let(:contributor) do + create(:contributor, telegram_id: nil, telegram_onboarding_token: 'ABCDEF', email: nil, organization: organization) + end it { should_not have_enqueued_job } context 'and connected' do - let(:contributor) { create(:contributor, telegram_id: 4711, telegram_onboarding_token: 'ABCDEF', email: nil) } + let(:contributor) { create(:contributor, :telegram_contributor, organization: organization) } it { should enqueue_job(TelegramAdapter::Outbound::Text).with(expected_job_args) } end end diff --git a/spec/requests/admin/organization_spec.rb b/spec/requests/admin/organization_spec.rb index 7a9ff5167..16577ce23 100644 --- a/spec/requests/admin/organization_spec.rb +++ b/spec/requests/admin/organization_spec.rb @@ -96,17 +96,10 @@ end end - context 'WhatsApp Twilio' do - let(:whats_app_params) do - { - whats_app_server_phone_number: '+4912345678', - twilio_account_sid: 'valid_account_sid', - twilio_api_key_sid: 'valid_api_key_sid', - twilio_api_key_secret: 'valid_secret' - } - end + context 'Signal' do + let(:signal_params) { { signal_server_phone_number: '+4912345678' } } let(:params) do - required_params.deep_merge({ organization: whats_app_params }) + required_params.deep_merge({ organization: signal_params }) end it 'allows configuration of Twilio specific attrs' do @@ -114,12 +107,9 @@ follow_redirect! expect(page).to have_content('+4912345678') - expect(page).to have_content('valid_account_sid') - expect(page).to have_content('valid_api_key_sid') - expect(page).not_to have_content('valid_secret') - organization = Organization.find_by(whats_app_server_phone_number: '+4912345678') - expect(organization).to have_attributes(whats_app_params) + organization = Organization.find_by(signal_server_phone_number: '+4912345678') + expect(organization).to have_attributes(signal_params) end end end diff --git a/spec/requests/organizations/signal_spec.rb b/spec/requests/organizations/signal_spec.rb index 7d0f71781..1ee5a5641 100644 --- a/spec/requests/organizations/signal_spec.rb +++ b/spec/requests/organizations/signal_spec.rb @@ -6,89 +6,6 @@ RSpec.describe 'Signal' do let(:organization) { create(:organization, signal_server_phone_number: nil) } - describe 'GET /:organization_id/add-signal' do - subject { -> { get organization_signal_add_path(organization, as: user) } } - - context 'unauthenticated' do - let(:user) { nil } - - it 'renders not found ' do - subject.call - expect(response).to be_not_found - end - end - - context 'unauthorized' do - let(:user) { create(:user, admin: false, organizations: [organization]) } - - it 'renders not found ' do - subject.call - expect(response).to be_not_found - end - end - - context 'authenticated and authorized' do - let(:user) { create(:user, admin: true) } - - it 'should be successful' do - subject.call - expect(response).to be_successful - end - - it 'renders a form to add signal_server_phone_number' do - subject.call - expect(page).to have_css("form[action='/#{organization.id}/signal/add']") do |form| - expect(form).to have_css('input[id="organization[signal_server_phone_number]"]') - end - end - end - end - - describe 'PATCH /:organization_id/add-signal' do - subject { -> { patch organization_signal_add_path(organization, as: user), params: params } } - - let(:params) { { organization: { signal_server_phone_number: '+4912345678' } } } - - context 'unauthenticated' do - let(:user) { nil } - - it 'renders not found ' do - subject.call - expect(response).to be_not_found - end - end - - context 'unauthorized' do - let(:user) { create(:user, admin: false, organizations: [organization]) } - - it 'renders not found ' do - subject.call - expect(response).to be_not_found - end - end - - context 'authenticated and authorized' do - let(:user) { create(:user, admin: true) } - - it "updates the organization's signal_server_phone_number" do - expect { subject.call }.to (change { organization.reload.signal_server_phone_number }).from(nil).to('+4912345678') - end - - it 'redirects to /signal/register' do - subject.call - expect(response).to redirect_to(organization_signal_register_path(organization)) - end - - it 'renders a form to register' do - subject.call - follow_redirect! - expect(page).to have_css("form[action='/#{organization.id}/signal/register']") do |form| - expect(form).to have_css('input[id="organization[signal][captcha]"]') - end - end - end - end - describe 'POST /:organization_id/signal/register' do subject { -> { post organization_signal_register_path(organization, as: user), params: params } } diff --git a/spec/system/admin/auth_spec.rb b/spec/system/admin/auth_spec.rb index d791f8c9a..1a72d9040 100644 --- a/spec/system/admin/auth_spec.rb +++ b/spec/system/admin/auth_spec.rb @@ -23,6 +23,6 @@ expect(page).to have_http_status(:ok) - expect(page).to have_link('New user') + expect(page).to have_link('New organization') end end