Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data transfer metrics 187183620 #4441

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def self.show?(_intake)
end

def edit
current_intake.state_file_analytics.update!(
canceled_data_transfer_count: current_intake.state_file_analytics.canceled_data_transfer_count + 1
)
@fake_data_transfer_link = fake_data_transfer_link
@irs_df_transfer_link = irs_df_transfer_link
@go_back_link = case current_intake.state_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ class InitiateDataTransferController < QuestionsController
include IrsDataTransferLinksConcern

def edit
if current_intake.state_file_analytics.initiate_data_transfer_first_visit_at.nil?
current_intake.state_file_analytics.update!(initiate_data_transfer_first_visit_at: DateTime.now)
end
@fake_data_transfer_link = fake_data_transfer_link
@irs_df_transfer_link = irs_df_transfer_link
@irs_df_transfer_link_present = irs_df_transfer_link.present?
end

def initiate_data_transfer
current_intake.state_file_analytics.update(
initiate_df_data_transfer_clicks: current_intake.state_file_analytics.initiate_df_data_transfer_clicks + 1
)
redirect_to irs_df_transfer_link, allow_other_host: true
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def update
referrer: session[:referrer]
)
intake.save
intake.create_state_file_analytics!
sign_in intake
redirect_to next_path
end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/state_file/questions/name_dob_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ module Questions
class NameDobController < AuthenticatedQuestionsController
include ReturnToReviewConcern

def edit
if current_intake.state_file_analytics.name_dob_first_visit_at.nil?
current_intake.state_file_analytics.update!(name_dob_first_visit_at: DateTime.now)
end
super
end

private

def form_params
Expand Down
42 changes: 22 additions & 20 deletions app/models/state_file_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
#
# Table name: state_file_analytics
#
# id :bigint not null, primary key
# dependent_tax_credit :integer
# empire_state_child_credit :integer
# excise_credit :integer
# family_income_tax_credit :integer
# fed_eitc_amount :integer
# filing_status :integer
# household_fed_agi :integer
# nyc_eitc :integer
# nyc_household_credit :integer
# nyc_school_tax_credit :integer
# nys_eitc :integer
# nys_household_credit :integer
# record_type :string not null
# refund_or_owed_amount :integer
# created_at :datetime not null
# updated_at :datetime not null
# record_id :bigint not null
# id :bigint not null, primary key
# canceled_data_transfer_count :integer default(0)
# dependent_tax_credit :integer
# empire_state_child_credit :integer
# excise_credit :integer
# family_income_tax_credit :integer
# fed_eitc_amount :integer
# filing_status :integer
# household_fed_agi :integer
# initiate_data_transfer_first_visit_at :datetime
# initiate_df_data_transfer_clicks :integer default(0)
# name_dob_first_visit_at :datetime
# nyc_eitc :integer
# nyc_household_credit :integer
# nyc_school_tax_credit :integer
# nys_eitc :integer
# nys_household_credit :integer
# record_type :string not null
# refund_or_owed_amount :integer
# created_at :datetime not null
# updated_at :datetime not null
# record_id :bigint not null
#
# Indexes
#
# index_state_file_analytics_on_record (record_type,record_id)
#
class StateFileAnalytics < ApplicationRecord
belongs_to :record, polymorphic: true
before_create :calculated_attrs

