Skip to content

Commit 2c74f30

Browse files
committed
stabilize API tests
1 parent e31b961 commit 2c74f30

File tree

4 files changed

+25
-50
lines changed

4 files changed

+25
-50
lines changed

aws-api/src/androidTest/java/com/amplifyframework/api/aws/GraphQLLazyCreateInstrumentationTest.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ package com.amplifyframework.api.aws
1717

1818
import android.content.Context
1919
import androidx.test.core.app.ApplicationProvider
20+
import com.amplifyframework.api.aws.extensions.fetchAllPages
2021
import com.amplifyframework.api.aws.test.R
2122
import com.amplifyframework.api.graphql.model.ModelMutation
2223
import com.amplifyframework.core.AmplifyConfiguration
2324
import com.amplifyframework.core.model.LazyModelList
2425
import com.amplifyframework.core.model.LazyModelReference
2526
import com.amplifyframework.core.model.LoadedModelList
2627
import com.amplifyframework.core.model.LoadedModelReference
27-
import com.amplifyframework.core.model.PaginationToken
2828
import com.amplifyframework.core.model.includes
2929
import com.amplifyframework.datastore.generated.model.HasManyChild
3030
import com.amplifyframework.datastore.generated.model.HasOneChild
@@ -72,15 +72,7 @@ class GraphQLLazyCreateInstrumentationTest {
7272
} ?: fail("Response child was null or not a LazyModelReference")
7373

7474
val children = responseParent.children as LazyModelList
75-
var children1HasNextPage = true
76-
var children1NextToken: PaginationToken? = null
77-
var hasManyChildren = mutableListOf<HasManyChild>()
78-
while (children1HasNextPage) {
79-
val page = children.fetchPage(children1NextToken)
80-
children1HasNextPage = page.hasNextPage
81-
children1NextToken = page.nextToken
82-
hasManyChildren.addAll(page.items)
83-
}
75+
val hasManyChildren = children.fetchAllPages()
8476
assertEquals(1, hasManyChildren.size)
8577

8678
// CLEANUP

aws-api/src/androidTest/java/com/amplifyframework/api/aws/GraphQLLazyDeleteInstrumentationTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.amplifyframework.api.aws
1717

