Add test for mark_read and unknown POST action
This commit is contained in:
parent
226a35fb43
commit
47661b73f1
|
@ -324,13 +324,14 @@ func (c *Client) Search(query string) ([]microsub.Feed, error) {
|
|||
func (c *Client) MarkRead(channel string, uids []string) error {
|
||||
args := make(map[string]string)
|
||||
args["channel"] = channel
|
||||
args["method"] = "mark_read"
|
||||
|
||||
data := url.Values{}
|
||||
for _, uid := range uids {
|
||||
data.Add("entry[]", uid)
|
||||
}
|
||||
|
||||
res, err := c.microsubPostFormRequest("mark_read", args, data)
|
||||
res, err := c.microsubPostFormRequest("timeline", args, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -210,9 +210,8 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
respondJSON(w, []string{})
|
||||
} else {
|
||||
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)
|
||||
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 400)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
@ -133,7 +133,14 @@ func TestServer_Search(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServer_UnknownAction(t *testing.T) {
|
||||
func TestServer_MarkRead(t *testing.T) {
|
||||
server, c := createServerClient()
|
||||
defer server.Close()
|
||||
err := c.MarkRead("0001", []string{"test"})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestServer_GetUnknownAction(t *testing.T) {
|
||||
server, c := createServerClient()
|
||||
defer server.Close()
|
||||
|
||||
|
@ -147,3 +154,17 @@ func TestServer_UnknownAction(t *testing.T) {
|
|||
assert.Equal(t, 400, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
func TestServer_PostUnknownAction(t *testing.T) {
|
||||
server, c := createServerClient()
|
||||
defer server.Close()
|
||||
|
||||
u := c.MicrosubEndpoint
|
||||
q := u.Query()
|
||||
q.Add("action", "missing")
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
resp, err := http.Post(u.String(), "application/json", nil)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, 400, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user