Skip to content

Instantly share code, notes, and snippets.

@Levii01
Created May 28, 2020 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Levii01/7b42e5d5759113258ef3cc8df603435a to your computer and use it in GitHub Desktop.
Save Levii01/7b42e5d5759113258ef3cc8df603435a to your computer and use it in GitHub Desktop.
describe 'POST callback' do
subject(:post_callback) { post :callback, params: params }
context 'with order uuid' do
let(:params) { { orderUuid: bank_account.verification_identifier } }
let(:bank_account) { create :bank_account }
it 'bank account found' do
expect(Sidekiq::Extensions::DelayedClass.jobs.size).to eq 0
post_callback
expect(Sidekiq::Extensions::DelayedClass.jobs.size).to eq 1
expect(BankAccount.method :get_verification_result!).to be_delayed(bank_account.id)
end
it { is_expected.to have_http_status(:ok) }
end
context 'without order uuid' do
let(:params) { { orderUuid: 'not existing' } }
it 'bank account not found' do
post_callback
expect(BankAccount.method :get_verification_result!).not_to be_delayed
end
it { is_expected.to have_http_status(:ok) }
end
context 'whitelists IPs' do
subject { post :callback }
context 'production enviroment' do
before { allow(Rails.env).to receive(:production?).and_return(true) }
it { is_expected.to have_http_status :forbidden }
context 'with allowed ip' do
before { allow_any_instance_of(ActionDispatch::Request).to receive(:ip).and_return('195.182.23.106') }
it { is_expected.not_to have_http_status :forbidden }
end
end
context 'another environment' do
it { is_expected.not_to have_http_status :forbidden }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment