Test case that reproeduces Trello card #1943.

pull/1123/head
Rick Carlino 2019-03-05 13:45:16 -06:00
parent c99e2dd5ee
commit 4529b236be
2 changed files with 100 additions and 78 deletions

View File

@ -2,6 +2,7 @@
# PROBABLY THE MOST COMPLICATED CODE IN ALL OF FARMBOT.
module CeleryScript
class TypeCheckError < StandardError; end
class Checker
MISSING_ARG = "Expected node '%s' to have a '%s', but got: %s."
EXTRA_ARGS = "'%s' has unexpected arguments: %s. Allowed arguments: %s"
@ -20,8 +21,8 @@ module CeleryScript
# BAD_LEAF template.
FRIENDLY_ERRORS = {
nothing: {
variable_declaration: "You must provide a value for all parameters"
}
variable_declaration: "You must provide a value for all parameters",
},
}.with_indifferent_access
attr_reader :tree, :corpus, :device
@ -119,7 +120,6 @@ module CeleryScript
# value.invalidate!(T_MISMATCH % [label, expected, actual])
# end SEE_MY_NOTE =============================^ RC 4 Oct 18
def type_check_parameter(var, expected)
data_type = var.args[:data_type].value
@ -131,7 +131,6 @@ module CeleryScript
# end SEE_MY_NOTE =============================^ RC 4 Oct 18
end
def validate_node_pairing(key, value)
actual = value.kind
allowed = corpus.fetchArg(key).allowed_values.map(&:to_s)
@ -170,9 +169,8 @@ module CeleryScript
kind: kind,
parent_kind: parent_kind,
allowed: allowed,
actual: actual
actual: actual,
}
raise TypeCheckError, message
end
end

View File

@ -1,13 +1,38 @@
require "spec_helper"
describe Api::RegimensController do
include Devise::Test::ControllerHelpers
describe "#create" do
let(:user) { FactoryBot.create(:user) }
let(:sequence) { FakeSequence.create(device: user.device) }
it "kicks back missing parameters" do
sign_in user
celery = File.read("spec/lib/celery_script/ast_fixture5.json")
json = JSON.parse(celery).deep_symbolize_keys
s = Sequences::Create.run!(json, device: user.device)
# No paramaters here.
payload = {
name: "New regimen 1",
color: "gray",
regimen_items: [{ time_offset: 300000, sequence_id: s.fetch(:id) }],
body: [
{
kind: "variable_declaration",
args: { label: "parent", data_value: { kind: "nothing", args: {} } },
},
],
}
before_count = Regimen.count
post :create, body: payload.to_json, format: :json
after_count = Regimen.count
expect(response.status).to eq(422)
expect(before_count).to eq(after_count)
end
it "creates a regimen that uses variables" do
sign_in user
s = FakeSequence.with_parameters
@ -20,13 +45,13 @@ describe Api::RegimensController do
args: {
label: "parent",
data_value: {
kind: "every_point", args: { every_point_type: "Plant" }
}
}
}
kind: "every_point", args: { every_point_type: "Plant" },
},
},
},
],
regimen_items: [
{ time_offset: 100, sequence_id: s.id }
{ time_offset: 100, sequence_id: s.id },
] }
post :create, body: payload.to_json, format: :json
expect(response.status).to eq(200)
@ -45,7 +70,7 @@ describe Api::RegimensController do
payload = {
name: name,
color: color,
regimen_items: [ {time_offset: 123, sequence_id: sequence.id} ]
regimen_items: [{ time_offset: 123, sequence_id: sequence.id }],
}
old_regimen_count = Regimen.count
@ -71,17 +96,16 @@ describe Api::RegimensController do
kind: "variable_declaration",
args: {
label: "parent",
data_value: { kind: "nothing", args: { } }
}
}
data_value: { kind: "nothing", args: {} },
},
},
],
regimen_items: [
{ time_offset: 100, sequence_id: s.id }
{ time_offset: 100, sequence_id: s.id },
] }
post :create, body: payload.to_json, format: :json
expect(response.status).to eq(422)
expect(json.fetch(:error))
.to include("must provide a value for all parameters")
expect(json.fetch(:error)).to include("must provide a value for all parameters")
end
end
end