-
Notifications
You must be signed in to change notification settings - Fork 625
Add OrderDirection support #6307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...t/src/androidTest/kotlin/com/google/firebase/dataconnect/OrderDirectionIntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.dataconnect | ||
|
||
import com.google.firebase.dataconnect.testutil.DataConnectIntegrationTestBase | ||
import com.google.firebase.dataconnect.testutil.sortedParallelTo | ||
import com.google.firebase.dataconnect.testutil.tag | ||
import io.kotest.common.DelicateKotest | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.distinct | ||
import io.kotest.property.arbitrary.int | ||
import io.kotest.property.arbitrary.next | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.serializer | ||
import org.junit.Test | ||
|
||
class OrderDirectionIntegrationTest : DataConnectIntegrationTestBase() { | ||
|
||
private val dataConnect: FirebaseDataConnect by lazy { | ||
val connectorConfig = testConnectorConfig.copy(connector = "alltypes") | ||
dataConnectFactory.newInstance(connectorConfig) | ||
} | ||
|
||
@OptIn(DelicateKotest::class) private val uniqueInts = Arb.int().distinct() | ||
|
||
@Test | ||
fun orderDirectionQueryVariableOmittedShouldUseAscendingOrder() = runTest { | ||
val tag = Arb.tag().next(rs) | ||
val values = List(5) { uniqueInts.next(rs) } | ||
val insertedIds = insertRow(tag, values) | ||
|
||
val queryIds = getRowIds(tag) | ||
|
||
queryIds shouldContainExactlyInAnyOrder insertedIds | ||
} | ||
|
||
@Test | ||
fun orderDirectionQueryVariableAscendingOrder() = runTest { | ||
val tag = Arb.tag().next(rs) | ||
val values = List(5) { uniqueInts.next(rs) } | ||
val insertedIds = insertRow(tag, values) | ||
|
||
val queryIds = getRowIds(tag, orderDirection = "ASC") | ||
|
||
val insertedIdsSorted = insertedIds.sortedParallelTo(values) | ||
queryIds shouldContainExactly insertedIdsSorted | ||
} | ||
|
||
@Test | ||
fun orderDirectionQueryVariableDescendingOrder() = runTest { | ||
val tag = Arb.tag().next(rs) | ||
val values = List(5) { uniqueInts.next(rs) } | ||
val insertedIds = insertRow(tag, values) | ||
|
||
val queryIds = getRowIds(tag, orderDirection = "DESC") | ||
|
||
val insertedIdsSorted = insertedIds.sortedParallelTo(values).reversed() | ||
queryIds shouldContainExactly insertedIdsSorted | ||
} | ||
|
||
private suspend fun insertRow(tag: String, values: List<Int>): List<String> { | ||
require(values.size == 5) { "values.size must be 5, but got ${values.size}" } | ||
return insertRow(tag, values[0], values[1], values[2], values[3], values[4]) | ||
} | ||
|
||
private suspend fun insertRow( | ||
tag: String, | ||
value1: Int, | ||
value2: Int, | ||
value3: Int, | ||
value4: Int, | ||
value5: Int | ||
): List<String> { | ||
val variables = OrderDirectionTestInsert5Variables(tag, value1, value2, value3, value4, value5) | ||
val mutationRef = | ||
dataConnect.mutation<OrderDirectionTestInsert5Data, OrderDirectionTestInsert5Variables>( | ||
operationName = "OrderDirectionTestInsert5", | ||
variables = variables, | ||
dataDeserializer = serializer(), | ||
variablesSerializer = serializer(), | ||
) | ||
val result = mutationRef.execute() | ||
return result.data.run { listOf(key1.id, key2.id, key3.id, key4.id, key5.id) } | ||
} | ||
|
||
private suspend fun getRowIds(tag: String, orderDirection: String? = null): List<String> { | ||
val optionalOrderDirection = | ||
if (orderDirection !== null) OptionalVariable.Value(orderDirection) | ||
else OptionalVariable.Undefined | ||
val variables = OrderDirectionTestGetAllByTagVariables(tag, optionalOrderDirection) | ||
val queryRef = | ||
dataConnect.query<OrderDirectionTestGetAllByTagData, OrderDirectionTestGetAllByTagVariables>( | ||
operationName = "OrderDirectionTestGetAllByTag", | ||
variables = variables, | ||
dataDeserializer = serializer(), | ||
variablesSerializer = serializer(), | ||
) | ||
val result = queryRef.execute() | ||
return result.data.items.map { it.id } | ||
} | ||
|
||
@Serializable | ||
data class OrderDirectionTestInsert5Variables( | ||
val tag: String, | ||
val value1: Int, | ||
val value2: Int, | ||
val value3: Int, | ||
val value4: Int, | ||
val value5: Int, | ||
) | ||
|
||
@Serializable data class OrderDirectionTestKey(val id: String) | ||
|
||
@Serializable | ||
data class OrderDirectionTestInsert5Data( | ||
val key1: OrderDirectionTestKey, | ||
val key2: OrderDirectionTestKey, | ||
val key3: OrderDirectionTestKey, | ||
val key4: OrderDirectionTestKey, | ||
val key5: OrderDirectionTestKey, | ||
) | ||
|
||
@Serializable | ||
data class OrderDirectionTestGetAllByTagVariables( | ||
val tag: String, | ||
val orderDirection: OptionalVariable<String>, | ||
) | ||
|
||
@Serializable | ||
data class OrderDirectionTestGetAllByTagData(val items: List<Item>) { | ||
@Serializable data class Item(val id: String) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.