Skip to content

Commit

Permalink
Stats for KYC'd Uphold accounts 🏷 (#1913)
Browse files Browse the repository at this point in the history
* Commit

* Add is_member true to fixture
  • Loading branch information
dlipeles authored May 29, 2019
1 parent 893af9d commit 1339c0a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/controllers/api/v1/stats/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ def channel_uphold_and_email_verified_signups_per_day
render(json: fill_in_blank_dates(result).to_json, status: 200)
end

def channel_and_kyc_uphold_and_email_verified_signups_per_day
sql =
"""
select p.created_at::date, count(*)
from (
select distinct publishers.*
from publishers
inner join channels
on channels.publisher_id = publishers.id and channels.verified = true
inner join uphold_connections
on uphold_connections.publisher_id = publishers.id
where role = 'publisher'
and uphold_connections.uphold_verified = true
and uphold_connections.is_member = true
and email is not null
) as p
group by p.created_at::date
order by p.created_at::date
"""
result = ActiveRecord::Base.connection.execute(sql).values
render(json: fill_in_blank_dates(result).to_json, status: 200)
end

def totals
if params[:up_to_date].present?
up_to_date = Date.parse(params[:up_to_date])
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
get :email_verified_signups_per_day
get :channel_and_email_verified_signups_per_day
get :channel_uphold_and_email_verified_signups_per_day
get :channel_and_kyc_uphold_and_email_verified_signups_per_day
get :javascript_enabled_usage
get :totals
end
Expand Down
19 changes: 19 additions & 0 deletions test/controllers/api/v1/stats/publishers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ class Api::V1::Stats::PublishersControllerTest < ActionDispatch::IntegrationTest
[1.days.ago.to_date.to_s, 0],
[0.days.ago.to_date.to_s, 0]
], JSON.parse(response.body)

get "/api/v1/stats/publishers/channel_and_kyc_uphold_and_email_verified_signups_per_day", headers: { "HTTP_AUTHORIZATION" => "Token token=fake_api_auth_token" }

assert_equal 200, response.status
assert_equal [
[6.days.ago.to_date.to_s, Publisher.distinct.joins(:channels).joins(:uphold_connection)
.where(created_at: 6.days.ago.beginning_of_day..6.days.ago.end_of_day,
'uphold_connections.uphold_verified': true, 'uphold_connections.is_member': true,
role: Publisher::PUBLISHER)
.where.not(email: nil)
.where(channels: { verified: true })
.count],
[5.days.ago.to_date.to_s, 0],
[4.days.ago.to_date.to_s, 0],
[3.days.ago.to_date.to_s, 0],
[2.days.ago.to_date.to_s, 0],
[1.days.ago.to_date.to_s, 0],
[0.days.ago.to_date.to_s, 0]
], JSON.parse(response.body)
end

test "totals endpoint has content" do
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/uphold_connections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ created_connection:
connected_connection:
uphold_verified: true
publisher: uphold_connected
is_member: true

verified_no_currency:
uphold_verified: true
Expand Down

0 comments on commit 1339c0a

Please sign in to comment.