Skip to content

Commit 9d232db

Browse files
committed
UnknownKeysIntegrationTest.kt added with a test for mutation data
1 parent 8d9dcc6 commit 9d232db

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

firebase-dataconnect/emulator/dataconnect/connector/person/person_ops.gql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,10 @@ mutation createPersonWithPartialFailureInTransaction($id: String!, $name: String
105105
person2: person_insert(data: { id_expr: "uuidV4()", name: $name }) @check(expr: "false", message: "te36b3zkvn")
106106
}
107107

108+
mutation create5People @auth(level: PUBLIC) {
109+
person1: person_upsert(data: { id: "8a218894521f457a9be45a0986494058", name: "Name1" })
110+
person2: person_upsert(data: { id: "464443371f284194be4b2e78c3ef000c", name: "Name2" })
111+
person3: person_upsert(data: { id: "903d83db81754bd29860458f127ef124", name: "Name3" })
112+
person4: person_upsert(data: { id: "ef8de2a4a6de400e94d555f148b643c0", name: "Name4" })
113+
person5: person_upsert(data: { id: "8584fd7ca2b6453da18d21d4341f1804", name: "Name5" })
114+
}

firebase-dataconnect/src/androidTest/kotlin/com/google/firebase/dataconnect/UnknownKeysIntegrationTest.kt

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:OptIn(ExperimentalFirebaseDataConnect::class)
18+
1719
package com.google.firebase.dataconnect
1820

1921
import com.google.firebase.dataconnect.testutil.DataConnectIntegrationTestBase
2022
import com.google.firebase.dataconnect.testutil.property.arbitrary.dataConnect
2123
import com.google.firebase.dataconnect.testutil.schemas.AllTypesSchema
24+
import com.google.firebase.dataconnect.testutil.schemas.PersonSchema
25+
import io.kotest.assertions.withClue
2226
import io.kotest.matchers.shouldBe
2327
import io.kotest.property.Arb
2428
import io.kotest.property.arbitrary.next
@@ -29,6 +33,7 @@ import org.junit.Test
2933

3034
class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase() {
3135

36+
private val personSchema by lazy { PersonSchema(dataConnectFactory) }
3237
private val allTypesSchema by lazy { AllTypesSchema(dataConnectFactory) }
3338

3439
@Test
@@ -64,7 +69,6 @@ class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase() {
6469
@Serializable
6570
data class PrimitiveQueryDataMissingSomeKeys(val primitive: PrimitiveQueryDataValues)
6671

67-
@OptIn(ExperimentalFirebaseDataConnect::class)
6872
val result =
6973
allTypesSchema
7074
.getPrimitive(id = id)
@@ -80,4 +84,57 @@ class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase() {
8084
stringFieldNullable = "TestNullableString"
8185
)
8286
}
87+
88+
@Test
89+
fun unknownKeysInMutationResponseDataShouldBeIgnored() = runTest {
90+
@Serializable data class PersonKeyWithId(val id: String)
91+
val person1 = PersonKeyWithId(id = "8a218894521f457a9be45a0986494058")
92+
val person4 = PersonKeyWithId(id = "ef8de2a4a6de400e94d555f148b643c0")
93+
val mutationRef =
94+
personSchema.dataConnect.mutation("create5People", Unit, serializer<Unit>(), serializer())
95+
96+
// Precondition check: Verify that the response contains person1..person5 and the expected IDs.
97+
withClue("precondition check") {
98+
@Serializable
99+
data class Create5PeopleData(
100+
val person1: PersonKeyWithId,
101+
val person3: PersonKeyWithId,
102+
val person2: PersonKeyWithId,
103+
val person4: PersonKeyWithId,
104+
val person5: PersonKeyWithId,
105+
)
106+
107+
val mutationResult =
108+
mutationRef.withDataDeserializer(serializer<Create5PeopleData>()).execute()
109+
mutationResult.data shouldBe
110+
Create5PeopleData(
111+
person1 = person1,
112+
person2 = PersonKeyWithId(id = "464443371f284194be4b2e78c3ef000c"),
113+
person3 = PersonKeyWithId(id = "903d83db81754bd29860458f127ef124"),
114+
person4 = person4,
115+
person5 = PersonKeyWithId(id = "8584fd7ca2b6453da18d21d4341f1804"),
116+
)
117+
}
118+
119+
withClue("actual test") {
120+
// Create5PeopleDataWithMissingKeys is missing "person2.id", "person3", and "person5" which
121+
// will be present in the response.
122+
@Serializable data class PersonKeyWithoutId(val foo: Nothing? = null)
123+
@Serializable
124+
data class Create5PeopleDataWithMissingKeys(
125+
val person1: PersonKeyWithId,
126+
val person2: PersonKeyWithoutId,
127+
val person4: PersonKeyWithId,
128+
)
129+
130+
val mutationResult =
131+
mutationRef.withDataDeserializer(serializer<Create5PeopleDataWithMissingKeys>()).execute()
132+
mutationResult.data shouldBe
133+
Create5PeopleDataWithMissingKeys(
134+
person1 = person1,
135+
person2 = PersonKeyWithoutId(),
136+
person4 = PersonKeyWithId(id = "ef8de2a4a6de400e94d555f148b643c0"),
137+
)
138+
}
139+
}
83140
}

0 commit comments

Comments
 (0)