| 2492 | } |
| 2493 | |
| 2494 | func TestSendNotes_isBehind(t *testing.T) { |
| 2495 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2496 | if r.URL.String() == "/v3/notes" && r.Method == "POST" { |
| 2497 | var payload client.CreateBookPayload |
| 2498 | |
| 2499 | err := json.NewDecoder(r.Body).Decode(&payload) |
| 2500 | if err != nil { |
| 2501 | t.Fatal(errors.Wrap(err, "decoding payload in the test server").Error()) |
| 2502 | return |
| 2503 | } |
| 2504 | |
| 2505 | resp := client.CreateNoteResp{ |
| 2506 | Result: client.RespNote{ |
| 2507 | USN: 11, |
| 2508 | }, |
| 2509 | } |
| 2510 | |
| 2511 | w.Header().Set("Content-Type", "application/json") |
| 2512 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2513 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2514 | return |
| 2515 | } |
| 2516 | return |
| 2517 | } |
| 2518 | |
| 2519 | p := strings.Split(r.URL.Path, "/") |
| 2520 | if len(p) == 4 && p[0] == "" && p[1] == "v3" && p[2] == "notes" { |
| 2521 | if r.Method == "PATCH" { |
| 2522 | resp := client.UpdateNoteResp{ |
| 2523 | Result: client.RespNote{ |
| 2524 | USN: 11, |
| 2525 | }, |
| 2526 | } |
| 2527 | |
| 2528 | w.Header().Set("Content-Type", "application/json") |
| 2529 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2530 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2531 | return |
| 2532 | } |
| 2533 | return |
| 2534 | } else if r.Method == "DELETE" { |
| 2535 | resp := client.DeleteNoteResp{ |
| 2536 | Result: client.RespNote{ |
| 2537 | USN: 11, |
| 2538 | }, |
| 2539 | } |
| 2540 | |
| 2541 | w.Header().Set("Content-Type", "application/json") |
| 2542 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
| 2543 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 2544 | return |
| 2545 | } |
| 2546 | return |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | t.Fatalf("unrecognized endpoint reached Method: %s Path: %s", r.Method, r.URL.Path) |
| 2551 | })) |