Skip to content

Commit e41534f

Browse files
authored
Merge branch 'master' into add-database-reference-testing
2 parents 4fa08d2 + f85e46a commit e41534f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

firebase-database/src/commonTest/kotlin/dev.gitlive.firebase.database/database.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ expect fun runTest(test: suspend () -> Unit)
1515

1616
class database {
1717

18+
@Serializable
19+
data class FirebaseDatabaseChildTest(val prop1: String? = null, val time: Double = 0.0)
20+
1821
@BeforeTest
1922
fun initializeFirebase() {
2023
Firebase
@@ -31,7 +34,7 @@ class database {
3134
gcmSenderId = "846484016111"
3235
)
3336
)
34-
Firebase.database.useEmulator(emulatorHost, 8080)
37+
Firebase.database.useEmulator(emulatorHost, 9000)
3538
}
3639
}
3740

@@ -49,4 +52,29 @@ class database {
4952

5053
assertEquals(testValue, testReferenceValue)
5154
}
55+
56+
@Test
57+
fun testChildCount() = runTest {
58+
setupRealtimeData()
59+
val dataSnapshot = Firebase.database
60+
.reference("FirebaseRealtimeDatabaseTest")
61+
.valueEvents
62+
.first()
63+
64+
val firebaseDatabaseChildCount = dataSnapshot.children.count()
65+
assertEquals(3, firebaseDatabaseChildCount)
66+
}
67+
68+
private suspend fun setupRealtimeData() {
69+
val firebaseDatabaseTestReference = Firebase.database
70+
.reference("FirebaseRealtimeDatabaseTest")
71+
72+
val firebaseDatabaseChildTest1 = FirebaseDatabaseChildTest("aaa")
73+
val firebaseDatabaseChildTest2 = FirebaseDatabaseChildTest("bbb")
74+
val firebaseDatabaseChildTest3 = FirebaseDatabaseChildTest("ccc")
75+
76+
firebaseDatabaseTestReference.child("1").setValue(firebaseDatabaseChildTest1)
77+
firebaseDatabaseTestReference.child("2").setValue(firebaseDatabaseChildTest2)
78+
firebaseDatabaseTestReference.child("3").setValue(firebaseDatabaseChildTest3)
79+
}
5280
}

test/database.rules.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
".read": true,
4+
".write": true
5+
}
6+
}

test/firebase.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
"firestore": {
33
"rules": "firestore.rules"
44
},
5+
"database": {
6+
"rules": "database.rules.json"
7+
},
58
"emulators": {
69
"auth": {
710
"port": 9099
811
},
912
"firestore": {
1013
"port": 8080
14+
},
15+
"database": {
16+
"port": 9000
1117
}
1218
}
1319
}

0 commit comments

Comments
 (0)