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"
|
|
|
|
|
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 := "/61590/Black-star-respiration/The-new-moon-rode-high-in-the-crown-of-the-metropolis/annotations"
|
|
|
|
|
|
|
|
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)
|
|
|
|
annotation := map[string]string{}
|
|
|
|
|
|
|
|
if err := decoder.Decode(&annotation); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, exists := annotation["html"]; !exists {
|
|
|
|
t.Fatalf("html field not found on annotation\n")
|
|
|
|
}
|
|
|
|
}
|