Skip to content

Commit 034566e

Browse files
authored
dataconnect: Add OrderDirection codegen integration test (#6308)
1 parent bf1f1fe commit 034566e

File tree

6 files changed

+131
-37
lines changed

6 files changed

+131
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.dataconnect.connectors.demo
18+
19+
import com.google.firebase.dataconnect.connectors.demo.testutil.DemoConnectorIntegrationTestBase
20+
import com.google.firebase.dataconnect.testutil.sortedParallelTo
21+
import com.google.firebase.dataconnect.testutil.tag
22+
import io.kotest.common.DelicateKotest
23+
import io.kotest.matchers.collections.shouldContainExactly
24+
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
25+
import io.kotest.property.Arb
26+
import io.kotest.property.arbitrary.distinct
27+
import io.kotest.property.arbitrary.int
28+
import io.kotest.property.arbitrary.next
29+
import java.util.UUID
30+
import kotlinx.coroutines.test.runTest
31+
import org.junit.Test
32+
33+
class OrderDirectionIntegrationTest : DemoConnectorIntegrationTestBase() {
34+
35+
@OptIn(DelicateKotest::class) private val uniqueInts = Arb.int().distinct()
36+
37+
@Test
38+
fun orderDirectionQueryVariableOmittedShouldUseUnspecifiedOrder() = runTest {
39+
val tag = Arb.tag().next(rs)
40+
val values = List(5) { uniqueInts.next(rs) }
41+
val insertedIds = insertRow(tag, values)
42+
43+
val queryResult = connector.orderDirectionTestGetAllByTag.execute(tag) {}
44+
45+
val queryIds = queryResult.data.items.map { it.id }
46+
queryIds shouldContainExactlyInAnyOrder insertedIds
47+
}
48+
49+
@Test
50+
fun orderDirectionQueryVariableAscendingOrder() = runTest {
51+
val tag = Arb.tag().next(rs)
52+
val values = List(5) { uniqueInts.next(rs) }
53+
val insertedIds = insertRow(tag, values)
54+
55+
val queryResult =
56+
connector.orderDirectionTestGetAllByTag.execute(tag) { orderDirection = OrderDirection.ASC }
57+
58+
val queryIds = queryResult.data.items.map { it.id }
59+
val insertedIdsSorted = insertedIds.sortedParallelTo(values)
60+
queryIds shouldContainExactly insertedIdsSorted
61+
}
62+
63+
@Test
64+
fun orderDirectionQueryVariableDescendingOrder() = runTest {
65+
val tag = Arb.tag().next(rs)
66+
val values = List(5) { uniqueInts.next(rs) }
67+
val insertedIds = insertRow(tag, values)
68+
69+
val queryResult =
70+
connector.orderDirectionTestGetAllByTag.execute(tag) { orderDirection = OrderDirection.DESC }
71+
72+
val queryIds = queryResult.data.items.map { it.id }
73+
val insertedIdsSorted = insertedIds.sortedParallelTo(values).reversed()
74+
queryIds shouldContainExactly insertedIdsSorted
75+
}
76+
77+
private suspend fun insertRow(tag: String, values: List<Int>): List<UUID> {
78+
require(values.size == 5) { "values.size must be 5, but got ${values.size}" }
79+
return insertRow(tag, values[0], values[1], values[2], values[3], values[4])
80+
}
81+
82+
private suspend fun insertRow(
83+
tag: String,
84+
value1: Int,
85+
value2: Int,
86+
value3: Int,
87+
value4: Int,
88+
value5: Int,
89+
): List<UUID> {
90+
val result =
91+
connector.orderDirectionTestInsert5.execute(tag, value1, value2, value3, value4, value5)
92+
return result.data.run { listOf(key1.id, key2.id, key3.id, key4.id, key5.id) }
93+
}
94+
}

firebase-dataconnect/emulator/dataconnect/connector/alltypes/alltypes_ops.gql

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -190,33 +190,3 @@ query getFarm($id: String!) @auth(level: PUBLIC) {
190190
}
191191
}
192192
}
193-
194-
###############################################################################
195-
# Operations for table: OrderDirectionTest
196-
###############################################################################
197-
198-
mutation OrderDirectionTestInsert5(
199-
$tag: String!,
200-
$value1: Int!,
201-
$value2: Int!,
202-
$value3: Int!,
203-
$value4: Int!,
204-
$value5: Int!,
205-
) @auth(level: PUBLIC) {
206-
key1: orderDirectionTest_insert(data: { tag: $tag, value: $value1 })
207-
key2: orderDirectionTest_insert(data: { tag: $tag, value: $value2 })
208-
key3: orderDirectionTest_insert(data: { tag: $tag, value: $value3 })
209-
key4: orderDirectionTest_insert(data: { tag: $tag, value: $value4 })
210-
key5: orderDirectionTest_insert(data: { tag: $tag, value: $value5 })
211-
}
212-
213-
query OrderDirectionTestGetAllByTag(
214-
$tag: String!,
215-
$orderDirection: OrderDirection,
216-
) @auth(level: PUBLIC) {
217-
items: orderDirectionTests(
218-
limit: 10,
219-
orderBy: { value: $orderDirection },
220-
where: { tag: { eq: $tag } },
221-
) { id }
222-
}

