-
Notifications
You must be signed in to change notification settings - Fork 24
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
add defer types to test fixture #520
Changes from all commits
90db233
61e400f
9f3cdfc
fcc3d01
48cfbc0
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 |
---|---|---|
|
@@ -168,6 +168,18 @@ private suspend fun execute( | |
) | ||
printSyncLine(actualQuery) | ||
|
||
fun failWithFixtureContext(message: String): Nothing { | ||
fail( | ||
"""${message} | ||
| fixture : '${fixture.name}' | ||
| service : '${serviceName}' | ||
| query : '${actualQuery}' | ||
| variables : '${actualVariables}' | ||
| operation : '${actualOperationName}' | ||
""".trimMargin() | ||
) | ||
} | ||
|
||
val response = synchronized(serviceCalls) { | ||
val indexOfCall = serviceCalls | ||
.indexOfFirst { | ||
|
@@ -180,17 +192,20 @@ private suspend fun execute( | |
|
||
if (indexOfCall != null) { | ||
val serviceCall = serviceCalls.removeAt(indexOfCall) | ||
serviceCall.response | ||
val response = serviceCall.response | ||
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. assigning
|
||
if (serviceCall.incrementalResponse != null && response != null) { | ||
failWithFixtureContext("Fixture cannot have both a response and an incrementalResponse.") | ||
} | ||
else if (serviceCall.incrementalResponse != null) { | ||
serviceCall.incrementalResponse.initialResponse //for now, just return initial response | ||
} else if (response != null) { | ||
response | ||
} | ||
else { | ||
failWithFixtureContext("Fixture had no response") | ||
} | ||
} else { | ||
fail( | ||
"""Unable to match service call | ||
| fixture : '${fixture.name}' | ||
| service : '${serviceName}' | ||
| query : '${actualQuery}' | ||
| variables : '${actualVariables}' | ||
| operation : '${actualOperationName}' | ||
""".trimMargin() | ||
) | ||
failWithFixtureContext("Unable to match service call") | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude | |
import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_DEFAULT | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import graphql.language.AstSorter | ||
import graphql.language.Document | ||
|
@@ -29,6 +30,8 @@ data class TestFixture( | |
val serviceCalls: List<ServiceCall>, | ||
@JsonProperty("response") | ||
val responseJsonString: String?, | ||
@JsonProperty("incrementalResponse") | ||
val incrementalResponseJsonString: IncrementalResponse?, | ||
@JsonInclude(NON_NULL) | ||
val exception: ExpectedException?, | ||
) { | ||
|
@@ -42,11 +45,14 @@ data class ServiceCall( | |
val serviceName: String, | ||
val request: Request, | ||
@JsonProperty("response") | ||
val responseJsonString: String, | ||
val responseJsonString: String?, | ||
val incrementalResponse: IncrementalResponse?, | ||
) { | ||
@get:JsonIgnore | ||
val response: JsonMap by lazy { | ||
jsonObjectMapper.readValue(responseJsonString) | ||
val response: JsonMap? by lazy { | ||
responseJsonString?.let { | ||
jsonObjectMapper.readValue(it) | ||
} | ||
} | ||
|
||
data class Request( | ||
|
@@ -88,3 +94,20 @@ data class ExpectedException( | |
) | ||
} | ||
} | ||
|
||
data class IncrementalResponse( | ||
@JsonProperty("initialResponse") | ||
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'm happy to merge this as it is. But as we discussed, it's worth trying to use the actual graphql-java types here to make deserialization easier. |
||
val initialResponseJsonString: String, | ||
@JsonProperty("delayedResponses") | ||
val delayedResponsesJsonString: String, | ||
) { | ||
@get:JsonIgnore | ||
val initialResponse: JsonMap by lazy { | ||
jsonObjectMapper.readValue(initialResponseJsonString) | ||
} | ||
|
||
@get:JsonIgnore | ||
val delayedResponses: List<JsonMap> by lazy { | ||
jsonObjectMapper.readValue(delayedResponsesJsonString, object : TypeReference<List<JsonMap>>() {}) | ||
} | ||
} |
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.
moved this into function because the fixture context is now useful for multiple fail messages