2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-06-07 10:06:40 +02:00
|
|
|
describe EmailCheckerController, type: :controller do
|
|
|
|
describe '#show' do
|
|
|
|
render_views
|
|
|
|
before { get :show, format: :json, params: params }
|
|
|
|
let(:body) { JSON.parse(response.body, symbolize_names: true) }
|
|
|
|
|
|
|
|
context 'valid email' do
|
|
|
|
let(:params) { { email: 'martin@orange.fr' } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(body).to eq({ success: true })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'email with typo' do
|
|
|
|
let(:params) { { email: 'martin@orane.fr' } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
2024-07-01 10:38:43 +02:00
|
|
|
expect(body).to eq({ success: true, suggestions: ['martin@orange.fr'] })
|
2024-06-07 10:06:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'empty' do
|
|
|
|
let(:params) { { email: '' } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(body).to eq({ success: false })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'notanemail' do
|
|
|
|
let(:params) { { email: 'clarkkent' } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(body).to eq({ success: false })
|
|
|
|
end
|
|
|
|
end
|
2024-06-17 13:25:28 +02:00
|
|
|
|
|
|
|
context 'incomplete' do
|
|
|
|
let(:params) { { email: 'bikram.subedi81@' } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(body).to eq({ success: false })
|
|
|
|
end
|
|
|
|
end
|
2024-10-18 16:22:13 +02:00
|
|
|
|
|
|
|
context 'malformed' do
|
|
|
|
let(:params) { { email: { some: 'hash' } } }
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(body).to eq({ success: false })
|
|
|
|
end
|
|
|
|
end
|
2024-06-07 10:06:40 +02:00
|
|
|
end
|
|
|
|
end
|