def calculated_attrs
attributes = {
Expand All @@ -37,6 +40,5 @@ def calculated_attrs
household_fed_agi: record.direct_file_data.fed_agi
}
attributes.merge!(record.calculator&.analytics_attrs || {})
assign_attributes(attributes)
end
end
2 changes: 1 addition & 1 deletion app/models/state_file_base_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StateFileBaseIntake < ApplicationRecord
has_many :efile_device_infos, -> { order(created_at: :asc) }, as: :intake, class_name: 'StateFileEfileDeviceInfo', inverse_of: :intake, dependent: :destroy
has_many :state_file_w2s, as: :state_file_intake, class_name: "StateFileW2", inverse_of: :state_file_intake, dependent: :destroy
has_many :df_data_import_errors, -> { order(created_at: :asc) }, as: :state_file_intake, class_name: "DfDataImportError", inverse_of: :state_file_intake, dependent: :destroy
has_one :state_file_analytics, as: :record
has_one :state_file_analytics, as: :record, dependent: :destroy
belongs_to :primary_state_id, class_name: "StateId", optional: true
belongs_to :spouse_state_id, class_name: "StateId", optional: true
accepts_nested_attributes_for :primary_state_id, :spouse_state_id
Expand Down
4 changes: 1 addition & 3 deletions app/state_machines/efile_submission_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ class EfileSubmissionStateMachine
# NOTE: a submission can have multiple successive :transmitted states, each with different
# response XML
analytics = submission.data_source.state_file_analytics
if analytics.blank?
submission.data_source.create_state_file_analytics!
end
analytics&.update(analytics.calculated_attrs)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<% end %>
<% end %>

<% if @irs_df_transfer_link.present? %>
<% if @irs_df_transfer_link_present %>
<% if Rails.env.production? %>
<%= link_to @irs_df_transfer_link.to_s, class: "button button--primary button--icon", id: "firstCta" do %>
<%= link_to StateFile::Questions::InitiateDataTransferController.to_path_helper(action: :initiate_data_transfer, us_state: current_intake.state_code), class: "button button--primary button--icon", id: "firstCta" do %>
<%= image_tag("icons/link-white.svg", alt: "") %>
<%= t(".from_irs") %>
<% end %>
<% else %>
<%= link_to @irs_df_transfer_link.to_s, class: "button button--icon text--small button--full-width", id: "firstCta" do %>
<%= link_to StateFile::Questions::InitiateDataTransferController.to_path_helper(action: :initiate_data_transfer, us_state: current_intake.state_code), class: "button button--icon text--small button--full-width", id: "firstCta" do %>
<%= t(".from_irs_testing") %>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def scoped_navigation_routes(context, navigation)
resources :federal_dependents, only: [:index, :new, :create, :edit, :update, :destroy], module: 'state_file/questions', path: 'questions/federal_dependents'
resources :unemployment, only: [:index, :new, :create, :edit, :update, :destroy], module: 'state_file/questions', path: 'questions/unemployment'
get "/data-import-failed", to: "state_file/state_file_pages#data_import_failed"
get "/initiate-data-transfer", to: "state_file/questions/initiate_data_transfer#initiate_data_transfer"
end

scope ':us_state', constraints: { us_state: /az|ny|us/i } do
Expand Down
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_03_19_194733) do

ActiveRecord::Schema[7.1].define(version: 2024_04_03_214006) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "plpgsql"
Expand Down Expand Up @@ -1592,6 +1593,7 @@
end

create_table "state_file_analytics", force: :cascade do |t|
t.integer "canceled_data_transfer_count", default: 0
t.datetime "created_at", null: false
t.integer "dependent_tax_credit"
t.integer "empire_state_child_credit"
Expand All @@ -1600,6 +1602,9 @@
t.integer "fed_eitc_amount"
t.integer "filing_status"
t.integer "household_fed_agi"
t.datetime "initiate_data_transfer_first_visit_at"
t.integer "initiate_df_data_transfer_clicks", default: 0
t.datetime "name_dob_first_visit_at"
t.integer "nyc_eitc"
t.integer "nyc_household_credit"
t.integer "nyc_school_tax_credit"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.describe StateFile::Questions::CanceledDataTransferController do
let(:intake) { create :state_file_az_intake }
before do
sign_in intake
end

describe "#edit" do
context "when the client visits this page" do
it "increments the counter" do
state_file_analytics = intake.state_file_analytics
state_file_analytics.update(canceled_data_transfer_count: 1)

expect {
get :edit, params: { us_state: 'az' }
state_file_analytics.reload
}.to change(state_file_analytics, :canceled_data_transfer_count)

