Skip to content

Commit c227828

Browse files
authored
Merge pull request #769 from code0-tech/fix-invalid-flow-error-throwing
Invalid flows will get validated first before getting passed in the update service
2 parents 708acf2 + 0da56a4 commit c227828

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/services/namespaces/projects/flows/create_service.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def execute
4444
return_type: flow_type.return_type
4545
)
4646

47+
unless flow.save
48+
t.rollback_and_return! ServiceResponse.error(
49+
message: 'Flow is invalid',
50+
error_code: :invalid_flow,
51+
details: flow.errors
52+
)
53+
end
54+
4755
UpdateService.new(
4856
current_authentication,
4957
flow,

spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@
131131
create(:namespace_member_role, role: namespace_role, member: namespace_member)
132132
end
133133

134+
context 'when flow name is taken' do
135+
before do
136+
create(:flow, name: input[:flow][:name], project: project)
137+
end
138+
139+
it 'returns an error' do
140+
mutate!
141+
142+
expect(graphql_data_at(:namespaces_projects_flows_create, :errors)).to be_present
143+
expect(graphql_data_at(:namespaces_projects_flows_create, :flow)).to be_nil
144+
expect(graphql_data_at(:namespaces_projects_flows_create, :errors,
145+
:error_code)).to contain_exactly('INVALID_FLOW')
146+
end
147+
end
148+
134149
it 'creates flow' do
135150
mutate!
136151

0 commit comments

Comments
 (0)