1818
import android.content.Context
1919
import androidx.test.core.app.ApplicationProvider
20+
import com.amplifyframework.api.aws.extensions.fetchAllPages
2021
import com.amplifyframework.api.aws.test.R
2122
import com.amplifyframework.api.graphql.model.ModelMutation
2223
import com.amplifyframework.core.AmplifyConfiguration
@@ -30,6 +31,8 @@ import com.amplifyframework.datastore.generated.model.HasOneChild
3031
import com.amplifyframework.datastore.generated.model.Parent
3132
import com.amplifyframework.datastore.generated.model.ParentPath
3233
import com.amplifyframework.kotlin.core.Amplify
34+
import com.amplifyframework.logging.AndroidLoggingPlugin
35+
import com.amplifyframework.logging.LogLevel
3336
import kotlinx.coroutines.test.runTest
3437
import org.junit.Assert.assertEquals
3538
import org.junit.Assert.fail
@@ -44,6 +47,7 @@ class GraphQLLazyDeleteInstrumentationTest {
4447
fun setUp() {
4548
val context = ApplicationProvider.getApplicationContext<Context>()
4649
val config = AmplifyConfiguration.fromConfigFile(context, R.raw.amplifyconfigurationlazy)
50+
Amplify.addPlugin(AndroidLoggingPlugin(LogLevel.VERBOSE))
4751
Amplify.addPlugin(AWSApiPlugin())
4852
Amplify.configure(config, context)
4953
}
@@ -72,8 +76,8 @@ class GraphQLLazyDeleteInstrumentationTest {
7276
assertEquals(hasOneChild.id, it.id)
7377
assertEquals(hasOneChild.content, it.content)
7478
} ?: fail("Response child was null or not a LazyModelReference")
75-
(updatedParent.children as? LazyModelList)?.fetchPage()?.let {
76-
assertEquals(1, it.items.size)
79+
(updatedParent.children as? LazyModelList)?.fetchAllPages()?.let {
80+
assertEquals(1, it.size)
7781
} ?: fail("Response child was null or not a LazyModelList")
7882

7983
// CLEANUP

aws-api/src/androidTest/java/com/amplifyframework/api/aws/GraphQLLazyQueryInstrumentationTest.kt

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ package com.amplifyframework.api.aws
1717

1818
import android.content.Context
1919
import androidx.test.core.app.ApplicationProvider
20+
import com.amplifyframework.api.aws.extensions.fetchAllPages
2021
import com.amplifyframework.api.aws.test.R
2122
import com.amplifyframework.api.graphql.model.ModelQuery
2223
import com.amplifyframework.core.AmplifyConfiguration
2324
import com.amplifyframework.core.model.LazyModelList
2425
import com.amplifyframework.core.model.LazyModelReference
2526
import com.amplifyframework.core.model.LoadedModelList
2627
import com.amplifyframework.core.model.LoadedModelReference
27-
import com.amplifyframework.core.model.PaginationToken
2828
import com.amplifyframework.core.model.includes
2929
import com.amplifyframework.datastore.generated.model.HasManyChild
3030
import com.amplifyframework.datastore.generated.model.HasManyChild.HasManyChildIdentifier
@@ -162,16 +162,8 @@ class GraphQLLazyQueryInstrumentationTest {
162162
} ?: fail("Response child was null or not a LazyModelReference")
163163

164164
val children = responseParent.children as LazyModelList
165-
var children1HasNextPage = true
166-
var children1NextToken: PaginationToken? = null
167-
var children1Count = 0
168-
while (children1HasNextPage) {
169-
val page = children.fetchPage(children1NextToken)
170-
children1HasNextPage = page.hasNextPage
171-
children1NextToken = page.nextToken
172-
children1Count += page.items.size
173-
}
174-
assertEquals(1001, children1Count)
165+
val fetchedChildren = children.fetchAllPages()
166+
assertEquals(1001, fetchedChildren.size)
175167
}
176168

177169
@Test
@@ -226,16 +218,8 @@ class GraphQLLazyQueryInstrumentationTest {
226218
} ?: fail("Response child was null or not a LazyModelReference")
227219

228220
val childrenFromParent1 = parent1.children as LazyModelList
229-
var children1HasNextPage = true
230-
var children1NextToken: PaginationToken? = null
231-
var children1Count = 0
232-
while (children1HasNextPage) {
233-
val page = childrenFromParent1.fetchPage(children1NextToken)
234-
children1HasNextPage = page.hasNextPage
235-
children1NextToken = page.nextToken
236-
children1Count += page.items.size
237-
}
238-
assertEquals(1001, children1Count)
221+
val fetchedChildrenFromParent1 = childrenFromParent1.fetchAllPages()
222+
assertEquals(1001, fetchedChildrenFromParent1.size)
239223

240224
assertEquals(HAS_ONE_CHILD2_ID, parent2.parentChildId)
241225
assertEquals(PARENT2_ID, parent2.id)
@@ -245,16 +229,8 @@ class GraphQLLazyQueryInstrumentationTest {
245229
} ?: fail("Response child was null or not a LazyModelReference")
246230

247231
val childrenFromParent2 = parent2.children as LazyModelList
248-
var children2HasNextPage = true
249-
var children2NextToken: PaginationToken? = null
250-
var children2Count = 0
251-
while (children2HasNextPage) {
252-
val page = childrenFromParent2.fetchPage(children2NextToken)
253-
children2HasNextPage = page.hasNextPage
254-
children2NextToken = page.nextToken
255-
children2Count += page.items.size
256-
}
257-
assertEquals(0, children2Count)
232+
val fetchedChildrenFromParent2 = childrenFromParent2.fetchAllPages()
233+
assertEquals(0, fetchedChildrenFromParent2.size)
258234
}
259235

260236
@Test
@@ -339,7 +315,7 @@ class GraphQLLazyQueryInstrumentationTest {
339315
} ?: fail("Response child was null or not a LoadedModelReference")
340316

341317
val children = responseParent.children as LazyModelList
342-
assertEquals(0, children.fetchPage().items.size)
318+
assertEquals(0, children.fetchAllPages().size)
343319
}
344320

