1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

rest: Implement MarkSeen for #58

- message: Add MarkSeen to Manager, StoreManager.
- rest: Add PATCH for /mailbox/name/id.
- rest: Add MailboxMarkSeenV1 handler.
- rest: Add Seen to model.
- rest: Update handlers to set Seen.
- rest: Add doJSONBody func.
This commit is contained in:
James Hillyerd
2018-04-01 11:13:33 -07:00
parent cc5cd7f9c3
commit dc02092cf6
11 changed files with 247 additions and 17 deletions

View File

@@ -21,7 +21,17 @@ func testRestGet(url string) (*httptest.ResponseRecorder, error) {
if err != nil {
return nil, err
}
w := httptest.NewRecorder()
web.Router.ServeHTTP(w, req)
return w, nil
}
func testRestPatch(url string, body string) (*httptest.ResponseRecorder, error) {
req, err := http.NewRequest("PATCH", url, strings.NewReader(body))
req.Header.Add("Accept", "application/json")
if err != nil {
return nil, err
}
w := httptest.NewRecorder()
web.Router.ServeHTTP(w, req)
return w, nil
@@ -46,6 +56,22 @@ func setupWebServer(mm message.Manager) *bytes.Buffer {
return buf
}
func decodedBoolEquals(t *testing.T, json interface{}, path string, want bool) {
t.Helper()
els := strings.Split(path, "/")
val, msg := getDecodedPath(json, els...)
if msg != "" {
t.Errorf("JSON result%s", msg)
return
}
if got, ok := val.(bool); ok {
if got == want {
return
}
}
t.Errorf("JSON result/%s == %v (%T), want: %v", path, val, val, want)
}
func decodedNumberEquals(t *testing.T, json interface{}, path string, want float64) {
t.Helper()
els := strings.Split(path, "/")