-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for JsonNumber * Allow JsonNumber in RecordWeighter
- Loading branch information
1 parent
d8a60f4
commit 7629cb1
Showing
11 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") | ||
id("com.apollographql.apollo") | ||
} | ||
|
||
apolloTest() | ||
|
||
dependencies { | ||
implementation(libs.apollo.api) | ||
implementation(libs.apollo.testingsupport) | ||
testImplementation(libs.kotlin.test) | ||
testImplementation(libs.apollo.testingsupport) | ||
testImplementation(libs.apollo.normalizedcache) | ||
} | ||
|
||
apollo { | ||
service("service") { | ||
packageName.set("com.example") | ||
mapScalar("Number", "kotlin.String") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
query GetNumber { | ||
number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
scalar Number | ||
|
||
type Query { | ||
number: Number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package test | ||
|
||
|
||
import com.apollographql.apollo.ApolloClient | ||
import com.apollographql.apollo.api.Adapter | ||
import com.apollographql.apollo.api.CustomScalarAdapters | ||
import com.apollographql.apollo.api.json.JsonNumber | ||
import com.apollographql.apollo.api.json.JsonReader | ||
import com.apollographql.apollo.api.json.JsonWriter | ||
import com.apollographql.apollo.cache.normalized.FetchPolicy | ||
import com.apollographql.apollo.cache.normalized.api.MemoryCacheFactory | ||
import com.apollographql.apollo.cache.normalized.fetchPolicy | ||
import com.apollographql.apollo.cache.normalized.normalizedCache | ||
import com.apollographql.apollo.testing.QueueTestNetworkTransport | ||
import com.apollographql.apollo.testing.enqueueTestResponse | ||
import com.example.GetNumberQuery | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class NumberTest { | ||
@Test | ||
fun test(): Unit = runBlocking { | ||
ApolloClient.Builder() | ||
.networkTransport(QueueTestNetworkTransport()) | ||
.normalizedCache(MemoryCacheFactory()) | ||
.addCustomScalarAdapter(com.example.type.Number.type, NumberAdapter()) | ||
.build() | ||
.use { apolloClient -> | ||
apolloClient.enqueueTestResponse(GetNumberQuery(), GetNumberQuery.Data("12345")) | ||
apolloClient.query(GetNumberQuery()).fetchPolicy(FetchPolicy.NetworkOnly).execute().apply { | ||
assertEquals("12345", data?.number) | ||
} | ||
apolloClient.query(GetNumberQuery()).fetchPolicy(FetchPolicy.CacheOnly).execute().apply { | ||
assertEquals("12345", data?.number) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class NumberAdapter: Adapter<String> { | ||
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): String { | ||
return reader.nextNumber().value | ||
} | ||
|
||
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: String) { | ||
writer.value(JsonNumber(value)) | ||
} | ||
} |