1717package com.google.firebase.dataconnect
1818
1919import com.google.firebase.dataconnect.testutil.DataConnectIntegrationTestBase
20+ import com.google.firebase.dataconnect.testutil.property.arbitrary.distinctPair
2021import com.google.firebase.dataconnect.testutil.schemas.PersonSchema
2122import com.google.firebase.dataconnect.testutil.schemas.PersonSchema.CreatePersonMutation
2223import com.google.firebase.dataconnect.testutil.schemas.PersonSchema.GetPersonQuery
@@ -157,12 +158,12 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
157158
158159 @Test
159160 fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingSucceeds () = runTest {
160- val id = Arb .alphanumericString().next()
161+ val (id1, id2) = Arb .alphanumericString().distinctPair ().next()
161162 val name = Arb .alphanumericString().next()
162163 val mutationRef =
163164 dataConnect.mutation(
164165 operationName = " createPersonWithPartialFailure" ,
165- variables = CreatePersonWithPartialFailureVariables (id = id , name = name),
166+ variables = CreatePersonWithPartialFailureVariables (id1 = id1, id2 = id2 , name = name),
166167 dataDeserializer = serializer<CreatePersonWithPartialFailureData >(),
167168 variablesSerializer = serializer(),
168169 optionsBuilder = {},
@@ -172,10 +173,10 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
172173
173174 exception.shouldSatisfy(
174175 expectedMessageSubstringCaseInsensitive = " operation encountered errors" ,
175- expectedMessageSubstringCaseSensitive = " ecxpjy4qfy " ,
176+ expectedMessageSubstringCaseSensitive = null ,
176177 expectedCause = null ,
177- expectedRawData = mapOf (" person1" to mapOf (" id" to id ), " person2" to null ),
178- expectedData = CreatePersonWithPartialFailureData (id ),
178+ expectedRawData = mapOf (" person1" to mapOf (" id" to id1 ), " person2" to mapOf ( " id " to id2) ),
179+ expectedData = CreatePersonWithPartialFailureData (id1, id2 ),
179180 errorsValidator = { it.shouldHaveAtLeastSize(1 ) },
180181 )
181182 }
@@ -208,12 +209,12 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
208209
209210 @Test
210211 fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingFails () = runTest {
211- val id = Arb .alphanumericString().next()
212+ val (id1, id2) = Arb .alphanumericString().distinctPair ().next()
212213 val name = Arb .alphanumericString().next()
213214 val mutationRef =
214215 dataConnect.mutation(
215216 operationName = " createPersonWithPartialFailure" ,
216- variables = CreatePersonWithPartialFailureVariables (id = id , name = name),
217+ variables = CreatePersonWithPartialFailureVariables (id1 = id1, id2 = id2 , name = name),
217218 dataDeserializer = serializer<IncompatibleData >(),
218219 variablesSerializer = serializer(),
219220 optionsBuilder = {},
@@ -223,22 +224,47 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
223224
224225 exception.shouldSatisfy(
225226 expectedMessageSubstringCaseInsensitive = " operation encountered errors" ,
226- expectedMessageSubstringCaseSensitive = " ecxpjy4qfy " ,
227+ expectedMessageSubstringCaseSensitive = null ,
227228 expectedCause = null ,
228- expectedRawData = mapOf (" person1" to mapOf (" id" to id ), " person2" to null ),
229+ expectedRawData = mapOf (" person1" to mapOf (" id" to id1 ), " person2" to mapOf ( " id " to id2) ),
229230 expectedData = null ,
230231 errorsValidator = { it.shouldHaveAtLeastSize(1 ) },
231232 )
232233 }
233234
235+ @Test
236+ fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingSucceedsInTransaction () = runTest {
237+ val id = Arb .alphanumericString().next()
238+ val name = Arb .alphanumericString().next()
239+ val mutationRef =
240+ dataConnect.mutation(
241+ operationName = " createPersonWithPartialFailureInTransaction" ,
242+ variables = CreatePersonWithPartialFailureVariablesInTransaction (id = id, name = name),
243+ dataDeserializer = serializer<CreatePersonWithPartialFailureDataNullable >(),
244+ variablesSerializer = serializer(),
245+ optionsBuilder = {},
246+ )
247+
248+ val exception = shouldThrow<DataConnectOperationException > { mutationRef.execute() }
249+
250+ exception.shouldSatisfy(
251+ expectedMessageSubstringCaseInsensitive = " operation encountered errors" ,
252+ expectedMessageSubstringCaseSensitive = null ,
253+ expectedCause = null ,
254+ expectedRawData = mapOf (" person1" to null , " person2" to null ),
255+ expectedData = CreatePersonWithPartialFailureDataNullable (null , null ),
256+ errorsValidator = { it.shouldHaveAtLeastSize(1 ) },
257+ )
258+ }
259+
234260 @Test
235261 fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingFailsInTransaction () = runTest {
236262 val id = Arb .alphanumericString().next()
237263 val name = Arb .alphanumericString().next()
238264 val mutationRef =
239265 dataConnect.mutation(
240266 operationName = " createPersonWithPartialFailureInTransaction" ,
241- variables = CreatePersonWithPartialFailureVariables (id = id, name = name),
267+ variables = CreatePersonWithPartialFailureVariablesInTransaction (id = id, name = name),
242268 dataDeserializer = serializer<IncompatibleData >(),
243269 variablesSerializer = serializer(),
244270 optionsBuilder = {},
@@ -273,15 +299,28 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
273299 }
274300
275301 @Serializable
276- private data class CreatePersonWithPartialFailureVariables (val id : String , val name : String )
302+ private data class CreatePersonWithPartialFailureVariables (
303+ val id1 : String ,
304+ val id2 : String ,
305+ val name : String ,
306+ )
307+
308+ @Serializable
309+ private data class CreatePersonWithPartialFailureVariablesInTransaction (
310+ val id : String ,
311+ val name : String ,
312+ )
277313
278314 @Serializable
279- private data class CreatePersonWithPartialFailureData (
280- val person1 : Person ,
281- val person2 : Nothing?
282- ) {
283- constructor (person1Id: String ) : this (Person (person1Id), null )
315+ private data class CreatePersonWithPartialFailureData (val person1 : Person , val person2 : Person ) {
316+ constructor (person1Id: String , person2Id: String ) : this (Person (person1Id), Person (person2Id))
284317
285- @Serializable private data class Person (val id : String )
318+ @Serializable data class Person (val id : String )
286319 }
320+
321+ @Serializable
322+ private data class CreatePersonWithPartialFailureDataNullable (
323+ val person1 : CreatePersonWithPartialFailureData .Person ? ,
324+ val person2 : CreatePersonWithPartialFailureData .Person ? ,
325+ )
287326}
0 commit comments