smr/spec/pages_sanity_spec.lua

139 lines
2.5 KiB
Lua
Raw Normal View History

2020-12-23 07:02:02 +01:00
function() return math.random() > 0.5 and "plain" or "imageboard" end
2020-12-21 05:22:22 +01:00
local pages = {
index = {
route = "/",
name = "home",
methods = {
GET={}
}
},
paste = {
route = "/_paste",
name = "post_story",
methods = {
GET={},
2020-12-23 07:02:02 +01:00
POST={
title = rng_any,
text = rng_any,
pasteas = rng_subdomain,
markup = rng_markup
tags = rng_any;
}
2020-12-21 05:22:22 +01:00
}
},
edit = {
route = "/_edit",
name = "edit",
methods = {
2020-12-23 07:02:02 +01:00
GET={
story=rng_storyid
},
POST={
title = rng_any,
text = rng_any,
pasteas = rng_subdomain,
markup = rng_markup,
tags = rng_any
},
2020-12-21 05:22:22 +01:00
}
},
--TODO:bio
login = {
route = "/_login",
name = "login",
methods = {
GET={},
2020-12-23 07:02:02 +01:00
POST={
user = rng_subdomain,
pass = rng_any
},
2020-12-21 05:22:22 +01:00
}
},
claim = {
route = "/_claim",
name = "claim",
methods = {
GET = {},
2020-12-23 07:02:02 +01:00
POST = {
user = rng_subdomain
}
2020-12-21 05:22:22 +01:00
}
},
download = {
route = "/_download",
name = "download",
methods = {
2020-12-23 07:02:02 +01:00
GET = {
story = rng_storyid
},
2020-12-21 05:22:22 +01:00
}
},
preview = {
route = "/_preview",
name = "preview",
methods = {
POST = {},
}
},
search = {
route = "/_search",
name = "search",
methods = {
GET = {},
}
}
}
2020-12-23 07:02:02 +01:00
local request_stub_m = {}
2020-12-21 05:22:22 +01:00
function http_response(req,errcode,str)
2020-12-23 07:02:02 +01:00
req.responded = true
req.errcode = errcode
req.message = str
2020-12-21 05:22:22 +01:00
end
function http_request_get_host(reqstub)
return "localhost:8888"
end
function http_request_populate_post(reqstub)
reqstub.post_populated = true
end
2020-12-23 07:02:02 +01:00
local function fuzz_endpoint(endpoint, parameters)
for i = 1,100 do
local req = {}
for paramtype, params in pairs(parameters) do
end
end
return true
end
2020-12-21 05:22:22 +01:00
describe("smr",function()
for name, obj in pairs(pages) do
describe("endpoint " .. name,function()
for method,parameters in pairs(obj.methods) do
describe("method " .. method,function()
local fname = string.format("%s_%s",name,string.lower(method))
it("should be named appropriately",function()
2020-12-23 07:02:02 +01:00
local f = assert(io.open("endpoints/"..fname .. ".lua","r"))
2020-12-21 05:22:22 +01:00
end)
it("should run without errors",function()
2020-12-23 07:02:02 +01:00
require("endpoints." .. fname)
2020-12-21 05:22:22 +01:00
end)
it("should return a function",function()
2020-12-23 07:02:02 +01:00
function configure(...) print("configure called") end
local pagefunc = assert(require("endpoints." .. fname))
2020-12-21 05:22:22 +01:00
assert(type(pagefunc) == "function")
end)
2020-12-23 07:02:02 +01:00
it("should call http_response() at some point",function()
local pagefunc = require("endpoints." .. fname)
assert(fuzz_endpoint(pagefunc,parameters))
2020-12-21 05:22:22 +01:00
end)
end)
end
end)
end
end)