14
14
* limitations under the License.
15
15
*/
16
16
17
+ @file:OptIn(ExperimentalFirebaseDataConnect ::class )
18
+
17
19
package com.google.firebase.dataconnect
18
20
19
21
import com.google.firebase.dataconnect.testutil.DataConnectIntegrationTestBase
20
22
import com.google.firebase.dataconnect.testutil.property.arbitrary.dataConnect
21
23
import com.google.firebase.dataconnect.testutil.schemas.AllTypesSchema
24
+ import com.google.firebase.dataconnect.testutil.schemas.PersonSchema
25
+ import io.kotest.assertions.withClue
22
26
import io.kotest.matchers.shouldBe
23
27
import io.kotest.property.Arb
24
28
import io.kotest.property.arbitrary.next
@@ -29,6 +33,7 @@ import org.junit.Test
29
33
30
34
class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase () {
31
35
36
+ private val personSchema by lazy { PersonSchema (dataConnectFactory) }
32
37
private val allTypesSchema by lazy { AllTypesSchema (dataConnectFactory) }
33
38
34
39
@Test
@@ -64,7 +69,6 @@ class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase() {
64
69
@Serializable
65
70
data class PrimitiveQueryDataMissingSomeKeys (val primitive : PrimitiveQueryDataValues )
66
71
67
- @OptIn(ExperimentalFirebaseDataConnect ::class )
68
72
val result =
69
73
allTypesSchema
70
74
.getPrimitive(id = id)
@@ -80,4 +84,57 @@ class UnknownKeysIntegrationTest : DataConnectIntegrationTestBase() {
80
84
stringFieldNullable = " TestNullableString"
81
85
)
82
86
}
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
+ }
83
140
}
0 commit comments