Move some tests to pending

Write a bunch of unit tests and mark some of them as pending.
This commit is contained in:
Robin Malley 2021-09-11 21:44:57 +00:00
parent ab6572314e
commit e0a8e01513
2 changed files with 108 additions and 6 deletions

View File

@ -34,7 +34,7 @@ describe("smr cacheing",function()
local cache = require("cache") local cache = require("cache")
renderspy = spy.on(cache,"render") renderspy = spy.on(cache,"render")
configure() configure()
error("TODO: complete") pending("TODO: complete")
end) end)
it("caches one page for domain/id and author.domain/id",function() it("caches one page for domain/id and author.domain/id",function()
local read_get = require("endpoints.read_get") local read_get = require("endpoints.read_get")
@ -68,7 +68,7 @@ describe("smr cacheing",function()
end) end)
describe("author home page",function() describe("author home page",function()
it("lists all stories by that author",function() it("lists all stories by that author",function()
error("TODO") pending("TODO")
end) end)
end) end)
end) end)

View File

@ -52,17 +52,21 @@ describe("smr login",function()
) )
end) end)
it("should give a session cookie when logging in with a user",function() it("should give a session cookie when logging in with a user",function()
pending("Look at cleaning mock env")
mock_env.mockdb() mock_env.mockdb()
local claim_post = require("endpoints.claim_post") local claim_post = require("endpoints.claim_post")
local login_post = require("endpoints.login_post") local login_post = require("endpoints.login_post")
local config = require("config") local config = require("config")
local db = require("db")
configure() configure()
local username = "nuser"
local claim_req = { local claim_req = {
method = "POST", method = "POST",
host = "test.host", host = "test.host",
path = "/_claim", path = "/_claim",
args = { args = {
user = "user" user = username
} }
} }
claim_post(claim_req) claim_post(claim_req)
@ -71,7 +75,7 @@ describe("smr login",function()
host = "test.host", host = "test.host",
path = "/_login", path = "/_login",
args = { args = {
user = "user" user = username
}, },
file = { file = {
pass = claim_req.response pass = claim_req.response
@ -81,7 +85,7 @@ describe("smr login",function()
local code = login_req.responsecode local code = login_req.responsecode
assert( assert(
code >= 300 and code <= 400, code >= 300 and code <= 400,
"Sucessful login should redirect the user" "Sucessful login should redirect the user, code:" .. tostring(code)
) )
assert( assert(
login_req.response_headers, login_req.response_headers,
@ -114,8 +118,106 @@ describe("smr login",function()
"Sucessful login should redirect to a location" "Sucessful login should redirect to a location"
) )
assert( assert(
login_req.response_headers["Location"] == "https://user." .. config.domain, login_req.response_headers["Location"] == "https://" .. username .. "." .. config.domain,
"Login redirect should get domain from config file" "Login redirect should get domain from config file"
) )
end) end)
it("should allow logged in users the option of posting under their username",function()
pending("Fix up cleaning db for unit tests")
mock_env.mockdb()
local claim_post = require("endpoints.claim_post")
local login_post = require("endpoints.login_post")
local paste_get = require("endpoints.paste_get")
local paste_post = require("endpoints.paste_post")
local read_get = require("endpoints.read_get")
local db = require("db")
local config = require("config")
config.domain = "test.host"
configure()
local claim_req = {
method = "POST",
host = "test.host",
path = "/_claim",
args = {
user = "user"
}
}
claim_post(claim_req)
login_req = {
method = "POST",
host = "test.host",
path = "/_login",
args = {
user = "user"
},
file = {
pass = claim_req.response
}
}
login_post(login_req)
local cookie = login_req.response_headers["set-cookie"]
local sessionid = cookie:match("session=([^;]+)")
local paste_req_get = {
method = "GET",
host = "user.test.host",
path = "/_paste",
cookies = {
session = sessionid
}
}
paste_get(paste_req_get)
local option = '<option value="user">user</option>'
assert(
paste_req_get.response:find(option),
"After logging in the user should have an option to "..
"make posts as themselves. Looking for " .. option ..
" but didn't find it in " .. paste_req_get.response
)
local paste_req_post = {
method = "POST",
host = "user.test.host",
path = "/_paste",
cookies = {
session = sessionid
},
args = {
title = "post title",
text = "post text",
markup = "plain",
tags = "",
}
}
paste_post(paste_req_post)
for row in db.conn:rows("SELECT COUNT(*) FROM posts") do
assert(row[1] == 1, "Expected exactly 1 post in sample db")
end
local code = paste_req_post.responsecode
assert(code >= 300 and code <= 400, "Should receive a redirect after posting, got:" .. tostring(code))
assert(paste_req_post.response_headers, "Should have received some response headers")
assert(paste_req_post.response_headers.Location, "Should have received a location in response headers")
local redirect = paste_req_post.response_headers.Location:match("(/[^/]*)$")
local read_req_get = {
method = "GET",
host = "user.test.host",
path = redirect,
cookies = {
session = sessionid
},
args = {}
}
read_get(read_req_get)
local response = read_req_get.response
assert(
response:find([[post title]]),
"Failed to find post title in response."
)
assert(
response:find([[By <a href="https://user.test.host">user</a>]]),
"Failed to find the author name after a paste."
)
assert(
response:find([[post text]]),
"Failed to find post text in response."
)
end)
end) end)