-
Notifications
You must be signed in to change notification settings - Fork 346
Add unit tests and fix few issues #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3534a79
cd9138e
fe3eb55
41e3925
15b6a03
b70f038
867d6ef
94456c6
a4e31d8
3654899
d7d96a7
d0346ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Net.Http; | ||
| using System.Security.Claims; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -42,6 +43,8 @@ type Query { | |
| getPlanet(id: ID, name: String): Planet | ||
| planetList: [Planet] | ||
| planets(first: Int, after: String): PlanetConnection | ||
| getPlanetListById(id: ID): [Planet] | ||
| getPlanetByName(name: String): Planet | ||
|
Comment on lines
+46
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These queries won't exist when #399 merges as we don't generate queries that match that signature, instead we use the typed filter (see https://github.com/Azure/project-hawaii/issues/11 for more on the typed filter). Consider what will needed to be done to refactor the tests that use those queries, and whether it'd be better to write them now to use a typed filter, rather than prepare something for a rewrite later on.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a very good point Aaron. I think this test atleast is good with what we have already checked in today. May be we can just clean this up when 399 merges? |
||
| } | ||
|
|
||
| type Mutation { | ||
|
|
@@ -65,7 +68,8 @@ type Character { | |
|
|
||
| type Planet { | ||
| id : ID, | ||
| name : String | ||
| name : String, | ||
| character: Character | ||
| }"; | ||
|
|
||
| _metadataStoreProvider.GraphQLSchema = jsonString; | ||
|
|
@@ -109,9 +113,11 @@ private static DefaultHttpContext GetHttpContextWithBody(string data) | |
| HttpRequestMessage request = new(); | ||
| MemoryStream stream = new(Encoding.UTF8.GetBytes(data)); | ||
| request.Method = HttpMethod.Post; | ||
| ClaimsPrincipal user = new(new ClaimsIdentity(authenticationType: "Bearer")); | ||
| DefaultHttpContext httpContext = new() | ||
| { | ||
| Request = { Body = stream, ContentLength = stream.Length } | ||
| Request = { Body = stream, ContentLength = stream.Length }, | ||
| User = user | ||
| }; | ||
| return httpContext; | ||
| } | ||
|
|
@@ -182,7 +188,8 @@ internal static async Task<JsonElement> ExecuteGraphQLRequestAsync(string queryN | |
|
|
||
| if (graphQLResult.TryGetProperty("errors", out JsonElement errors)) | ||
| { | ||
| Assert.Fail(errors.GetRawText()); | ||
| // to validate expected errors and error message | ||
| return errors; | ||
| } | ||
|
|
||
| return graphQLResult.GetProperty("data").GetProperty(queryName); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ private async Task<JObject> ExecuteAsync(IDictionary<string, object?> inputDict, | |
|
|
||
| JObject jObject; | ||
|
|
||
| if (inputDict != null) | ||
| if (inputDict != null && inputDict.Count > 0) | ||
| { | ||
| // TODO: optimize this multiple round of serialization/deserialization | ||
| string json = JsonConvert.SerializeObject(inputDict); | ||
|
|
@@ -75,7 +75,7 @@ private async Task<JObject> ExecuteAsync(IDictionary<string, object?> inputDict, | |
|
|
||
| break; | ||
| default: | ||
| throw new NotSupportedException($"unsupprted operation type: {resolver.OperationType.ToString()}"); | ||
| throw new NotSupportedException($"unsupported operation type: {resolver.OperationType.ToString()}"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be converted to a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we are not using |
||
| } | ||
|
|
||
| return response.Resource; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should fail at the Hot Chocolate level, not at the runtime level, because the GraphQL is malformed. Should we be writing tests that aren't really run through the runtime pipeline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronpowell This GraphQL query is in actually a valid form and will run through the runtime process. Please see screenshot as below.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. I had a look at the schema and the reason is that both the arguments to the mutation are nullable, meaning that you can call the mutation with no arguments.
Admittedly this is only a problem with the design of the current schema and pipeline, so we'll review with #399