require 'test_helper' module MailSpy class ManagerTest < ActiveSupport::TestCase test "the truth" do assert true end def setup MailSpy::Email.delete_all end # ------------------------------------------- CREATE EMAIL def test_create_email to = "test@test.com" from = "test@test.com" reply_to = "testGuy" subject = "test subject" campaign = "test campaign" stream = "test stream" component = "test component" schedule_at = DateTime.now email = MailSpy.create_email( :to => to, :from => from, :reply_to => reply_to, :subject => subject, :template_values => {}, :campaign => campaign, :stream => stream, :component => component, :schedule_at => schedule_at ) assert(email.to == to, "email subject must be set") assert(email.subject == subject, "email subject must be set") assert(email.campaign == campaign, "email campaign must be set") assert(email.stream == stream, "email stream must be set") assert(email.component == component, "email component must be set") assert(email.schedule_at.to_i == schedule_at.to_i, "email schedule_at must be set") end def test_missing_sender from = "test@test.com" reply_to = "testGuy" subject = "test subject" campaign = "test campaign" stream = "test stream" component = "test component" schedule_at = DateTime.now assert_raise RuntimeError do MailSpy.create_email( :from => from, :reply_to => reply_to, :subject => subject, :template_values => {}, :campaign => campaign, :stream => stream, :component => component, :schedule_at => schedule_at ) end end def test_missing_required_field to = "test@test.com" from = "test@test.com" reply_to = "testGuy" campaign = "test campaign" stream = "test stream" component = "test component" schedule_at = DateTime.now assert_raise RuntimeError do MailSpy.create_email( :to => to, :from => from, :reply_to => reply_to, :template_values => {}, :campaign => campaign, :stream => stream, :component => component, :schedule_at => schedule_at ) end end end def test_referencing_missing_template to = "test@test.com" from = "test@test.com" reply_to = "testGuy" subject = "test subject" campaign = "NO SUCH CAMPAIGN" stream = "NO SUCH STREAM" component = "NO SUCH COMPONENT" schedule_at = DateTime.now assert_raise RuntimeError do MailSpy.create_email( :to => to, :subject => subject, :from => from, :reply_to => reply_to, :template_values => {}, :campaign => campaign, :stream => stream, :component => component, :schedule_at => schedule_at ) end end # ------------------------------------------- SEND_OUTSTANDING_EMAILS #TODO need to document the testing methods for setting up the test_email def test_send_outstanding_emails create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test") num_sent = MailSpy.send_outstanding_emails assert(num_sent == 1, "We should have sent a email") end end