Skip to content

Commit 46eda57

Browse files
committed
Add test
1 parent 9f33753 commit 46eda57

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

relay/relay_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,27 @@ func TestServeHTTP(t *testing.T) {
3434
t.Fatalf("Invalid response. Expected [%s], but instead got [%s]", expectedResponse, actualResponse)
3535
}
3636
}
37+
38+
func TestBatchedServeHTTP(t *testing.T) {
39+
w := httptest.NewRecorder()
40+
r := httptest.NewRequest("POST", "/some/path/here", strings.NewReader(`[{"id":"qID", "query":"{ hero { name } }", "operationName":"", "variables": null},
41+
{"id":"qID", "query":"{ hero { name } }", "operationName":"", "variables": null}]`))
42+
h := relay.BatchedHandler{Schema: starwarsSchema}
43+
44+
h.ServeHTTP(w, r)
45+
46+
if w.Code != 200 {
47+
t.Fatalf("Expected status code 200, got %d.", w.Code)
48+
}
49+
50+
contentType := w.Header().Get("Content-Type")
51+
if contentType != "application/json" {
52+
t.Fatalf("Invalid content-type. Expected [application/json], but instead got [%s]", contentType)
53+
}
54+
55+
expectedResponse := `[{"id":"qID","data":{"hero":{"name":"R2-D2"}}},{"id":"qID","data":{"hero":{"name":"R2-D2"}}}]`
56+
actualResponse := w.Body.String()
57+
if expectedResponse != actualResponse {
58+
t.Fatalf("Invalid response. Expected [%s], but instead got [%s]", expectedResponse, actualResponse)
59+
}
60+
}

0 commit comments

Comments
 (0)