Commit 712c33ca authored by Thong Kuah's avatar Thong Kuah

Merge branch 'mo-add-compare-reports-base-service-spec' into 'master'

Add compare reports base service spec

See merge request gitlab-org/gitlab!49488
parents 0c667b96 44018696
...@@ -29,34 +29,4 @@ RSpec.describe Ci::CompareAccessibilityReportsService do ...@@ -29,34 +29,4 @@ RSpec.describe Ci::CompareAccessibilityReportsService do
end end
end end
end end
describe '#latest?' do
subject { service.latest?(base_pipeline, head_pipeline, data) }
let!(:base_pipeline) { nil }
let!(:head_pipeline) { create(:ci_pipeline, :with_accessibility_reports, project: project) }
let!(:key) { service.send(:key, base_pipeline, head_pipeline) }
context 'when cache key is latest' do
let(:data) { { key: key } }
it { is_expected.to be_truthy }
end
context 'when cache key is outdated' do
before do
head_pipeline.update_column(:updated_at, 10.minutes.ago)
end
let(:data) { { key: key } }
it { is_expected.to be_falsy }
end
context 'when cache key is empty' do
let(:data) { { key: nil } }
it { is_expected.to be_falsy }
end
end
end end
...@@ -29,34 +29,4 @@ RSpec.describe Ci::CompareCodequalityReportsService do ...@@ -29,34 +29,4 @@ RSpec.describe Ci::CompareCodequalityReportsService do
end end
end end
end end
describe '#latest?' do
subject { service.latest?(base_pipeline, head_pipeline, data) }
let!(:base_pipeline) { nil }
let!(:head_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
let!(:key) { service.send(:key, base_pipeline, head_pipeline) }
context 'when cache key is latest' do
let(:data) { { key: key } }
it { is_expected.to be_truthy }
end
context 'when cache key is outdated' do
before do
head_pipeline.update_column(:updated_at, 10.minutes.ago)
end
let(:data) { { key: key } }
it { is_expected.to be_falsy }
end
context 'when cache key is empty' do
let(:data) { { key: nil } }
it { is_expected.to be_falsy }
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::CompareReportsBaseService do
let(:service) { described_class.new(project) }
let(:project) { create(:project, :repository) }
describe '#latest?' do
subject { service.latest?(base_pipeline, head_pipeline, data) }
let!(:base_pipeline) { nil }
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
let!(:key) { service.send(:key, base_pipeline, head_pipeline) }
context 'when cache key is latest' do
let(:data) { { key: key } }
it { is_expected.to be_truthy }
end
context 'when cache key is outdated' do
before do
head_pipeline.update_column(:updated_at, 10.minutes.ago)
end
let(:data) { { key: key } }
it { is_expected.to be_falsy }
end
context 'when cache key is empty' do
let(:data) { { key: nil } }
it { is_expected.to be_falsy }
end
end
end
...@@ -80,34 +80,4 @@ RSpec.describe Ci::CompareTestReportsService do ...@@ -80,34 +80,4 @@ RSpec.describe Ci::CompareTestReportsService do
end end
end end
end end
describe '#latest?' do
subject { service.latest?(base_pipeline, head_pipeline, data) }
let!(:base_pipeline) { nil }
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
let!(:key) { service.send(:key, base_pipeline, head_pipeline) }
context 'when cache key is latest' do
let(:data) { { key: key } }
it { is_expected.to be_truthy }
end
context 'when cache key is outdated' do
before do
head_pipeline.update_column(:updated_at, 10.minutes.ago)
end
let(:data) { { key: key } }
it { is_expected.to be_falsy }
end
context 'when cache key is empty' do
let(:data) { { key: nil } }
it { is_expected.to be_falsy }
end
end
end end
...@@ -52,34 +52,4 @@ RSpec.describe Ci::GenerateCoverageReportsService do ...@@ -52,34 +52,4 @@ RSpec.describe Ci::GenerateCoverageReportsService do
end end
end end
end end
describe '#latest?' do
subject { service.latest?(base_pipeline, head_pipeline, data) }
let!(:base_pipeline) { nil }
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
let!(:key) { service.send(:key, base_pipeline, head_pipeline) }
context 'when cache key is latest' do
let(:data) { { key: key } }
it { is_expected.to be_truthy }
end
context 'when cache key is outdated' do
before do
head_pipeline.update_column(:updated_at, 10.minutes.ago)
end
let(:data) { { key: key } }
it { is_expected.to be_falsy }
end
context 'when cache key is empty' do
let(:data) { { key: nil } }
it { is_expected.to be_falsy }
end
end
end end
...@@ -64,33 +64,4 @@ RSpec.describe Ci::GenerateTerraformReportsService do ...@@ -64,33 +64,4 @@ RSpec.describe Ci::GenerateTerraformReportsService do
end end
end end
end end
describe '#latest?' do
let_it_be(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
subject { described_class.new(project) }
it 'returns true when cache key is latest' do
cache_key = subject.send(:key, nil, head_pipeline)
result = subject.latest?(nil, head_pipeline, key: cache_key)
expect(result).to eq(true)
end
it 'returns false when cache key is outdated' do
cache_key = subject.send(:key, nil, head_pipeline)
head_pipeline.update_column(:updated_at, 10.minutes.ago)
result = subject.latest?(nil, head_pipeline, key: cache_key)
expect(result).to eq(false)
end
it 'returns false when cache key is nil' do
result = subject.latest?(nil, head_pipeline, key: nil)
expect(result).to eq(false)
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment