videoconf/app_test.go

83 lines
1.9 KiB
Go
Raw Normal View History

2016-02-29 20:16:20 +01:00
package main
import (
2016-03-03 10:38:57 +01:00
"bytes"
2016-02-29 20:16:20 +01:00
"net/http"
"net/http/httptest"
"testing"
2016-03-01 19:40:13 +01:00
. "github.com/franela/goblin"
"github.com/gin-gonic/gin"
2016-02-29 20:16:20 +01:00
)
2016-03-01 19:14:44 +01:00
const Cookie = "Set-Cookie"
2016-03-01 19:40:13 +01:00
func client(method, path, cookie string) *httptest.ResponseRecorder {
2016-03-03 10:38:57 +01:00
return request(method, path, cookie, "")
}
func request(method, path, cookie string, body string) *httptest.ResponseRecorder {
2016-02-29 20:29:47 +01:00
gin.SetMode("test")
app := NewApp()
2016-03-03 10:38:57 +01:00
payload := bytes.NewBufferString(body)
req, _ := http.NewRequest(method, path, payload)
2016-03-01 19:40:13 +01:00
if len(cookie) != 0 {
req.Header.Set("Cookie", cookie)
2016-03-01 19:14:44 +01:00
}
2016-02-29 20:16:20 +01:00
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
return w
}
func Test(t *testing.T) {
g := Goblin(t)
g.Describe("App api", func() {
2016-03-01 19:40:13 +01:00
var cookie string
2016-02-29 20:16:20 +01:00
2018-01-19 02:15:19 +01:00
g.It("Should return 302 on / to redirect to file name ", func() {
2016-03-01 19:14:44 +01:00
w := client("GET", "/", "")
2018-01-19 02:15:19 +01:00
g.Assert(w.Code).Equal(302)
2016-03-01 19:40:13 +01:00
cookie = w.HeaderMap.Get(Cookie)
2016-02-29 20:16:20 +01:00
})
g.It("Should return 200 on /slides.md ", func() {
2016-03-01 19:40:13 +01:00
w := client("GET", "/slides.md", cookie)
2016-02-29 20:16:20 +01:00
g.Assert(w.Code).Equal(200)
})
g.It("Should return 200 on PUT /slides.md ", func() {
2016-03-03 10:38:57 +01:00
w := request("PUT", "/slides.md", cookie, "whatever")
2016-02-29 20:16:20 +01:00
g.Assert(w.Code).Equal(200)
})
2016-03-02 22:55:10 +01:00
g.It("Should return list of slides ", func() {
w := client("GET", "/stash", cookie)
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in preview", func() {
2016-03-03 10:38:57 +01:00
w := client("GET", "/published/slides/shy-cell.md", cookie)
2016-03-02 22:55:10 +01:00
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in edit mode", func() {
w := client("GET", "/stash/edit/shy-cell.md", cookie)
g.Assert(w.Code).Equal(200)
})
2016-03-03 10:38:57 +01:00
g.It("Should return specific slide in preview without session", func() {
w := client("GET", "/published/slides/shy-cell.md", "")
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in edit mode without session", func() {
w := client("GET", "/stash/edit/shy-cell.md", "")
g.Assert(w.Code).Equal(200)
})
2016-02-29 20:16:20 +01:00
g.It("Should works")
})
}