add basic smoke tests for notices

This commit is contained in:
cblgh 2021-03-05 14:01:13 +01:00
parent c2ae71e2c7
commit 8d35860cde
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package handlers
import (
"net/http"
"testing"
"github.com/ssb-ngi-pointer/go-ssb-room/admindb"
"github.com/stretchr/testify/assert"
)
// TestNoticeSmokeTest ensures the most basic notice serving is working
func TestNoticeSmokeTest(t *testing.T) {
ts := setup(t)
a := assert.New(t)
noticeData := admindb.Notice{
ID: 1,
Title: "Welcome!",
}
ts.NoticeDB.GetByIDReturns(noticeData, nil)
html, res := ts.Client.GetHTML("/notice/show?id=1")
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
a.Equal("Welcome!", html.Find("title").Text())
}
func TestNoticeMarkdownServedCorrectly(t *testing.T) {
ts := setup(t)
a := assert.New(t)
markdown := `
Hello world!
## The loveliest of rooms is here
`
noticeData := admindb.Notice{
ID: 1,
Title: "Welcome!",
Content: markdown,
}
ts.NoticeDB.GetByIDReturns(noticeData, nil)
html, res := ts.Client.GetHTML("/notice/show?id=1")
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
a.Equal("Welcome!", html.Find("title").Text())
a.Equal("The loveliest of rooms is here", html.Find("h2").Text())
}