Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Oct 17, 2024
1 parent 0d787f8 commit 5743672
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 111 deletions.
4 changes: 2 additions & 2 deletions app/controllers/organizations/signal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spec/adapters/postmark_adapter/outbound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion spec/adapters/signal_adapter/outbound/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) } }

Expand Down
6 changes: 5 additions & 1 deletion spec/adapters/signal_adapter/outbound/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 9 additions & 4 deletions spec/models/contributor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -925,11 +928,13 @@
{ organization_id: organization.id, contributor_id: contributor.id,
text: "<b>Welcome new contributor!</b>\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
Expand Down
20 changes: 5 additions & 15 deletions spec/requests/admin/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,20 @@
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
subject.call
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
Expand Down
83 changes: 0 additions & 83 deletions spec/requests/organizations/signal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }

Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5743672

Please sign in to comment.