Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(db): add shorthands precedence test when using complex records #13554

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
48 changes: 44 additions & 4 deletions spec/01-unit/01-db/01-schema/01-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,12 @@ describe("schema", function()
name = "test",
fields = {
{ name = { type = "string" } },
{ record = {
type = "record",
fields = {
{ x = { type = "string" } }
},
}},
},
shorthand_fields = {
{
Expand All @@ -4127,19 +4133,37 @@ describe("schema", function()
end,
},
},
{
y = {
type = "string",
func = function(value)
return {
record = {
x = value,
},
}
end,
},
},
},
})

local input = { username = "test1", name = "ignored" }
local input = { username = "test1", name = "ignored", record = { x = "ignored" }, y = "test1" }
local output, _ = TestSchema:process_auto_fields(input)
assert.same({ name = "test1" }, output)
assert.same({ name = "test1", record = { x = "test1" } }, output)
end)

it("does not take precedence if deprecated", function()
local TestSchema = Schema.new({
name = "test",
fields = {
{ name = { type = "string" } },
{ record = {
type = "record",
fields = {
{ x = { type = "string" } }
},
}},
},
shorthand_fields = {
{
Expand All @@ -4156,12 +4180,28 @@ describe("schema", function()
},
},
},
{
y = {
type = "string",
func = function(value)
return {
record = {
x = value,
},
}
end,
deprecation = {
message = "y is deprecated, please use record.x instead",
removal_in_version = "4.0",
},
},
},
},
})

local input = { username = "ignored", name = "test1" }
local input = { username = "ignored", name = "test1", record = { x = "test1" }, y = "ignored" }
local output, _ = TestSchema:process_auto_fields(input)
assert.same({ name = "test1" }, output)
assert.same({ name = "test1", record = { x = "test1" } }, output)
end)

it("can produce multiple fields", function()
Expand Down
Loading