Commit d22c6821 authored by Stan Hu's avatar Stan Hu

Merge branch 'philipcunningham-fix-dast-branch-selection-issue' into 'master'

Replace stubbed dastProfiles.branch GraphQL field

See merge request gitlab-org/gitlab!56604
parents f8e5887d b7d14e28
# frozen_string_literal: true # frozen_string_literal: true
module Dast module Dast
Branch = Struct.new(:project) do Branch = Struct.new(:profile) do
delegate :project, to: :profile
def name def name
project.default_branch profile.branch_name || project.default_branch
end end
def exists def exists
project.repository.branch_exists?(project.default_branch) project.repository.branch_exists?(name)
end end
end end
end end
...@@ -23,7 +23,7 @@ module Dast ...@@ -23,7 +23,7 @@ module Dast
def branch def branch
return unless project.repository.exists? return unless project.repository.exists?
Dast::Branch.new(project) Dast::Branch.new(self)
end end
private private
......
---
title: Replace stubbed dastProfiles.branch GraphQL field
merge_request: 56604
author:
type: fixed
...@@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['DastProfile'] do ...@@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['DastProfile'] do
context 'when the feature flag is enabled' do context 'when the feature flag is enabled' do
it 'correctly resolves the field' do it 'correctly resolves the field' do
expected_result = Dast::Branch.new(project) expected_result = Dast::Branch.new(object)
expect(resolve_field(:branch, object, current_user: user)).to eq(expected_result) expect(resolve_field(:branch, object, current_user: user)).to eq(expected_result)
end end
......
...@@ -3,11 +3,17 @@ ...@@ -3,11 +3,17 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Dast::Branch do RSpec.describe Dast::Branch do
let_it_be(:project) { create(:project) } let_it_be(:dast_profile) { create(:dast_profile) }
subject { described_class.new(project) } subject { described_class.new(dast_profile) }
describe 'instance methods' do describe '#project' do
it 'delegates to profile.project' do
expect(subject.project).to eq(dast_profile.project)
end
end
context 'when profile.branch_name is nil' do
context 'when the associated project does not have a repository' do context 'when the associated project does not have a repository' do
describe '#name' do describe '#name' do
it 'returns nil' do it 'returns nil' do
...@@ -23,13 +29,41 @@ RSpec.describe Dast::Branch do ...@@ -23,13 +29,41 @@ RSpec.describe Dast::Branch do
end end
context 'when the associated project has a repository' do context 'when the associated project has a repository' do
let_it_be(:project) { create(:project, :repository) } let_it_be(:dast_profile) { create(:dast_profile, project: create(:project, :repository)) }
describe '#name' do describe '#name' do
it 'returns the default_branch' do it 'returns project.default_branch' do
expect(subject.name).to eq(project.default_branch) expect(subject.name).to eq(subject.project.default_branch)
end
end
describe '#exists' do
it 'returns true' do
expect(subject.exists).to eq(true)
end
end
end
end
context 'when profile.branch_name is not nil' do
let_it_be(:dast_profile) { create(:dast_profile, branch_name: 'orphaned-branch') }
describe '#name' do
it 'returns profile.branch_name' do
expect(subject.name).to eq(dast_profile.branch_name)
end
end
context 'when the associated project does not have a repository' do
describe '#exists' do
it 'returns false' do
expect(subject.exists).to eq(false)
end end
end end
end
context 'when the associated branch has a repository and the branch exists' do
let_it_be(:dast_profile) { create(:dast_profile, project: create(:project, :repository), branch_name: 'orphaned-branch') }
describe '#exists' do describe '#exists' do
it 'returns true' do it 'returns true' do
......
...@@ -4,6 +4,6 @@ require 'spec_helper' ...@@ -4,6 +4,6 @@ require 'spec_helper'
RSpec.describe Dast::BranchPolicy do RSpec.describe Dast::BranchPolicy do
it_behaves_like 'a dast on-demand scan policy' do it_behaves_like 'a dast on-demand scan policy' do
let_it_be(:record) { Dast::Branch.new(project) } let_it_be(:record) { Dast::Branch.new(create(:dast_profile, project: project)) }
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