dumb/handlers/annotations_test.go

41 lines
795 B
Go
Raw Permalink Normal View History

2024-03-06 20:53:29 +01:00
package handlers
import (
"encoding/json"
"net/http"
"net/http/httptest"
2024-05-02 21:29:50 +01:00
"os"
2024-03-06 20:53:29 +01:00
"testing"
"github.com/rramiachraf/dumb/data"
2024-05-02 21:29:50 +01:00
"github.com/rramiachraf/dumb/utils"
2024-03-06 20:53:29 +01:00
)
func TestAnnotations(t *testing.T) {
url := "/943841/Black-star-respiration/Shinin-like-who-on-top-of-this/annotations"
2024-03-06 20:53:29 +01:00
r, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
2024-05-02 21:29:50 +01:00
l := utils.NewLogger(os.Stdout)
2024-05-03 14:47:57 +01:00
m := New(l, &assets{})
2024-03-06 20:53:29 +01:00
m.ServeHTTP(rr, r)
defer rr.Result().Body.Close()
decoder := json.NewDecoder(rr.Result().Body)
var annotation data.Annotation
2024-03-06 20:53:29 +01:00
if err := decoder.Decode(&annotation); err != nil {
t.Fatal(err)
}
if annotation.State != "accepted" {
t.Fatalf("expected state to be %q, got %q\n", "accepted", annotation.State)
2024-03-06 20:53:29 +01:00
}
}