Commit 6123685d authored by Thong Kuah's avatar Thong Kuah

Merge branch 'fix-vulnerability-feedback-spec-for-parent-strategy' into 'master'

Refactor Vulnerability Feedback spec to support parent strategy

See merge request gitlab-org/gitlab!41765
parents a5f93728 6621e83f
...@@ -28,8 +28,10 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -28,8 +28,10 @@ RSpec.describe Vulnerabilities::Feedback do
it { is_expected.to validate_presence_of(:category) } it { is_expected.to validate_presence_of(:category) }
it { is_expected.to validate_presence_of(:project_fingerprint) } it { is_expected.to validate_presence_of(:project_fingerprint) }
let_it_be(:project) { create(:project) }
context 'pipeline is nil' do context 'pipeline is nil' do
let(:feedback) { build(:vulnerability_feedback, pipeline_id: nil) } let(:feedback) { build(:vulnerability_feedback, project: project, pipeline_id: nil) }
it 'is valid' do it 'is valid' do
expect(feedback).to be_valid expect(feedback).to be_valid
...@@ -37,7 +39,7 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -37,7 +39,7 @@ RSpec.describe Vulnerabilities::Feedback do
end end
context 'pipeline has the same project_id' do context 'pipeline has the same project_id' do
let(:feedback) { build(:vulnerability_feedback) } let(:feedback) { build(:vulnerability_feedback, project: project) }
it 'is valid' do it 'is valid' do
expect(feedback.project_id).to eq(feedback.pipeline.project_id) expect(feedback.project_id).to eq(feedback.pipeline.project_id)
...@@ -46,15 +48,15 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -46,15 +48,15 @@ RSpec.describe Vulnerabilities::Feedback do
end end
context 'pipeline_id does not exist' do context 'pipeline_id does not exist' do
let(:feedback) { build(:vulnerability_feedback, pipeline_id: -100) } let(:feedback) { build(:vulnerability_feedback, project: project, pipeline_id: -100) }
it 'is invalid' do it 'is invalid' do
expect(feedback.project_id).not_to eq(feedback.pipeline_id) expect(feedback.project_id).not_to eq(feedback.pipeline_id)
expect(feedback).not_to be_valid expect(feedback).not_to be_valid
end end
end end
context 'pipeline has a different project_id' do context 'pipeline has a different project_id' do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: create(:project)) } let(:pipeline) { create(:ci_pipeline, project: create(:project)) }
let(:feedback) { build(:vulnerability_feedback, project: project, pipeline: pipeline) } let(:feedback) { build(:vulnerability_feedback, project: project, pipeline: pipeline) }
...@@ -65,7 +67,7 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -65,7 +67,7 @@ RSpec.describe Vulnerabilities::Feedback do
end end
context 'comment is set' do context 'comment is set' do
let(:feedback) { build(:vulnerability_feedback, comment: 'a comment' ) } let(:feedback) { build(:vulnerability_feedback, project: project, comment: 'a comment' ) }
it 'validates presence of comment_timestamp' do it 'validates presence of comment_timestamp' do
expect(feedback).to validate_presence_of(:comment_timestamp) expect(feedback).to validate_presence_of(:comment_timestamp)
...@@ -128,7 +130,9 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -128,7 +130,9 @@ RSpec.describe Vulnerabilities::Feedback do
end end
describe '#has_comment?' do describe '#has_comment?' do
let(:feedback) { build(:vulnerability_feedback, comment: comment, comment_author: comment_author) } let_it_be(:project) { create(:project) }
let(:feedback) { build(:vulnerability_feedback, project: project, comment: comment, comment_author: comment_author) }
let(:comment) { 'a comment' } let(:comment) { 'a comment' }
let(:comment_author) { build(:user) } let(:comment_author) { build(:user) }
...@@ -222,14 +226,13 @@ RSpec.describe Vulnerabilities::Feedback do ...@@ -222,14 +226,13 @@ RSpec.describe Vulnerabilities::Feedback do
end end
describe '#occurrence_key' do describe '#occurrence_key' do
let(:project_id) { 1 } let(:project) { create(:project) }
let(:category) { 'sast' } let(:category) { 'sast' }
let(:project_fingerprint) { Digest::SHA1.hexdigest('foo') } let(:project_fingerprint) { Digest::SHA1.hexdigest('foo') }
let(:expected_occurrence_key) { { project_id: project_id, category: category, project_fingerprint: project_fingerprint } } let(:feedback) { build(:vulnerability_feedback, project: project, category: category, project_fingerprint: project_fingerprint) }
let(:feedback) { build(:vulnerability_feedback, expected_occurrence_key) }
subject { feedback.finding_key } subject { feedback.finding_key }
it { is_expected.to eq(expected_occurrence_key) } it { is_expected.to eq({ project_id: project.id, category: category, project_fingerprint: project_fingerprint }) }
end end
end end
...@@ -152,13 +152,13 @@ RSpec.describe Vulnerabilities::FeedbackEntity do ...@@ -152,13 +152,13 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end end
context 'when comment is not present' do context 'when comment is not present' do
let(:feedback) { build(:vulnerability_feedback, :dismissal) } let(:feedback) { build(:vulnerability_feedback, :dismissal, project: project) }
it { is_expected.not_to include(:comment_details) } it { is_expected.not_to include(:comment_details) }
end end
context 'when comment is present' do context 'when comment is present' do
let(:feedback) { build(:vulnerability_feedback, :comment) } let(:feedback) { build(:vulnerability_feedback, :comment, project: project) }
it 'exposes comment information' do it 'exposes comment information' do
expect(subject).to include(:comment_details) expect(subject).to include(:comment_details)
......
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