Skip to content

Commit 8c77a15

Browse files
committed
OperationExecutionErrorsIntegrationTest.kt: add test for @check in transaction: executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingFailsInTransaction
1 parent 3dc075f commit 8c77a15

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ mutation createPersonWithPartialFailure($id: String!, $name: String!) @auth(leve
100100
person2: person_insert(data: { id_expr: "uuidV4()", name: $name })
101101
}
102102

103+
mutation createPersonWithPartialFailureInTransaction($id: String!, $name: String!) @auth(level: PUBLIC) @transaction {
104+
person1: person_insert(data: { id: $id, name: $name })
105+
person2: person_insert(data: { id_expr: "uuidV4()", name: $name }) @check(expr: "false", message: "te36b3zkvn")
106+
}
107+

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,31 @@ class OperationExecutionErrorsIntegrationTest : DataConnectIntegrationTestBase()
231231
)
232232
}
233233

234+
@Test
235+
fun executeMutationFailsWithNonNullDataNonEmptyErrorsDecodingFailsInTransaction() = runTest {
236+
val id = Arb.alphanumericString().next()
237+
val name = Arb.alphanumericString().next()
238+
val mutationRef =
239+
dataConnect.mutation(
240+
operationName = "createPersonWithPartialFailureInTransaction",
241+
variables = CreatePersonWithPartialFailureVariables(id = id, name = name),
242+
dataDeserializer = serializer<IncompatibleData>(),
243+
variablesSerializer = serializer(),
244+
optionsBuilder = {},
245+
)
246+
247+
val exception = shouldThrow<DataConnectOperationException> { mutationRef.execute() }
248+
249+
exception.shouldSatisfy(
250+
expectedMessageSubstringCaseInsensitive = "operation encountered errors",
251+
expectedMessageSubstringCaseSensitive = "te36b3zkvn",
252+
expectedCause = null,
253+
expectedRawData = mapOf("person1" to null, "person2" to null),
254+
expectedData = null,
255+
errorsValidator = { it.shouldHaveAtLeastSize(1) },
256+
)
257+
}
258+
234259
@Serializable private data class IncompatibleVariables(val jwdbzka4k5: String)
235260

236261
@Serializable private data class IncompatibleData(val btzjhbfz7h: String)

0 commit comments

Comments
 (0)