1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-28 08:58:38 +02:00
authboss/defaults/renderer_test.go
2020-07-03 11:24:07 -07:00

43 lines
925 B
Go

package defaults
import (
"context"
"testing"
"github.com/volatiletech/authboss/v3"
)
func TestJSONRenderer(t *testing.T) {
t.Parallel()
r := JSONRenderer{}
success := authboss.HTMLData{"fun": "times"}
failure := authboss.HTMLData{authboss.DataErr: "problem"}
hasAlready := authboss.HTMLData{authboss.DataErr: "problem", "status": "noproblem"}
b, _, err := r.Render(context.Background(), "", success)
if err != nil {
t.Error(err)
}
if string(b) != `{"fun":"times","status":"success"}` {
t.Errorf("wrong json: %s", b)
}
b, _, err = r.Render(context.Background(), "", failure)
if err != nil {
t.Error(err)
}
if string(b) != `{"error":"problem","status":"failure"}` {
t.Errorf("wrong json: %s", b)
}
b, _, err = r.Render(context.Background(), "", hasAlready)
if err != nil {
t.Error(err)
}
if string(b) != `{"error":"problem","status":"noproblem"}` {
t.Errorf("wrong json: %s", b)
}
}