2020-03-23 20:46:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ContactControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@rol = create :rol
|
|
|
|
@site = @rol.site
|
|
|
|
@usuarie = @rol.usuarie
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
@site&.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'el sitio tiene que existir' do
|
|
|
|
@site.destroy
|
|
|
|
|
|
|
|
post v1_site_contact_url(@site),
|
|
|
|
params: {
|
|
|
|
name: SecureRandom.hex,
|
|
|
|
pronouns: SecureRandom.hex,
|
|
|
|
contact: SecureRandom.hex,
|
|
|
|
from: "#{SecureRandom.hex}@sutty.nl",
|
|
|
|
body: SecureRandom.hex,
|
|
|
|
gdpr: true
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_response :unprocessable_entity, response.status
|
|
|
|
assert_equal 'site_exists', response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'hay que enviar desde el sitio principal' do
|
|
|
|
post v1_site_contact_url(@site),
|
|
|
|
params: {
|
|
|
|
name: SecureRandom.hex,
|
|
|
|
pronouns: SecureRandom.hex,
|
|
|
|
contact: SecureRandom.hex,
|
|
|
|
from: "#{SecureRandom.hex}@sutty.nl",
|
|
|
|
body: SecureRandom.hex,
|
|
|
|
gdpr: true
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_response :unprocessable_entity, response.status
|
|
|
|
assert_equal 'site_is_origin', response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'hay que dar consentimiento' do
|
|
|
|
post v1_site_contact_url(@site),
|
|
|
|
headers: {
|
|
|
|
Origin: @site.url
|
|
|
|
},
|
|
|
|
params: {
|
|
|
|
name: SecureRandom.hex,
|
|
|
|
pronouns: SecureRandom.hex,
|
|
|
|
contact: SecureRandom.hex,
|
|
|
|
from: "#{SecureRandom.hex}@sutty.nl",
|
|
|
|
body: SecureRandom.hex
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_response :unprocessable_entity, response.status
|
|
|
|
assert_equal 'gave_consent', response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'enviar un mensaje genera correos' do
|
2020-03-25 18:36:06 +00:00
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
|
|
|
redirect = "#{@site.url}/?thanks"
|
|
|
|
|
2020-03-23 20:46:19 +00:00
|
|
|
10.times do
|
|
|
|
create :rol, site: @site
|
|
|
|
end
|
|
|
|
|
2020-03-25 18:36:06 +00:00
|
|
|
post v1_site_contact_url(site_id: @site.hostname),
|
2020-03-23 20:46:19 +00:00
|
|
|
headers: {
|
|
|
|
Origin: @site.url
|
|
|
|
},
|
|
|
|
params: {
|
|
|
|
name: SecureRandom.hex,
|
|
|
|
pronouns: SecureRandom.hex,
|
|
|
|
contact: SecureRandom.hex,
|
|
|
|
from: "#{SecureRandom.hex}@sutty.nl",
|
|
|
|
body: SecureRandom.hex,
|
2020-03-25 18:36:06 +00:00
|
|
|
gdpr: true,
|
|
|
|
redirect: redirect
|
2020-03-23 20:46:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 18:36:06 +00:00
|
|
|
assert_equal redirect, response.headers['Location']
|
2020-03-23 20:46:19 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|