From 1339c0aeca2b3299d2d104550307cfd85c270d84 Mon Sep 17 00:00:00 2001 From: "Dan A. Lipeles" Date: Wed, 29 May 2019 12:29:20 -0400 Subject: [PATCH] =?UTF-8?q?Stats=20for=20KYC'd=20Uphold=20accounts=20?= =?UTF-8?q?=F0=9F=8F=B7=20=20(#1913)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Commit * Add is_member true to fixture --- .../api/v1/stats/publishers_controller.rb | 23 +++++++++++++++++++ config/routes.rb | 1 + .../v1/stats/publishers_controller_test.rb | 19 +++++++++++++++ test/fixtures/uphold_connections.yml | 1 + 4 files changed, 44 insertions(+) diff --git a/app/controllers/api/v1/stats/publishers_controller.rb b/app/controllers/api/v1/stats/publishers_controller.rb index 23304980aa..55f6d020d9 100644 --- a/app/controllers/api/v1/stats/publishers_controller.rb +++ b/app/controllers/api/v1/stats/publishers_controller.rb @@ -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]) diff --git a/config/routes.rb b/config/routes.rb index fb3fa3334a..aac64686fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/api/v1/stats/publishers_controller_test.rb b/test/controllers/api/v1/stats/publishers_controller_test.rb index b7b2d97353..c8f83bddc4 100644 --- a/test/controllers/api/v1/stats/publishers_controller_test.rb +++ b/test/controllers/api/v1/stats/publishers_controller_test.rb @@ -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 diff --git a/test/fixtures/uphold_connections.yml b/test/fixtures/uphold_connections.yml index 681654605d..071f20f1d3 100644 --- a/test/fixtures/uphold_connections.yml +++ b/test/fixtures/uphold_connections.yml @@ -19,6 +19,7 @@ created_connection: connected_connection: uphold_verified: true publisher: uphold_connected + is_member: true verified_no_currency: uphold_verified: true