Commit 1dd22b11 authored by Mario Celi's avatar Mario Celi

Add actor to work_items FF on create mutation

Adds project as an actor for the work_items FF
in the WorkItemCreate GraphQL mutation
parent 74bbdea9
......@@ -8,6 +8,9 @@ module Mutations
include Mutations::SpamProtection
include FindsProject
description "Creates a work item." \
" Available only when feature flag `work_items` is enabled. The feature is experimental and is subject to change without notice."
authorize :create_work_item
argument :description, GraphQL::Types::String,
......@@ -29,6 +32,11 @@ module Mutations
def resolve(project_path:, **attributes)
project = authorized_find!(project_path)
unless Feature.enabled?(:work_items, project)
return { errors: ['`work_items` feature flag disabled for this project'] }
end
params = global_id_compatibility_params(attributes).merge(author_id: current_user.id)
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
......
......@@ -125,7 +125,7 @@ module Types
mount_mutation Mutations::Packages::Destroy
mount_mutation Mutations::Packages::DestroyFile
mount_mutation Mutations::Echo
mount_mutation Mutations::WorkItems::Create, feature_flag: :work_items
mount_mutation Mutations::WorkItems::Create
mount_mutation Mutations::WorkItems::Delete
mount_mutation Mutations::WorkItems::Update
end
......
......@@ -5168,7 +5168,7 @@ Input type: `VulnerabilityRevertToDetectedInput`
### `Mutation.workItemCreate`
Available only when feature flag `work_items` is enabled. This flag is disabled by default, because the feature is experimental and is subject to change without notice.
Creates a work item. Available only when feature flag `work_items` is enabled. The feature is experimental and is subject to change without notice.
Input type: `WorkItemCreateInput`
......@@ -68,8 +68,13 @@ RSpec.describe 'Create a work item' do
stub_feature_flags(work_items: false)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ["Field 'workItemCreate' doesn't exist on type 'Mutation'", "Variable $workItemCreateInput is declared by anonymous mutation but not used"]
it 'does not create the work item and returns an error' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
end.to not_change(WorkItem, :count)
expect(mutation_response['errors']).to contain_exactly('`work_items` feature flag disabled for this project')
end
end
end
end
......@@ -71,10 +71,11 @@ RSpec.describe 'Update a work item' do
stub_feature_flags(work_items: false)
end
it 'does nothing and returns and error' do
it 'does not update the work item and returns and error' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
end.to not_change(WorkItem, :count)
work_item.reload
end.to not_change(work_item, :title)
expect(mutation_response['errors']).to contain_exactly('`work_items` feature flag disabled for this project')
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