local describe = require("lua_test.test").describe
local test = require("lua_test.test").test
local expect = require("lua_test.test").expect
describe("RES.ok - nil and empty string handling", function()
local RES
local function setup()
package.loaded["pasta.shiori.res"] = nil
RES = require("pasta.shiori.res")
end
test("returns no_content when value is nil", function()
setup()
local result = RES.ok(nil)
expect(result:find("204 No Content")).not_:toBe(nil)
expect(result:find("Value:")):toBe(nil)
end)
test("returns no_content when value is empty string", function()
setup()
local result = RES.ok("")
expect(result:find("204 No Content")).not_:toBe(nil)
expect(result:find("Value:")):toBe(nil)
end)
test("returns 200 OK with Value header when value is valid string", function()
setup()
local result = RES.ok("Hello World")
expect(result:find("200 OK")).not_:toBe(nil)
expect(result:find("Value: Hello World")).not_:toBe(nil)
end)
test("preserves additional headers when returning no_content for nil", function()
setup()
local result = RES.ok(nil, { Reference0 = "test" })
expect(result:find("204 No Content")).not_:toBe(nil)
expect(result:find("Reference0: test")).not_:toBe(nil)
end)
test("preserves additional headers when returning no_content for empty string", function()
setup()
local result = RES.ok("", { Reference0 = "test" })
expect(result:find("204 No Content")).not_:toBe(nil)
expect(result:find("Reference0: test")).not_:toBe(nil)
end)
test("returns 200 OK with additional headers for valid string", function()
setup()
local result = RES.ok("Response", { Reference0 = "extra" })
expect(result:find("200 OK")).not_:toBe(nil)
expect(result:find("Value: Response")).not_:toBe(nil)
expect(result:find("Reference0: extra")).not_:toBe(nil)
end)
test("whitespace-only string is treated as valid (not empty)", function()
setup()
local result = RES.ok(" ")
expect(result:find("200 OK")).not_:toBe(nil)
expect(result:find("Value: ")).not_:toBe(nil)
end)
end)