expect(state_file_analytics.canceled_data_transfer_count).to eq 2
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'rails_helper'

RSpec.describe StateFile::Questions::InitiateDataTransferController do
let(:intake) { create :state_file_ny_intake }
let(:state_file_analytics) { intake.state_file_analytics }
before do
sign_in intake
end

describe "#edit" do
context "when it is the client's first visit to this page" do
it "saves the timestamp for the first visit" do
expect {
get :edit, params: { us_state: 'ny' }
state_file_analytics.reload
}.to change(state_file_analytics, :initiate_data_transfer_first_visit_at)

expect(state_file_analytics.initiate_data_transfer_first_visit_at).to be_within(1.second).of(DateTime.now)
end
end

context "when it is not the client's first visit to the page" do
it "does nothing" do
state_file_analytics.update(initiate_data_transfer_first_visit_at: 1.day.ago)
expect {
get :edit, params: { us_state: 'ny' }
state_file_analytics.reload
}.not_to change(state_file_analytics, :initiate_data_transfer_first_visit_at)
end
end

context "it has a link to initiate_data_transfer when irs_df_transfer_link returns a link" do
render_views

it "has a link to the initiate_data_transfer action (which redirects to the right data transfer link)" do
df_link = "https://fake-df-transfer.gov"
allow(subject).to receive(:irs_df_transfer_link).and_return(df_link)
get :edit, params: { us_state: 'ny' }

expect(response.body).to have_link(href: described_class.to_path_helper(action: :initiate_data_transfer, us_state: 'ny'))
end
end
end

describe "#initiate_data_transfer" do
it "increments the count of clicks on data transfer and redirects to direct file" do
df_link = "https://fake-df-transfer.gov"
allow(subject).to receive(:irs_df_transfer_link).and_return(df_link)
get :initiate_data_transfer, params: { us_state: 'ny' }

expect(state_file_analytics.reload.initiate_df_data_transfer_clicks).to eq 1
expect(response).to redirect_to df_link
end
end
end
25 changes: 25 additions & 0 deletions spec/controllers/state_file/questions/name_dob_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@
end
end
end

describe "#edit" do
let(:state_file_analytics) { intake.state_file_analytics }

context "when it is the client's first visit to this page" do
it "saves the timestamp for the first visit" do
expect {
get :edit, params: { us_state: 'az' }
state_file_analytics.reload
}.to change(state_file_analytics, :name_dob_first_visit_at)

expect(state_file_analytics.name_dob_first_visit_at).to be_within(1.second).of(DateTime.now)
end
end

context "when it is not the client's first visit to the page" do
it "does nothing" do
state_file_analytics.update(name_dob_first_visit_at: 1.day.ago)
expect {
get :edit, params: { us_state: 'az' }
state_file_analytics.reload
}.not_to change(state_file_analytics, :name_dob_first_visit_at)
end
end
end
end
1 change: 1 addition & 0 deletions spec/factories/state_file_az_intakes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
raw_direct_file_data { File.read(Rails.root.join('app', 'controllers', 'state_file', 'questions', 'df_return_sample.xml')) }
primary_first_name { "Ariz" }
primary_last_name { "Onian" }
state_file_analytics { StateFileAnalytics.create }

after(:build) do |intake, evaluator|
numeric_status = {
Expand Down
1 change: 1 addition & 0 deletions spec/factories/state_file_ny_intakes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
permanent_city { direct_file_data.mailing_city }
permanent_zip { direct_file_data.mailing_zip }
nyc_residency { 'full_year' }
state_file_analytics { StateFileAnalytics.create }

after(:build) do |intake, evaluator|
numeric_status = {
Expand Down
1 change: 1 addition & 0 deletions spec/features/state_file/data_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
click_on I18n.t("state_file.questions.terms_and_conditions.edit.accept")

step_through_df_data_transfer

expect(page).to have_text "Your federal tax return is now transferred."
end
end
Loading
Loading