require 'test_helper' module MailSpy class TrackingControllerTest < ActionController::TestCase def setup MailSpy::Email.delete_all create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test") @email = MailSpy::Email.first end def teardown 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 #Load up the generated GA tokens ga_hash = {} email = MailSpy::Email.first ga_hash[:utm_source] = email.utm_source if email.utm_source.present? ga_hash[:utm_medium] = email.utm_medium if email.utm_medium.present? ga_hash[:utm_campaign] = email.utm_campaign if email.utm_campaign.present? ga_hash[:utm_term] = email.utm_term if email.utm_term.present? ga_hash[:utm_content] = email.utm_content if email.utm_content.present? #Parse tokens into uri uri = URI.parse(params[:url]) uri.query = [uri.query, ga_hash.to_param].compact.join('&') assert_redirected_to uri.to_s 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 3") end end end