most_used_apps_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AnnualReport::MostUsedApps do
  4. describe '#generate' do
  5. subject { described_class.new(account, Time.zone.now.year) }
  6. context 'with an inactive account' do
  7. let(:account) { Fabricate :account }
  8. it 'builds a report for an account' do
  9. expect(subject.generate)
  10. .to include(
  11. most_used_apps: be_an(Array).and(be_empty)
  12. )
  13. end
  14. end
  15. context 'with an active account' do
  16. let(:account) { Fabricate :account }
  17. let(:application) { Fabricate :application, name: 'App' }
  18. let(:most_application) { Fabricate :application, name: 'Most App' }
  19. before do
  20. _other = Fabricate :status
  21. Fabricate.times 2, :status, account: account, application: application
  22. Fabricate.times 3, :status, account: account, application: most_application
  23. end
  24. it 'builds a report for an account' do
  25. expect(subject.generate)
  26. .to include(
  27. most_used_apps: eq(
  28. [
  29. { name: most_application.name, count: 3 },
  30. { name: application.name, count: 2 },
  31. ]
  32. )
  33. )
  34. end
  35. end
  36. end
  37. end