345321
@Test
@@ -611,24 +587,24 @@ class GraphQLLazyQueryInstrumentationTest {
611587
// Scenario 1: Start loads from lazy reference of blog
612588
val s1l1Blog = (post.blog as LazyModelReference).fetchModel()!!
613589
assertEquals(expectedBlogName, s1l1Blog.name)
614-
val s1l2Posts = (s1l1Blog.posts as LazyModelList).fetchPage().items
590+
val s1l2Posts = (s1l1Blog.posts as LazyModelList).fetchAllPages()
615591
assertEquals(1, s1l2Posts.size)
616592
assertEquals(expectedPostTitle, s1l2Posts[0].title)
617593
val s1l3Blog = (s1l2Posts[0].blog as LazyModelReference).fetchModel()!!
618594
assertEquals(expectedBlogName, s1l3Blog.name)
619-
val s1l3Comments = (s1l2Posts[0].comments as LazyModelList).fetchPage().items
595+
val s1l3Comments = (s1l2Posts[0].comments as LazyModelList).fetchAllPages()
620596
assertEquals(1, s1l3Comments.size)
621597
assertEquals(expectedCommentConent, s1l3Comments[0].content)
622598

623599
// Scenario 1: Start loads from model list of comments
624-
val s2l1Comments = (post.comments as LazyModelList).fetchPage().items
600+
val s2l1Comments = (post.comments as LazyModelList).fetchAllPages()
625601
assertEquals(1, s2l1Comments.size)
626602
assertEquals(expectedCommentConent, s2l1Comments[0].content)
627603
val s2l2Post = (s1l3Comments[0].post as LazyModelReference).fetchModel()!!
628604
assertEquals(expectedPostTitle, s2l2Post.title)
629605
val s2l3Blog = (s2l2Post.blog as LazyModelReference).fetchModel()!!
630606
assertEquals(expectedBlogName, s2l3Blog.name)
631-
val s2l3Comments = (s2l2Post.comments as LazyModelList).fetchPage().items
607+
val s2l3Comments = (s2l2Post.comments as LazyModelList).fetchAllPages()
632608
assertEquals(1, s2l3Comments.size)
633609
assertEquals(expectedCommentConent, s2l3Comments[0].content)
634610
}

aws-api/src/androidTest/java/com/amplifyframework/api/aws/GraphQLLazyUpdateInstrumentationTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.amplifyframework.api.aws
1717

1818
import android.content.Context
1919
import androidx.test.core.app.ApplicationProvider
20+
import com.amplifyframework.api.aws.extensions.fetchAllPages
2021
import com.amplifyframework.api.aws.test.R
2122
import com.amplifyframework.api.graphql.model.ModelMutation
2223
import com.amplifyframework.core.AmplifyConfiguration
@@ -31,6 +32,7 @@ import com.amplifyframework.datastore.generated.model.HasOneChild
3132
import com.amplifyframework.datastore.generated.model.Parent
3233
import com.amplifyframework.datastore.generated.model.ParentPath
3334
import com.amplifyframework.kotlin.core.Amplify
35+
import com.amplifyframework.testutils.Repeat
3436
import kotlinx.coroutines.test.runTest
3537
import org.junit.Assert.assertEquals
3638
import org.junit.Assert.assertNull
@@ -51,6 +53,7 @@ class GraphQLLazyUpdateInstrumentationTest {
5153
}
5254
}
5355

56+
@Repeat(100)
5457
@Test
5558
fun update_with_no_includes() = runTest {
5659
// GIVEN
@@ -78,8 +81,8 @@ class GraphQLLazyUpdateInstrumentationTest {
7881
assertEquals(hasOneChild2.id, it.id)
7982
assertEquals(hasOneChild2.content, it.content)
8083
} ?: fail("Response child was null or not a LazyModelReference")
81-
(updatedParent.children as? LazyModelList)?.fetchPage()?.let {
82-
assertEquals(1, it.items.size)
84+
(updatedParent.children as? LazyModelList)?.fetchAllPages()?.let {
85+
assertEquals(1, it.size)
8386
} ?: fail("Response child was null or not a LazyModelList")
8487

8588
// CLEANUP

0 commit comments

Comments
 (0)