require 'test_helper' module MailSpy class TrackingControllerTest < ActionController::TestCase def setup initialize_mail_spy_test_esp html_erb = "A link : <%= track_link 'My home', 'www.google.com' %>
A Bug <%= tracking_bug %>" text_erb = "A link : <%= track_link 'My home', 'www.google.com' %>
A Bug <%= tracking_bug %>" template_values_definition = {} template = MailSpy.create_template("a test template", html_erb, text_erb, template_values_definition) create_emails(template) @email = MailSpy::Email.first end def teardown MailSpy::EmailTemplate.delete_all MailSpy::Email.delete_all end test "the truth" do assert true end def test_link_tracking params = { :eid => @email.id, :url =>"http://google.com", :n => 0 } get "link", params assert_redirected_to params[:url] email = @email.reload details = email.actions.first.details assert(email.actions.length == 1, "The email should only have on action at this point") assert(email.actions.first.action_type == MailSpy::Action::ACTION_TYPE_CLICK,"Action type should be click") assert(details[:url] == params[:url], "Url should be recorded") assert(details[:link_number].to_i == params[:n].to_i, "link number should be recorded") assert(email.actions.first.count == 1, "the action count should be 1") end def test_bug_tracking params = { :eid => @email.id, } get "bug", params assert_response :success email = @email.reload assert(email.actions.length == 1, "The email should only have on action at this point") assert(email.actions.first.action_type == MailSpy::Action::ACTION_TYPE_OPEN,"Action type should be open") assert(email.actions.first.count == 1, "the action count should be 1") end def test_action_tracking params = { :eid => @email.id, :action_type => "Conversion", :count => 3 } get "action", params assert_response :success email = @email.reload assert(email.actions.length == 1, "The email should only have on action at this point") assert(email.actions.first.action_type == params[:action_type],"Action type should be conversion") assert(email.actions.first.count == params[:count], "the action count should be 1") end end end