-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-api_helpers_spec.lua
80 lines (78 loc) · 2.34 KB
/
09-api_helpers_spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local api_helpers = require "kong.api.api_helpers"
local norm = api_helpers.normalize_nested_params
describe("api_helpers", function()
describe("normalize_nested_params()", function()
it("renders table from dot notation", function()
assert.same({
foo = "bar",
number = 10,
config = {
nested = 1,
nested_2 = 2
}
}, norm {
foo = "bar",
number = 10,
["config.nested"] = 1,
["config.nested_2"] = 2
})
assert.same({
foo = 'bar',
number = 10,
config = {
nested = {
["sub-nested"] = "hi"
},
nested_1 = 1,
nested_2 = 2
}
}, norm {
foo = "bar",
number = 10,
["config.nested_1"] = 1,
["config.nested_2"] = 2,
["config.nested.sub-nested"] = "hi"
})
end)
it("integer indexes arrays with integer strings", function()
assert.same({
foo = 'bar',
number = 10,
config = {
nested = {"hello", "world"},
}
}, norm {
foo = "bar",
number = 10,
["config.nested"] = {["1"]="hello", ["2"]="world"}
})
end)
it("complete use case", function()
assert.same({
api_id = 123,
name = "request-transformer",
config = {
add = {
form = "new-form-param:some_value, another-form-param:some_value",
headers = "x-new-header:some_value, x-another-header:some_value",
querystring = "new-param:some_value, another-param:some_value"
},
remove = {
form = "formparam-toremove",
headers = "x-toremove, x-another-one",
querystring = "param-toremove, param-another-one"
}
}
}, norm {
api_id = 123,
name = "request-transformer",
["config.add.headers"] = "x-new-header:some_value, x-another-header:some_value",
["config.add.querystring"] = "new-param:some_value, another-param:some_value",
["config.add.form"] = "new-form-param:some_value, another-form-param:some_value",
["config.remove.headers"] = "x-toremove, x-another-one",
["config.remove.querystring"] = "param-toremove, param-another-one",
["config.remove.form"] = "formparam-toremove"
})
end)
end)
end)