firebase-dataconnect/emulator/dataconnect/connector/demo/demo_ops.gql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,3 +1413,33 @@ query AnyScalarNonNullableListOfNonNullableGetAllByTagAndValue($tag: String, $va
14131413
where: { value: { includesAll: $value }, tag: { eq: $tag } },
14141414
) { id }
14151415
}
1416+
1417+
###############################################################################
1418+
# Operations for table: OrderDirectionTest
1419+
###############################################################################
1420+
1421+
mutation OrderDirectionTestInsert5(
1422+
$tag: String!,
1423+
$value1: Int!,
1424+
$value2: Int!,
1425+
$value3: Int!,
1426+
$value4: Int!,
1427+
$value5: Int!,
1428+
) @auth(level: PUBLIC) {
1429+
key1: orderDirectionTest_insert(data: { tag: $tag, value: $value1 })
1430+
key2: orderDirectionTest_insert(data: { tag: $tag, value: $value2 })
1431+
key3: orderDirectionTest_insert(data: { tag: $tag, value: $value3 })
1432+
key4: orderDirectionTest_insert(data: { tag: $tag, value: $value4 })
1433+
key5: orderDirectionTest_insert(data: { tag: $tag, value: $value5 })
1434+
}
1435+
1436+
query OrderDirectionTestGetAllByTag(
1437+
$tag: String!,
1438+
$orderDirection: OrderDirection,
1439+
) @auth(level: PUBLIC) {
1440+
items: orderDirectionTests(
1441+
limit: 10,
1442+
orderBy: { value: $orderDirection },
1443+
where: { tag: { eq: $tag } },
1444+
) { id }
1445+
}

firebase-dataconnect/emulator/dataconnect/schema/alltypes_schema.gql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,3 @@ type Farmer @table {
6262
name: String!
6363
parent: Farmer
6464
}
65-
66-
type OrderDirectionTest @table @index(fields: ["tag"]) {
67-
value: Int
68-
tag: String
69-
}

firebase-dataconnect/emulator/dataconnect/schema/demo_schema.gql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,8 @@ type AnyScalarNonNullableListOfNonNullable @table @index(fields: ["tag"]) {
337337
tag: String
338338
position: Int
339339
}
340+
341+
type OrderDirectionTest @table @index(fields: ["tag"]) {
342+
value: Int
343+
tag: String
344+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ import org.junit.Test
3434
class OrderDirectionIntegrationTest : DataConnectIntegrationTestBase() {
3535

3636
private val dataConnect: FirebaseDataConnect by lazy {
37-
val connectorConfig = testConnectorConfig.copy(connector = "alltypes")
37+
val connectorConfig = testConnectorConfig.copy(connector = "demo")
3838
dataConnectFactory.newInstance(connectorConfig)
3939
}
4040

4141
@OptIn(DelicateKotest::class) private val uniqueInts = Arb.int().distinct()
4242

4343
@Test
44-
fun orderDirectionQueryVariableOmittedShouldUseAscendingOrder() = runTest {
44+
fun orderDirectionQueryVariableOmittedShouldUseUnspecifiedOrder() = runTest {
4545
val tag = Arb.tag().next(rs)
4646
val values = List(5) { uniqueInts.next(rs) }
4747
val insertedIds = insertRow(tag, values)

0 commit comments

Comments
 (0)