Commit b7d14e28 authored by Philip Cunningham's avatar Philip Cunningham

Fix issue with dastProfiles.branch GraphQL field

- Replace stub
- Update specs
- Add changelog entry
parent f974964d
# frozen_string_literal: true
module Dast
Branch = Struct.new(:project) do
Branch = Struct.new(:profile) do
delegate :project, to: :profile
def name
project.default_branch
profile.branch_name || project.default_branch
end
def exists
project.repository.branch_exists?(project.default_branch)
project.repository.branch_exists?(name)
end
end
end
......@@ -23,7 +23,7 @@ module Dast
def branch
return unless project.repository.exists?
Dast::Branch.new(project)
Dast::Branch.new(self)
end
private
......
---
title: Replace stubbed dastProfiles.branch GraphQL field
merge_request: 56604
author:
type: fixed
......@@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['DastProfile'] do
context 'when the feature flag is enabled' 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)
end
......
......@@ -3,11 +3,17 @@
require 'spec_helper'
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
describe '#name' do
it 'returns nil' do
......@@ -23,13 +29,41 @@ RSpec.describe Dast::Branch do
end
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
it 'returns the default_branch' do
expect(subject.name).to eq(project.default_branch)
it 'returns project.default_branch' do
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
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
it 'returns true' do
......
......@@ -4,6 +4,6 @@ require 'spec_helper'
RSpec.describe Dast::BranchPolicy 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
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