File: fetch_statistics_increment_service_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (35 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'spec_helper'

module Projects
  RSpec.describe FetchStatisticsIncrementService, feature_category: :groups_and_projects do
    let_it_be(:project) { create(:project) }
    let_it_be(:yesterday_stat) { create(:project_daily_statistic, fetch_count: 3, project: project, date: 1.day.ago) }

    describe '#execute', :sidekiq_inline do
      context "when no record for today is present" do
        it 'creates a new record for today and increments fetch_count' do
          expect { described_class.new(project).execute }.to change { ProjectDailyStatistic.count }.by(1)

          new_record = ProjectDailyStatistic.last
          expect(new_record.fetch_count).to eq(1)
          expect(new_record.project).to eq(project)
          expect(new_record.date).to eq(Date.today)
        end
      end

      context "when today's record is present" do
        let_it_be(:project_daily_stat) { create(:project_daily_statistic, fetch_count: 5, project: project, date: Date.today) }

        it 'increments the existing record' do
          expect { described_class.new(project).execute }.to change { project_daily_stat.reload.fetch_count }.by(1)
        end

        it "doesn't increment yesterday's record" do
          expect { described_class.new(project).execute }.not_to change { yesterday_stat.reload.fetch_count }
        end
      end
    end
  end
end