Skip to content

Commit

Permalink
Major fixes; Changed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Dec 5, 2024
1 parent 169fbd1 commit f6a0eb8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
10 changes: 8 additions & 2 deletions http/handler_ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestCCIPGet_WithValidData(t *testing.T) {
resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x"))
require.NoError(t, err)

assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex))
assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}, {"name": "adam"}]}}`, string(resHex))
}

func TestCCIPGet_WithSubscription(t *testing.T) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCCIPPost_WithValidData(t *testing.T) {
resHex, err := hex.DecodeString(strings.TrimPrefix(ccipRes.Data, "0x"))
require.NoError(t, err)

assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}]}}`, string(resHex))
assert.JSONEq(t, `{"data": {"User": [{"name": "bob"}, {"name": "adam"}]}}`, string(resHex))
}

func TestCCIPPost_WithInvalidGraphQLRequest(t *testing.T) {
Expand Down Expand Up @@ -210,5 +210,11 @@ func setupDatabase(t *testing.T) client.DB {
err = col.Create(ctx, doc)
require.NoError(t, err)

doc2, err := client.NewDocFromJSON([]byte(`{"name": "adam"}`), col.Definition())
require.NoError(t, err)

err = col.Create(ctx, doc2)
require.NoError(t, err)

return cdb
}
3 changes: 3 additions & 0 deletions http/handler_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ func (s *storeHandler) ExecRequest(rw http.ResponseWriter, req *http.Request) {
var request GraphQLRequest
switch {
case req.URL.Query().Get("query") != "":

request.Query = req.URL.Query().Get("query")

request.OperationName = req.URL.Query().Get("operationName")

variablesFromQuery := req.URL.Query().Get("variables")
if variablesFromQuery != "" {
var variables map[string]any
Expand Down
36 changes: 32 additions & 4 deletions http/handler_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ func TestExecRequest_WithInvalidQuery_HasSpecCompliantErrors(t *testing.T) {
func TestExecRequest_HttpGet_WithOperationName(t *testing.T) {
cdb := setupDatabase(t)

query := `query UserQuery {
query := `
query UserQuery {
User {
name
}
}`
}
query UserQueryWithDocID {
User {
_docID
name
}
}
`
operationName := "UserQuery"

encodedQuery := url.QueryEscape(query)
Expand All @@ -123,15 +131,25 @@ func TestExecRequest_HttpGet_WithOperationName(t *testing.T) {
resData, err := io.ReadAll(res.Body)
require.NoError(t, err)

t.Log(string(resData))

var gqlResponse map[string]any
err = json.Unmarshal(resData, &gqlResponse)
require.NoError(t, err)

// errors should be omitted
_, ok := gqlResponse["errors"]
assert.False(t, ok)

// Compare the response data to the expected output
expectedJSON := `{
"data": {
"User": [
{"name": "bob"},
{"name": "adam"}
]
}
}`
assert.JSONEq(t, expectedJSON, string(resData))

}

Check failure on line 153 in http/handler_store_test.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

unnecessary trailing newline (whitespace)

func TestExecRequest_HttpGet_WithVariables(t *testing.T) {
Expand Down Expand Up @@ -171,4 +189,14 @@ func TestExecRequest_HttpGet_WithVariables(t *testing.T) {
// errors should be omitted
_, ok := gqlResponse["errors"]
assert.False(t, ok)

// Compare the response data to the expected output
expectedJSON := `{
"data": {
"User": [
{"name": "bob"}
]
}
}`
assert.JSONEq(t, expectedJSON, string(resData))
}

0 comments on commit f6a0eb8

Please sign in to comment.