| 68 | } |
| 69 | |
| 70 | func TestHandler_Handle_POST_JSON(t *testing.T) { |
| 71 | h := &handler{} |
| 72 | body := `{"key":"value"}` |
| 73 | r := httptest.NewRequest("POST", "/api/endpoint", strings.NewReader(body)) |
| 74 | r.Header.Set("Content-Type", "application/json") |
| 75 | r.Host = "localhost:8000" |
| 76 | |
| 77 | inc, err := h.Handle(r) |
| 78 | if err != nil { |
| 79 | t.Fatal(err) |
| 80 | } |
| 81 | |
| 82 | var payload map[string]any |
| 83 | json.Unmarshal(inc.Payload, &payload) |
| 84 | |
| 85 | req, _ := payload["request"].(map[string]any) |
| 86 | post, _ := req["post"].(map[string]any) |
| 87 | if post["key"] != "value" { |
| 88 | t.Errorf("post.key = %v", post["key"]) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | func TestHandler_Handle_POST_PlainBody(t *testing.T) { |
| 93 | h := &handler{} |