Skip to content

Commit

Permalink
simplfy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Jan 19, 2024
1 parent 16281ed commit 2a37723
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions spec/01-unit/01-db/01-schema/06-routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1580,49 +1580,28 @@ describe("routes schema (flavor = expressions)", function()
id = a_valid_uuid,
name = "my_route",
protocols = { "http" },
expression = [[http.path.segments. == "foo"]],
priority = 100,
service = { id = another_uuid },
}

local route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])

r.expression = [[http.path.segments.abc == "foo"]]

route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])

r.expression = [[http.path.segments.1_2_3 == "foo"]]

route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])

r.expression = [[http.path.segments.1_ == "foo"]]

route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])

r.expression = [[http.path.segments.2_1 == "foo"]]

route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])
local wrong_expressions = {
[[http.path.segments. == "foo"]],
[[http.path.segments.abc == "foo"]],
[[http.path.segments.a_c == "foo"]],
[[http.path.segments.1_2_3 == "foo"]],
[[http.path.segments.1_ == "foo"]],
[[http.path.segments._1 == "foo"]],
[[http.path.segments.2_1 == "foo"]],
[[http.path.segments.1_1 == "foo"]],
}

r.expression = [[http.path.segments.1_1 == "foo"]]
for _, exp in ipairs(wrong_expressions) do
r.expression = exp

route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])
local route = Routes:process_auto_fields(r, "insert")
local ok, errs = Routes:validate_insert(route)
assert.falsy(ok)
assert.truthy(errs["@entity"])
end
end)
end)

0 comments on commit 2a37723

Please sign in to comment.