Add test for flash_firmware node
parent
e5389b747e
commit
afceaf25e0
|
@ -5,11 +5,6 @@ import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
|
|||
import { t } from "../../i18next_wrapper";
|
||||
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
|
||||
import { editStep } from "../../api/crud";
|
||||
// import { StepRadio } from "../step_ui/step_radio";
|
||||
// const PACKAGE_CHOICES = (): Record<ALLOWED_PACKAGES, string> => ({
|
||||
// "arduino_firmware": t("Just the Arduino"),
|
||||
// "farmbot_os": t("Entire system")
|
||||
// });
|
||||
|
||||
function assertReboot(x: SequenceBodyItem): asserts x is Reboot {
|
||||
if (x.kind !== "reboot") {
|
||||
|
|
|
@ -6,68 +6,68 @@ describe CeleryScript::Corpus do
|
|||
|
||||
it "handles valid move_absolute blocks" do
|
||||
ok1 = CeleryScript::AstNode.new(**{
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: 3,
|
||||
},
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: 3,
|
||||
},
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
check1 = CeleryScript::Checker.new(ok1, corpus, device)
|
||||
expect(check1.valid?).to be_truthy
|
||||
|
||||
ok2 = CeleryScript::AstNode.new(**{
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "tool",
|
||||
args: { tool_id: FactoryBot.create(:tool).id },
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "tool",
|
||||
args: { tool_id: FactoryBot.create(:tool).id },
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
check2 = CeleryScript::Checker.new(ok2, corpus, device)
|
||||
expect(check2.valid?).to be_truthy
|
||||
end
|
||||
|
||||
it "kicks back invalid move_absolute nodes" do
|
||||
bad = CeleryScript::AstNode.new(**{
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: 42,
|
||||
speed: 100,
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: 42,
|
||||
speed: 100,
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||
expect(check.valid?).to be_falsey
|
||||
expect(check.error.message).to include("but got Integer")
|
||||
|
@ -76,19 +76,19 @@ describe CeleryScript::Corpus do
|
|||
|
||||
it "finds problems with nested nodes" do
|
||||
bad = CeleryScript::AstNode.new(**{
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "tool",
|
||||
args: { tool_id: "PROBLEM!" }, # <= Invalid:
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: { "x": 0, "y": 0, "z": 0 },
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
kind: "move_absolute",
|
||||
args: {
|
||||
location: {
|
||||
kind: "tool",
|
||||
args: { tool_id: "PROBLEM!" }, # <= Invalid:
|
||||
},
|
||||
offset: {
|
||||
kind: "coordinate",
|
||||
args: { "x": 0, "y": 0, "z": 0 },
|
||||
},
|
||||
speed: 100,
|
||||
},
|
||||
})
|
||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||
expect(check.valid?).to be_falsey
|
||||
expect(check.error.message).to include("but got String")
|
||||
|
@ -110,31 +110,31 @@ describe CeleryScript::Corpus do
|
|||
# This test is __ONLY__ relevant for version 1.
|
||||
# Change / delete / update as needed.
|
||||
tree = CeleryScript::AstNode.new(**{
|
||||
"kind": "send_message",
|
||||
"args": {
|
||||
"message": "Hello, world!",
|
||||
"message_type": "wrong",
|
||||
},
|
||||
"body": [],
|
||||
})
|
||||
"kind": "send_message",
|
||||
"args": {
|
||||
"message": "Hello, world!",
|
||||
"message_type": "wrong",
|
||||
},
|
||||
"body": [],
|
||||
})
|
||||
checker = CeleryScript::Checker.new(tree, corpus, device)
|
||||
expect(checker.error.message).to include("not a valid message_type")
|
||||
end
|
||||
|
||||
it "Handles channel_name validations" do
|
||||
tree = CeleryScript::AstNode.new(**{
|
||||
"kind": "send_message",
|
||||
"args": {
|
||||
"message": "Hello, world!",
|
||||
"message_type": "fun",
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"kind": "channel",
|
||||
"args": { "channel_name": "wrong" },
|
||||
},
|
||||
],
|
||||
})
|
||||
"kind": "send_message",
|
||||
"args": {
|
||||
"message": "Hello, world!",
|
||||
"message_type": "fun",
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"kind": "channel",
|
||||
"args": { "channel_name": "wrong" },
|
||||
},
|
||||
],
|
||||
})
|
||||
checker = CeleryScript::Checker.new(tree, corpus, device)
|
||||
expect(checker.error.message).to include("not a valid channel_name")
|
||||
end
|
||||
|
@ -150,10 +150,10 @@ describe CeleryScript::Corpus do
|
|||
|
||||
it "Validates resource_update nodes" do
|
||||
ast = { "kind": "resource_update",
|
||||
"args": { "resource_type" => "Device",
|
||||
"resource_id" => 23, # Mutated to "0" later..
|
||||
"label" => "mounted_tool_id",
|
||||
"value" => 1 } }
|
||||
"args": { "resource_type" => "Device",
|
||||
"resource_id" => 23, # Mutated to "0" later..
|
||||
"label" => "mounted_tool_id",
|
||||
"value" => 1 } }
|
||||
checker = CeleryScript::Checker
|
||||
.new(CeleryScript::AstNode.new(**ast), corpus, device)
|
||||
expect(checker.valid?).to be(true)
|
||||
|
@ -164,10 +164,10 @@ describe CeleryScript::Corpus do
|
|||
fake_id = FactoryBot.create(:plant).id + 1
|
||||
expect(Plant.exists?(fake_id)).to be(false)
|
||||
ast = { "kind": "resource_update",
|
||||
"args": { "resource_type" => "Plant",
|
||||
"resource_id" => fake_id,
|
||||
"label" => "foo",
|
||||
"value" => "Should Fail" } }
|
||||
"args": { "resource_type" => "Plant",
|
||||
"resource_id" => fake_id,
|
||||
"label" => "foo",
|
||||
"value" => "Should Fail" } }
|
||||
hmm = CeleryScript::AstNode.new(**ast)
|
||||
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
|
||||
checker = CeleryScript::Checker.new(hmm, corpus, device)
|
||||
|
@ -177,10 +177,10 @@ describe CeleryScript::Corpus do
|
|||
|
||||
it "rejects bogus resource_types" do
|
||||
ast = { "kind": "resource_update",
|
||||
"args": { "resource_type" => "CanOpener",
|
||||
"resource_id" => 0,
|
||||
"label" => "foo",
|
||||
"value" => "Should Fail" } }
|
||||
"args": { "resource_type" => "CanOpener",
|
||||
"resource_id" => 0,
|
||||
"label" => "foo",
|
||||
"value" => "Should Fail" } }
|
||||
checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast),
|
||||
corpus,
|
||||
device)
|
||||
|
@ -224,9 +224,9 @@ describe CeleryScript::Corpus do
|
|||
|
||||
it "sets a MAX_WAIT_MS limit for `wait` nodes" do
|
||||
bad = CeleryScript::AstNode.new(**{
|
||||
kind: "wait",
|
||||
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
|
||||
})
|
||||
kind: "wait",
|
||||
args: { milliseconds: CeleryScriptSettingsBag::MAX_WAIT_MS + 10 },
|
||||
})
|
||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||
expect(check.valid?).to be_falsey
|
||||
expect(check.error.message).to include("cannot exceed 3 minutes")
|
||||
|
@ -238,9 +238,9 @@ describe CeleryScript::Corpus do
|
|||
name: "cs checks",
|
||||
point_ids: [])
|
||||
bad = CeleryScript::AstNode.new(**{
|
||||
kind: "point_group",
|
||||
args: { point_group_id: pg.id },
|
||||
})
|
||||
kind: "point_group",
|
||||
args: { point_group_id: pg.id },
|
||||
})
|
||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||
expect(check.valid?).to be true
|
||||
end
|
||||
|
@ -249,12 +249,35 @@ describe CeleryScript::Corpus do
|
|||
it "disallows invalid `point_group` nodes" do
|
||||
device.auto_sync_transaction do
|
||||
bad = CeleryScript::AstNode.new(**{
|
||||
kind: "point_group",
|
||||
args: { point_group_id: -1 },
|
||||
})
|
||||
kind: "point_group",
|
||||
args: { point_group_id: -1 },
|
||||
})
|
||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||
expect(check.valid?).to be false
|
||||
expect(check.error.message).to eq("Can't find PointGroup with id of -1")
|
||||
end
|
||||
end
|
||||
|
||||
it "validates the `package` for flash_firmware" do
|
||||
ok1 = CeleryScript::AstNode.new(**{
|
||||
args: {
|
||||
version: 20180209,
|
||||
locals: {
|
||||
kind: "scope_declaration",
|
||||
args: {},
|
||||
},
|
||||
},
|
||||
kind: "sequence",
|
||||
body: [
|
||||
{
|
||||
kind: "flash_firmware",
|
||||
args: {
|
||||
package: "arduino_firmware",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
check1 = CeleryScript::Checker.new(ok1, corpus, device)
|
||||
expect(check1.valid?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue