| 2081 | } |
| 2082 | |
| 2083 | func TestSendBooks_isBehind(t *testing.T) { |
| 2084 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2085 | if r.URL.String() == "/v3/books" && r.Method == "POST" { |
| 2086 | var payload client.CreateBookPayload |
| 2087 | |
| 2088 | err := json.NewDecoder(r.Body).Decode(&payload) |
| 2089 | if err != nil { |
| 2090 | t.Fatal(errors.Wrap(err, "decoding payload in the test server").Error()) |
| 2091 | return |
| 2092 | } |
| 2093 | |
| 2094 | resp := client.CreateBookResp{ |
| 2095 | Book: client.RespBook{ |
| 2096 | USN: 11, |
| 2097 | }, |
| 2098 | } |
| 2099 | |
| 2100 | w.Header().Set("Content-Type", "application/json") |
| 2101 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2102 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2103 | return |
| 2104 | } |
| 2105 | return |
| 2106 | } |
| 2107 | |
| 2108 | p := strings.Split(r.URL.Path, "/") |
| 2109 | if len(p) == 4 && p[0] == "" && p[1] == "v3" && p[2] == "books" { |
| 2110 | if r.Method == "PATCH" { |
| 2111 | resp := client.UpdateBookResp{ |
| 2112 | Book: client.RespBook{ |
| 2113 | USN: 11, |
| 2114 | }, |
| 2115 | } |
| 2116 | |
| 2117 | w.Header().Set("Content-Type", "application/json") |
| 2118 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2119 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2120 | return |
| 2121 | } |
| 2122 | return |
| 2123 | } else if r.Method == "DELETE" { |
| 2124 | resp := client.DeleteBookResp{ |
| 2125 | Book: client.RespBook{ |
| 2126 | USN: 11, |
| 2127 | }, |
| 2128 | } |
| 2129 | |
| 2130 | w.Header().Set("Content-Type", "application/json") |
| 2131 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2132 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2133 | return |
| 2134 | } |
| 2135 | return |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | t.Fatalf("unrecognized endpoint reached Method: %s Path: %s", r.Method, r.URL.Path) |
| 2140 | })) |