diff options
Diffstat (limited to 'spec/models/project_feature_usage_spec.rb')
-rw-r--r-- | spec/models/project_feature_usage_spec.rb | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/spec/models/project_feature_usage_spec.rb b/spec/models/project_feature_usage_spec.rb index cd70602fc4d..4baa59535e4 100644 --- a/spec/models/project_feature_usage_spec.rb +++ b/spec/models/project_feature_usage_spec.rb @@ -24,21 +24,91 @@ RSpec.describe ProjectFeatureUsage, type: :model do subject { project.feature_usage } - it 'logs Jira DVCS Cloud last sync' do - freeze_time do - subject.log_jira_dvcs_integration_usage + context 'when the feature usage has not been created yet' do + it 'logs Jira DVCS Cloud last sync' do + freeze_time do + subject.log_jira_dvcs_integration_usage - expect(subject.jira_dvcs_server_last_sync_at).to be_nil - expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.current) + expect(subject.jira_dvcs_server_last_sync_at).to be_nil + expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.current) + end + end + + it 'logs Jira DVCS Server last sync' do + freeze_time do + subject.log_jira_dvcs_integration_usage(cloud: false) + + expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.current) + expect(subject.jira_dvcs_cloud_last_sync_at).to be_nil + end end end - it 'logs Jira DVCS Server last sync' do - freeze_time do - subject.log_jira_dvcs_integration_usage(cloud: false) + context 'when the feature usage already exists' do + let(:today) { Time.current.beginning_of_day } + let(:project) { create(:project) } + + subject { project.feature_usage } - expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.current) - expect(subject.jira_dvcs_cloud_last_sync_at).to be_nil + where(:cloud, :timestamp_field) do + [ + [true, :jira_dvcs_cloud_last_sync_at], + [false, :jira_dvcs_server_last_sync_at] + ] + end + + with_them do + context 'when Jira DVCS Cloud last sync has not been logged' do + before do + travel_to today - 3.days do + subject.log_jira_dvcs_integration_usage(cloud: !cloud) + end + end + + it 'logs Jira DVCS Cloud last sync' do + freeze_time do + subject.log_jira_dvcs_integration_usage(cloud: cloud) + + expect(subject.reload.send(timestamp_field)).to be_like_time(Time.current) + end + end + end + + context 'when Jira DVCS Cloud last sync was logged today' do + let(:last_updated) { today + 1.hour } + + before do + travel_to last_updated do + subject.log_jira_dvcs_integration_usage(cloud: cloud) + end + end + + it 'does not log Jira DVCS Cloud last sync' do + travel_to today + 2.hours do + subject.log_jira_dvcs_integration_usage(cloud: cloud) + + expect(subject.reload.send(timestamp_field)).to be_like_time(last_updated) + end + end + end + + context 'when Jira DVCS Cloud last sync was logged yesterday' do + let(:last_updated) { today - 2.days } + + before do + travel_to last_updated do + subject.log_jira_dvcs_integration_usage(cloud: cloud) + end + end + + it 'logs Jira DVCS Cloud last sync' do + travel_to today + 1.hour do + subject.log_jira_dvcs_integration_usage(cloud: cloud) + + expect(subject.reload.send(timestamp_field)).to be_like_time(today + 1.hour) + end + end + end end end |