diff --git a/app/controllers/concerns/billable_event_trackable.rb b/app/controllers/concerns/billable_event_trackable.rb index 0f08e90debf..80850d0b6e6 100644 --- a/app/controllers/concerns/billable_event_trackable.rb +++ b/app/controllers/concerns/billable_event_trackable.rb @@ -3,7 +3,6 @@ def track_billing_events if current_session_has_been_billed? create_sp_return_log(billable: false) else - increment_sp_monthly_auths create_sp_return_log(billable: true) mark_current_session_billed end @@ -11,14 +10,6 @@ def track_billing_events private - def increment_sp_monthly_auths - MonthlySpAuthCount.increment( - user_id: current_user.id, - service_provider: current_sp, - ial: sp_session_ial, - ) - end - def create_sp_return_log(billable:) user_ial_context = IalContext.new( ial: ial_context.ial, service_provider: current_sp, user: current_user, diff --git a/app/jobs/reports/iaa_billing_report.rb b/app/jobs/reports/iaa_billing_report.rb deleted file mode 100644 index 808aab32de4..00000000000 --- a/app/jobs/reports/iaa_billing_report.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'identity/hostdata' - -module Reports - class IaaBillingReport < BaseReport - REPORT_NAME = 'iaa-billing-report'.freeze - - def perform(_today) - @sps_for_iaa = {} - @today = Time.zone.today - results = [] - transaction_with_timeout do - unique_iaa_sps.each do |sp| - iaa_results = active_ial2_counts_for_iaa(sp) - auth_counts = auth_counts_for_iaa(sp.iaa) - iaa_results['auth_counts'] = auth_counts - results << iaa_results - end - end - save_report(REPORT_NAME, results.to_json, extension: 'json') - end - - private - - attr_accessor :today, :sps_for_iaa - - def auth_counts_for_iaa(iaa) - results = [] - sps_for_iaa[iaa].each do |sp| - results << sp_month_auth_counts(sp, 1) - results << sp_month_auth_counts(sp, 2) - end - results - end - - def sp_month_auth_counts(sp, ial) - count = Db::MonthlySpAuthCount::SpMonthTotalAuthCounts.call(today, sp.issuer, ial) - { issuer: sp.issuer, ial: ial, count: count }.stringify_keys - end - - def active_ial2_counts_for_iaa(sp) - count = Db::Identity::IaaActiveUserCount.new( - sp.iaa, - sp.iaa_start_date, - sp.iaa_end_date, - ).call(2, today) - { iaa: sp.iaa, - iaa_start_date: sp.iaa_start_date.strftime('%Y-%m-%d'), - iaa_end_date: sp.iaa_end_date.strftime('%Y-%m-%d'), - ial2_active_count: count }.stringify_keys - end - - def unique_iaa_sps - iaa_done = {} - sps = [] - ServiceProvider.where.not( - iaa: nil, - ).where.not( - iaa_start_date: nil, - ).where.not( - iaa_end_date: nil, - ).sort_by(&:issuer).each do |sp| - iaa = sp.iaa - (sps_for_iaa[iaa] ||= []) << sp - next if iaa_done[iaa] - sps << sp - iaa_done[iaa] = true - end - sps - end - end -end diff --git a/app/jobs/reports/unique_monthly_auths_report.rb b/app/jobs/reports/unique_monthly_auths_report.rb deleted file mode 100644 index 058c2d80a96..00000000000 --- a/app/jobs/reports/unique_monthly_auths_report.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'identity/hostdata' - -module Reports - class UniqueMonthlyAuthsReport < BaseReport - REPORT_NAME = 'unique-monthly-auths-report'.freeze - - def perform(_date) - auth_counts = transaction_with_timeout do - Db::MonthlySpAuthCount::UniqueMonthlyAuthCounts.call - end - save_report(REPORT_NAME, auth_counts.to_json, extension: 'json') - end - end -end diff --git a/app/jobs/reports/unique_yearly_auths_report.rb b/app/jobs/reports/unique_yearly_auths_report.rb deleted file mode 100644 index f44046d22dd..00000000000 --- a/app/jobs/reports/unique_yearly_auths_report.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'identity/hostdata' - -module Reports - class UniqueYearlyAuthsReport < BaseReport - REPORT_NAME = 'unique-yearly-auths-report'.freeze - - def perform(_date) - auth_counts = transaction_with_timeout do - Db::MonthlySpAuthCount::UniqueYearlyAuthCounts.call - end - save_report(REPORT_NAME, auth_counts.to_json, extension: 'json') - end - end -end diff --git a/app/models/monthly_sp_auth_count.rb b/app/models/monthly_sp_auth_count.rb deleted file mode 100644 index b84a86608c3..00000000000 --- a/app/models/monthly_sp_auth_count.rb +++ /dev/null @@ -1,29 +0,0 @@ -class MonthlySpAuthCount < ApplicationRecord - # rubocop:disable Rails/InverseOf - belongs_to :user - belongs_to :service_provider, - foreign_key: 'issuer', - primary_key: 'issuer' - # rubocop:enable Rails/InverseOf - - def self.increment(user_id:, service_provider:, ial:) - # The following sql offers superior db performance with one write and no locking overhead - sql = <<~SQL - INSERT INTO monthly_sp_auth_counts (issuer, ial, year_month, user_id, auth_count) - VALUES (?, ?, ?, ?, 1) - ON CONFLICT (issuer, ial, year_month, user_id) DO UPDATE - SET auth_count = monthly_sp_auth_counts.auth_count + 1 - SQL - year_month = Time.zone.today.strftime('%Y%m') - current_user = User.find_by(id: user_id) - ial_context = IalContext.new(ial: ial, service_provider: service_provider, user: current_user) - query = sanitize_sql_array( - [sql, - service_provider&.issuer.to_s, - ial_context.bill_for_ial_1_or_2, - year_month, - user_id], - ) - MonthlySpAuthCount.connection.execute(query) - end -end diff --git a/app/services/db/identity/iaa_active_user_count.rb b/app/services/db/identity/iaa_active_user_count.rb deleted file mode 100644 index 1a573f984d2..00000000000 --- a/app/services/db/identity/iaa_active_user_count.rb +++ /dev/null @@ -1,85 +0,0 @@ -# generate incremental IAL2 active user counts by IAA (rolling up applications) -# incremental means a user can only be active for one month in the entire span of the IAA -# -# strategy: get active users in the current month in identities and -# subtract out those active in prior months from monthly_sp_auth_counts -# -# for each IAA: -# SELECT COUNT(*) as active_count FROM identities -# WHERE service_provider in (issuer1, issuer2, ...) -# AND last_ial2_authenticated_at >= first_of_the_month -# AND user_id IN (select user_id from profiles) -# AND user_id NOT IN ( -# SELECT DISTINCT user_id -# FROM monthly_sp_auth_counts -# WHERE issuer IN (issuer1, issuer2, ...) AND ial=2 -# AND year_month BETWEEN iaa_start_year_month AND last_month_year_month - -module Db - module Identity - class IaaActiveUserCount - def initialize(iaa, iaa_start_date, iaa_end_date) - @iaa = iaa - @iaa_start_date = iaa_start_date - @iaa_end_date = iaa_end_date - end - - def call(ial, today) - issuers = issuers_sql(iaa) - return unless issuers - sql = format(<<~SQL, sql_params(today, issuers, ial)) - SELECT COUNT(*) as active_count FROM identities - WHERE service_provider in %{issuers} - AND last_ial%{ial}_authenticated_at >= %{beginning_of_month} and - user_id IN (select user_id from profiles) - %{prior_months_sql} - SQL - ActiveRecord::Base.connection.execute(sql)[0]['active_count'] - end - - private - - attr_reader :iaa, :iaa_start_date, :iaa_end_date - - def from_monthly_sp_counts(issuers, ial, prior_months) - <<~SQL - AND user_id NOT IN ( - SELECT DISTINCT user_id FROM monthly_sp_auth_counts WHERE issuer IN #{issuers} and ial=#{ial} - #{prior_months} - ) - SQL - end - - def sql_params(today, issuers, ial) - { - beginning_of_month: ActiveRecord::Base.connection.quote(today.beginning_of_month), - ial: ial, - prior_months_sql: prior_months_sql(ial, today, issuers), - issuers: issuers, - } - end - - def issuers_sql(iaa) - sps = ServiceProvider.where(iaa: iaa) - return if sps.blank? - "(#{sps.map { |sp| "'#{sp.issuer}'" }.join(',')})" - end - - def prior_months_sql(ial, today, issuers) - last_month = today.last_month - return '' if last_month < iaa_start_date - <<~SQL - AND user_id NOT IN ( - SELECT DISTINCT user_id - FROM monthly_sp_auth_counts WHERE issuer IN #{issuers} and ial=#{ial} - AND year_month BETWEEN '#{year_month(iaa_start_date)}' AND '#{year_month(last_month)}' - ) - SQL - end - - def year_month(date) - date.strftime('%Y%m') - end - end - end -end diff --git a/app/services/db/monthly_sp_auth_count/sp_month_total_auth_counts.rb b/app/services/db/monthly_sp_auth_count/sp_month_total_auth_counts.rb deleted file mode 100644 index 41a35714575..00000000000 --- a/app/services/db/monthly_sp_auth_count/sp_month_total_auth_counts.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Db - module MonthlySpAuthCount - class SpMonthTotalAuthCounts - def self.call(today, issuer, ial) - sql = <<~SQL - SELECT SUM(auth_count) AS total - FROM monthly_sp_auth_counts - WHERE issuer = '#{issuer}' AND ial=#{ial} AND year_month='#{today.strftime('%Y%m')}' - SQL - results = ActiveRecord::Base.connection.execute(sql) - results.count.positive? ? results[0]['total'] || 0 : 0 - end - end - end -end diff --git a/app/services/db/monthly_sp_auth_count/unique_monthly_auth_counts.rb b/app/services/db/monthly_sp_auth_count/unique_monthly_auth_counts.rb deleted file mode 100644 index 4a42588dd2c..00000000000 --- a/app/services/db/monthly_sp_auth_count/unique_monthly_auth_counts.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Db - module MonthlySpAuthCount - class UniqueMonthlyAuthCounts - def self.call - sql = <<~SQL - SELECT monthly_sp_auth_counts.issuer,year_month,MAX(app_id) AS app_id, - COUNT(*) AS total - FROM monthly_sp_auth_counts,service_providers - WHERE monthly_sp_auth_counts.issuer = service_providers.issuer - GROUP BY monthly_sp_auth_counts.issuer, monthly_sp_auth_counts.ial, year_month - ORDER BY monthly_sp_auth_counts.issuer, monthly_sp_auth_counts.ial, year_month - SQL - ActiveRecord::Base.connection.execute(sql) - end - end - end -end diff --git a/app/services/db/monthly_sp_auth_count/unique_yearly_auth_counts.rb b/app/services/db/monthly_sp_auth_count/unique_yearly_auth_counts.rb deleted file mode 100644 index c3a4edc4a44..00000000000 --- a/app/services/db/monthly_sp_auth_count/unique_yearly_auth_counts.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Db - module MonthlySpAuthCount - class UniqueYearlyAuthCounts - def self.call - sql = <<~SQL - SELECT issuer, MAX(app_id) AS app_id, year, COUNT(*) AS total - FROM ( - SELECT monthly_sp_auth_counts.issuer, MAX(app_id) AS app_id, user_id, - monthly_sp_auth_counts.ial, LEFT(year_month, 4) AS year, COUNT(*) - FROM monthly_sp_auth_counts, service_providers - WHERE monthly_sp_auth_counts.issuer = service_providers.issuer - GROUP BY monthly_sp_auth_counts.issuer, monthly_sp_auth_counts.ial, - year, user_id) AS tbl - GROUP BY issuer, ial, year - SQL - ActiveRecord::Base.connection.execute(sql) - end - end - end -end diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index f3074992986..74d83ba9fc8 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -28,18 +28,6 @@ cron: cron_24h, args: -> { [Time.zone.today] }, }, - # Send Unique Monthly Auths Report to S3 - unique_monthly_auths: { - class: 'Reports::UniqueMonthlyAuthsReport', - cron: cron_24h, - args: -> { [Time.zone.today] }, - }, - # Send Unique Yearly Auths Report to S3 - unique_yearly_auths: { - class: 'Reports::UniqueYearlyAuthsReport', - cron: cron_24h, - args: -> { [Time.zone.today] }, - }, # Send Agency User Counts Report to S3 agency_user_counts: { class: 'Reports::AgencyUserCountsReport', @@ -141,12 +129,6 @@ cron: cron_24h, args: -> { [Time.zone.today] }, }, - # IAA Billing Report - iaa_billing_report: { - class: 'Reports::IaaBillingReport', - cron: cron_24h, - args: -> { [Time.zone.today] }, - }, # Send deleted user accounts to S3 deleted_user_accounts: { class: 'Reports::DeletedUserAccountsReport', diff --git a/spec/features/reports/authorization_count_spec.rb b/spec/features/reports/authorization_count_spec.rb index c36510d62c6..525a4e0f340 100644 --- a/spec/features/reports/authorization_count_spec.rb +++ b/spec/features/reports/authorization_count_spec.rb @@ -284,9 +284,6 @@ def visit_idp_from_ial2_saml_sp(issuer:) end def expect_ial1_count_only(issuer) - expect(ial1_monthly_auth_count(issuer)).to eq(1) - expect(ial2_monthly_auth_count(issuer)).to eq(0) - ial1_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 1) ial2_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 2) expect(ial1_return_logs.count).to eq(1) @@ -294,9 +291,6 @@ def expect_ial1_count_only(issuer) end def expect_ial2_count_only(issuer) - expect(ial1_monthly_auth_count(issuer)).to eq(0) - expect(ial2_monthly_auth_count(issuer)).to eq(1) - ial1_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 1) ial2_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 2) expect(ial1_return_logs.count).to eq(0) @@ -304,25 +298,13 @@ def expect_ial2_count_only(issuer) end def expect_ial1_and_ial2_count(issuer) - expect(ial1_monthly_auth_count(issuer)).to eq(1) - expect(ial2_monthly_auth_count(issuer)).to eq(1) - ial1_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 1) ial2_return_logs = SpReturnLog.where(issuer: issuer, billable: true, ial: 2) expect(ial1_return_logs.count).to eq(1) expect(ial2_return_logs.count).to eq(1) end - def ial2_monthly_auth_count(client_id) - Db::MonthlySpAuthCount::SpMonthTotalAuthCounts.call(today, client_id, 2) - end - - def ial1_monthly_auth_count(client_id) - Db::MonthlySpAuthCount::SpMonthTotalAuthCounts.call(today, client_id, 1) - end - def reset_monthly_auth_count_and_login(user) - MonthlySpAuthCount.delete_all SpReturnLog.delete_all visit api_saml_logout2022_path sign_in_live_with_2fa(user) diff --git a/spec/jobs/reports/iaa_billing_report_spec.rb b/spec/jobs/reports/iaa_billing_report_spec.rb deleted file mode 100644 index 2599989423b..00000000000 --- a/spec/jobs/reports/iaa_billing_report_spec.rb +++ /dev/null @@ -1,190 +0,0 @@ -require 'rails_helper' - -describe Reports::IaaBillingReport do - subject { described_class.new } - - let(:issuer) { 'foo' } - let(:issuer2) { 'foo2' } - let(:issuer3) { 'foo3' } - let(:iaa) { 'iaa' } - let(:iaa2) { 'iaa2' } - let(:iaa_start_date1_str) { '2020-02-01' } - let(:iaa_end_date1_str) { '2021-02-01' } - let(:iaa_start_date2_str) { '2020-05-01' } - let(:iaa_end_date2_str) { '2021-05-01' } - let(:iaa_start_date1) { Time.zone.parse(iaa_start_date1_str) } - let(:iaa_end_date1) { Time.zone.parse(iaa_end_date1_str) } - let(:iaa_start_date2) { Time.zone.parse(iaa_start_date2_str) } - let(:iaa_end_date2) { Time.zone.parse(iaa_end_date2_str) } - - let(:results_for_1_iaa) do - [ - { - iaa: 'iaa', - iaa_start_date: iaa_start_date1_str, - iaa_end_date: iaa_end_date1_str, - ial2_active_count: 0, - auth_counts: - [ - { - issuer: 'foo', - ial: 1, - count: 0, - }, - { - issuer: 'foo', - ial: 2, - count: 0, - }, - { - issuer: 'foo2', - ial: 1, - count: 0, - }, - { - issuer: 'foo2', - ial: 2, - count: 0, - }, - ], - }, - ] - end - let(:results_for_2_iaas_1) do - { - iaa: 'iaa', - iaa_start_date: iaa_start_date1_str, - iaa_end_date: iaa_end_date1_str, - ial2_active_count: 1, - auth_counts: - [ - { - issuer: 'foo', - ial: 1, - count: 7, - }, - { - issuer: 'foo', - ial: 2, - count: 0, - }, - ], - } - end - let(:results_for_2_iaas_2) do - { - iaa: 'iaa2', - iaa_start_date: iaa_start_date2_str, - iaa_end_date: iaa_end_date2_str, - ial2_active_count: 1, - auth_counts: - [ - { - issuer: 'foo2', - ial: 1, - count: 0, - }, - { - issuer: 'foo2', - ial: 2, - count: 3, - }, - { - issuer: 'foo3', - ial: 1, - count: 0, - }, - { - issuer: 'foo3', - ial: 2, - count: 0, - }, - ], - } - end - - let(:now) { Time.zone.parse('2020-06-15') } - - before do - Agreements::IntegrationUsage.delete_all - Agreements::Integration.delete_all - ServiceProvider.delete_all - travel_to(now) - end - - it 'works with no SPs' do - expect(subject.perform(Time.zone.today)).to eq([].to_json) - end - - it 'ignores sps without an IAA or a start date or an end date' do - ServiceProvider.create(issuer: issuer, friendly_name: issuer, ial: 1) - ServiceProvider.create( - issuer: issuer2, friendly_name: issuer2, ial: 1, iaa: iaa, - iaa_start_date: iaa_start_date1 - ) - ServiceProvider.create( - issuer: issuer3, friendly_name: issuer3, ial: 1, iaa: iaa2, - iaa_end_date: iaa_end_date1 - ) - - expect(subject.perform(Time.zone.today)).to eq([].to_json) - end - - it 'rolls up 2 issuers in a single IAA' do - ServiceProvider.create( - issuer: issuer, friendly_name: issuer, ial: 1, iaa: iaa, - iaa_start_date: iaa_start_date1, iaa_end_date: iaa_end_date1 - ) - ServiceProvider.create( - issuer: issuer2, friendly_name: issuer2, ial: 2, iaa: iaa, - iaa_start_date: iaa_start_date1, iaa_end_date: iaa_end_date1 - ) - - expect(subject.perform(Time.zone.today)).to eq(results_for_1_iaa.to_json) - end - - it 'works with multiple IAAs and issuers' do - last_month = now.last_month - today_year_month = now.strftime('%Y%m') - - ServiceProvider.create( - issuer: issuer, friendly_name: issuer, ial: 1, iaa: iaa, - iaa_start_date: iaa_start_date1, iaa_end_date: iaa_end_date1 - ) - ServiceProvider.create( - issuer: issuer2, friendly_name: issuer2, ial: 2, iaa: iaa2, - iaa_start_date: iaa_start_date2, iaa_end_date: iaa_end_date2 - ) - ServiceProvider.create( - issuer: issuer3, friendly_name: issuer3, ial: 2, iaa: iaa2, - iaa_start_date: iaa_start_date2, iaa_end_date: iaa_end_date2 - ) - ServiceProviderIdentity.create( - user_id: 1, service_provider: issuer, uuid: 'a', - last_ial2_authenticated_at: now - 1.hour - ) - ServiceProviderIdentity.create( - user_id: 2, service_provider: issuer2, uuid: 'b', - last_ial2_authenticated_at: last_month - ) - ServiceProviderIdentity.create( - user_id: 3, service_provider: issuer3, uuid: 'c', - last_ial2_authenticated_at: now - 1.hour - ) - create(:profile, :active, :verified, user_id: 1) - create(:profile, :active, :verified, user_id: 2) - create(:profile, :active, :verified, user_id: 3) - MonthlySpAuthCount.create( - issuer: issuer, ial: 1, year_month: today_year_month, user_id: 2, - auth_count: 7 - ) - MonthlySpAuthCount.create( - issuer: issuer2, ial: 2, year_month: today_year_month, user_id: 3, - auth_count: 3 - ) - - tuples = subject.perform(Time.zone.today) - expect(tuples).to include(results_for_2_iaas_1.to_json) - expect(tuples).to include(results_for_2_iaas_2.to_json) - end -end diff --git a/spec/jobs/reports/unique_monthly_auths_report_spec.rb b/spec/jobs/reports/unique_monthly_auths_report_spec.rb deleted file mode 100644 index 3a3fd174f01..00000000000 --- a/spec/jobs/reports/unique_monthly_auths_report_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -describe Reports::UniqueMonthlyAuthsReport do - subject { described_class.new } - - let(:issuer) { 'foo' } - let(:app_id) { 'app_id' } - let(:year_month) { '201901' } - - it 'is empty' do - expect(subject.perform(Time.zone.today)).to eq('[]') - end - - it 'returns 1 unique despite the count for the user being 7' do - ServiceProvider.create(issuer: issuer, friendly_name: issuer, app_id: app_id) - MonthlySpAuthCount.create( - issuer: issuer, ial: 1, year_month: '201901', user_id: 2, - auth_count: 7 - ) - result = [{ issuer: 'foo', year_month: '201901', app_id: app_id, total: 1 }].to_json - - expect(subject.perform(Time.zone.today)).to eq(result) - end -end diff --git a/spec/jobs/reports/unique_yearly_auths_report_spec.rb b/spec/jobs/reports/unique_yearly_auths_report_spec.rb deleted file mode 100644 index 3dde809a03f..00000000000 --- a/spec/jobs/reports/unique_yearly_auths_report_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -describe Reports::UniqueYearlyAuthsReport do - subject { described_class.new } - - let(:issuer) { 'foo' } - let(:year_month) { '201901' } - let(:year) { '2019' } - let(:app_id) { 'app_id' } - - it 'is empty' do - expect(subject.perform(Time.zone.today)).to eq('[]') - end - - it 'returns 1 unique despite the count for the user being 7' do - ServiceProvider.create(issuer: issuer, friendly_name: issuer, app_id: app_id) - MonthlySpAuthCount.create( - issuer: 'foo', ial: 1, year_month: year_month, user_id: 2, - auth_count: 7 - ) - result = [{ issuer: 'foo', app_id: app_id, year: year, total: 1 }].to_json - - expect(subject.perform(Time.zone.today)).to eq(result) - end -end diff --git a/spec/models/monthly_auth_count_spec.rb b/spec/models/monthly_auth_count_spec.rb deleted file mode 100644 index 11238c40694..00000000000 --- a/spec/models/monthly_auth_count_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'rails_helper' - -describe MonthlySpAuthCount do - let(:user_id) { 1 } - let(:issuer) { 'foo' } - let(:service_provider) { build(:service_provider, issuer: issuer) } - let(:ial) { 1 } - - describe '.increment' do - it 'sets the monthly count to 1' do - year_month = current_year_month - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - - monthly_auth_count = MonthlySpAuthCount.first - expect(monthly_auth_count.user_id).to eq(user_id) - expect(monthly_auth_count.issuer).to eq(issuer) - expect(monthly_auth_count.year_month).to eq(year_month) - expect(monthly_auth_count.auth_count).to eq(1) - end - - it 'updates the monthly count to 2' do - year_month = current_year_month - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - - monthly_auth_count = MonthlySpAuthCount.first - expect(monthly_auth_count.user_id).to eq(user_id) - expect(monthly_auth_count.issuer).to eq(issuer) - expect(monthly_auth_count.year_month).to eq(year_month) - expect(monthly_auth_count.auth_count).to eq(2) - end - - it 'updates the monthly count to 3' do - year_month = current_year_month - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - MonthlySpAuthCount.increment(user_id: user_id, service_provider: service_provider, ial: ial) - - monthly_auth_count = MonthlySpAuthCount.first - expect(monthly_auth_count.user_id).to eq(user_id) - expect(monthly_auth_count.issuer).to eq(issuer) - expect(monthly_auth_count.year_month).to eq(year_month) - expect(monthly_auth_count.auth_count).to eq(3) - end - end - - def current_year_month - Time.zone.today.strftime('%Y%m') - end -end diff --git a/spec/services/db/monthly_auth_count/unique_monthly_auth_counts_spec.rb b/spec/services/db/monthly_auth_count/unique_monthly_auth_counts_spec.rb deleted file mode 100644 index 8ee8e27799e..00000000000 --- a/spec/services/db/monthly_auth_count/unique_monthly_auth_counts_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -describe Db::MonthlySpAuthCount::UniqueMonthlyAuthCounts do - subject { described_class } - - let(:issuer) { 'foo' } - let(:app_id) { 'app_id' } - let(:year_month) { '201901' } - - it 'is empty' do - expect(subject.call.ntuples).to eq(0) - end - - it 'returns 1 unique despite the count for the user being 7' do - ServiceProvider.create(issuer: issuer, friendly_name: issuer, app_id: app_id) - MonthlySpAuthCount.create( - issuer: issuer, ial: 1, year_month: year_month, user_id: 2, - auth_count: 7 - ) - result = { issuer: issuer, year_month: year_month, app_id: app_id, total: 1 }.to_json - - expect(subject.call.ntuples).to eq(1) - expect(subject.call[0].to_json).to eq(result) - end -end diff --git a/spec/services/db/monthly_auth_count/unique_yearly_auth_counts_spec.rb b/spec/services/db/monthly_auth_count/unique_yearly_auth_counts_spec.rb deleted file mode 100644 index e1000be65c6..00000000000 --- a/spec/services/db/monthly_auth_count/unique_yearly_auth_counts_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -describe Db::MonthlySpAuthCount::UniqueYearlyAuthCounts do - subject { described_class } - - let(:issuer) { 'foo' } - let(:app_id) { 'app_id' } - let(:year_month) { '201901' } - let(:year) { '2019' } - - it 'is empty' do - expect(subject.call.ntuples).to eq(0) - end - - it 'returns 1 unique despite the count for the user being 7' do - ServiceProvider.create(issuer: issuer, friendly_name: issuer, app_id: app_id) - MonthlySpAuthCount.create( - issuer: issuer, ial: 1, year_month: year_month, user_id: 2, - auth_count: 7 - ) - result = { issuer: issuer, app_id: app_id, year: year, total: 1 }.to_json - - expect(subject.call.ntuples).to eq(1) - expect(subject.call[0].to_json).to eq(result) - end -end