Skip to content

Commit

Permalink
add basic smoke tests for notices
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Mar 16, 2021
1 parent c2ae71e commit 8d35860
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions web/handlers/notices_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 8d35860

Please sign in to comment.