Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/node_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def validate_recursion
def to_grpc
Tucana::Shared::NodeFunction.new(
database_id: id,
runtime_function_id: function_definition.runtime_function_definition.runtime_name,
runtime_function_id: function_definition.identifier,
parameters: ordered_parameters.map(&:to_grpc),
next_node_id: next_node&.id,
definition_source: function_definition.runtime_function_definition.definition_source
Expand Down
2 changes: 2 additions & 0 deletions app/services/namespaces/projects/flows/validation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def execute
end

UpdateRuntimesForProjectJob.perform_later(flow.project.id)

result
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
node_functions: [
{
database_id: starting_node.id,
runtime_function_id: starting_node.function_definition.runtime_function_definition.runtime_name,
runtime_function_id: starting_node.function_definition.identifier,
parameters: [
{
database_id: starting_node.node_parameters.first.id,
Expand Down
95 changes: 64 additions & 31 deletions spec/services/namespaces/projects/flows/validation_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,91 @@
let(:runtime) { create(:runtime) }
let(:namespace_project) { create(:namespace_project) }
let(:flow_type) { create(:flow_type, runtime: runtime) }
let(:runtime_function_definition) { create(:runtime_function_definition, runtime: runtime) }
let(:runtime_function_definition) do
create(:runtime_function_definition, runtime: runtime, signature: '(arg: string): void')
end
let(:function_definition) do
create(:function_definition, runtime_function_definition: runtime_function_definition).tap do |fd|
rpd = create(:runtime_parameter_definition, runtime_function_definition: runtime_function_definition)
rpd = create(
:runtime_parameter_definition,
runtime_function_definition: runtime_function_definition,
runtime_name: 'arg'
)
create(:parameter_definition, runtime_parameter_definition: rpd, function_definition: fd)
end
end
let(:node_function) { create(:node_function, flow: flow, function_definition: function_definition) }
let(:node_function) do
create(:node_function, function_definition: function_definition).tap do |nf|
create(
:node_parameter,
parameter_definition: function_definition.parameter_definitions[0],
node_function: nf,
literal_value: '1'
)
end
end
let(:flow) do
create(:flow, project: namespace_project, flow_type: flow_type, validation_status: :unvalidated,
starting_node: nil)
create(
:flow,
project: namespace_project,
flow_type: flow_type,
validation_status: :unvalidated,
starting_node: node_function
).tap do |f|
node_function.update!(flow: f)
end
end

before do
flow.update!(starting_node: node_function)
allow(UpdateRuntimesForProjectJob).to receive(:perform_later)
context 'with fixed validation results' do
before do
flow.update!(starting_node: node_function)
allow(UpdateRuntimesForProjectJob).to receive(:perform_later)

result = Triangulum::Validation::Result.new(valid?: valid, return_type: nil, diagnostics: [])
allow(Triangulum::Validation).to receive(:new).and_return(
instance_double(Triangulum::Validation, validate: result)
)
end
result = Triangulum::Validation::Result.new(valid?: valid, return_type: nil, diagnostics: [])
allow(Triangulum::Validation).to receive(:new).and_return(
instance_double(Triangulum::Validation, validate: result)
)
end

context 'when validation passes' do
let(:valid) { true }
context 'when validation passes' do
let(:valid) { true }

it 'sets validation status to valid' do
service.execute
it 'sets validation status to valid' do
service.execute

expect(flow.reload.validation_status).to eq('valid')
end
expect(flow.reload.validation_status).to eq('valid')
end

it 'enqueues UpdateRuntimesForProjectJob' do
service.execute
it 'enqueues UpdateRuntimesForProjectJob' do
service.execute

expect(UpdateRuntimesForProjectJob).to have_received(:perform_later).with(namespace_project.id)
expect(UpdateRuntimesForProjectJob).to have_received(:perform_later).with(namespace_project.id)
end
end
end

context 'when validation fails' do
let(:valid) { false }
context 'when validation fails' do
let(:valid) { false }

it 'sets validation status to invalid' do
service.execute

expect(flow.reload.validation_status).to eq('invalid')
end

it 'sets validation status to invalid' do
service.execute
it 'enqueues UpdateRuntimesForProjectJob' do
service.execute

expect(flow.reload.validation_status).to eq('invalid')
expect(UpdateRuntimesForProjectJob).to have_received(:perform_later).with(namespace_project.id)
end
end
end

it 'enqueues UpdateRuntimesForProjectJob' do
service.execute
context 'when calling triangulum without mocking' do
it 'sets validation status to valid' do
result = service.execute

expect(UpdateRuntimesForProjectJob).to have_received(:perform_later).with(namespace_project.id)
expect(result).to have_attributes(valid?: true, diagnostics: [])
expect(flow.reload.validation_status).to eq('valid')
end
end
end