Skip to content

Commit 25b869e

Browse files
committed
WIP on tests
1 parent b5a6491 commit 25b869e

File tree

12 files changed

+185
-7
lines changed

12 files changed

+185
-7
lines changed

build.gradle.kts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ buildscript {
2020
}
2121

2222
val targetSdkVersion by extra(28)
23-
val minSdkVersion by extra(14)
23+
val minSdkVersion by extra(16)
2424

2525

2626
tasks {
@@ -140,8 +140,15 @@ subprojects {
140140
"iosMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.4")
141141
"commonTestImplementation"(kotlin("test-common"))
142142
"commonTestImplementation"(kotlin("test-annotations-common"))
143+
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.4")
144+
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.4")
143145
"jsTestImplementation"(kotlin("test-js"))
144-
"androidTestImplementation"(kotlin("test-junit"))
146+
"androidAndroidTestImplementation"(kotlin("test-junit"))
147+
"androidAndroidTestImplementation"("junit:junit:4.12")
148+
"androidAndroidTestImplementation"("androidx.test:core:1.2.0")
149+
"androidAndroidTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4")
150+
"androidAndroidTestImplementation"("androidx.test.ext:junit:1.1.1")
151+
"androidAndroidTestImplementation"("androidx.test:runner:1.1.0")
145152
}
146153
}
147154

firebase-app/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ android {
2626
manifest.srcFile("src/androidMain/AndroidManifest.xml")
2727
}
2828
}
29+
testOptions {
30+
unitTests.apply {
31+
isIncludeAndroidResources = true
32+
}
33+
}
34+
packagingOptions {
35+
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
36+
}
2937
}
3038

3139
kotlin {

firebase-auth/build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ android {
1111
defaultConfig {
1212
minSdkVersion(property("minSdkVersion") as Int)
1313
targetSdkVersion(property("targetSdkVersion") as Int)
14+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1415
}
1516
sourceSets {
1617
getByName("main") {
1718
manifest.srcFile("src/androidMain/AndroidManifest.xml")
1819
}
20+
getByName("androidTest").java.srcDir(file("src/androidAndroidTest/kotlin"))
21+
}
22+
testOptions {
23+
unitTests.apply {
24+
isIncludeAndroidResources = true
25+
}
26+
}
27+
packagingOptions {
28+
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
1929
}
2030
}
2131

@@ -26,6 +36,8 @@ kotlin {
2636
moduleKind = "commonjs"
2737
}
2838
}
39+
nodejs()
40+
browser()
2941
}
3042
android {
3143
publishLibraryVariants("release", "debug")
@@ -53,8 +65,7 @@ kotlin {
5365
api("com.google.firebase:firebase-auth:19.1.0")
5466
}
5567
}
56-
// val iosMain by creating
57-
68+
5869
configure(listOf(iosArm64, iosX64)) {
5970
compilations.getByName("main") {
6071
source(sourceSets.get("iosMain"))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:JvmName("tests")
6+
package dev.gitlive.firebase.auth
7+
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import androidx.test.filters.SmallTest
10+
import androidx.test.platform.app.InstrumentationRegistry
11+
import dev.gitlive.firebase.Firebase
12+
import dev.gitlive.firebase.FirebaseOptions
13+
import dev.gitlive.firebase.initialize
14+
import kotlinx.coroutines.runBlocking
15+
import org.junit.Before
16+
import org.junit.runner.RunWith
17+
import kotlin.test.assertEquals
18+
19+
val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
20+
21+
@RunWith(AndroidJUnit4::class)
22+
@SmallTest
23+
class FirebaseAuthTest {
24+
25+
@Before
26+
fun initializeFirebase() {
27+
Firebase.initialize(context, FirebaseOptions(
28+
applicationId ="fir-kotlin-sdk",
29+
apiKey = "AIzaSyDft_DSsVA7KPJj_GItUvMLjk6wbOdGBOs",
30+
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
31+
storageBucket = "fir-kotlin-sdk.appspot.com",
32+
projectId ="fir-kotlin-sdk"
33+
))
34+
35+
}
36+
37+
@org.junit.Test
38+
fun testSignInWithUsernameAndPassword() = runBlocking {
39+
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
40+
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
41+
}
42+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.gitlive.firebase.auth
6+
7+
import dev.gitlive.firebase.Firebase
8+
import dev.gitlive.firebase.FirebaseOptions
9+
import dev.gitlive.firebase.initialize
10+
import kotlinx.coroutines.runBlocking
11+
import kotlin.test.BeforeTest
12+
import kotlin.test.Test
13+
import kotlin.test.assertEquals
14+
15+
class FirebaseAuthTest {
16+
17+
@BeforeTest
18+
fun initializeFirebase() {
19+
Firebase.initialize(null, FirebaseOptions(
20+
applicationId ="fir-kotlin-sdk",
21+
apiKey = "AIzaSyDft_DSsVA7KPJj_GItUvMLjk6wbOdGBOs",
22+
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
23+
storageBucket = "fir-kotlin-sdk.appspot.com",
24+
projectId ="fir-kotlin-sdk"
25+
))
26+
27+
}
28+
29+
@Test
30+
fun testSignInWithUsernameAndPassword() = runBlocking {
31+
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
32+
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.gitlive.firebase.auth
6+
7+
import dev.gitlive.firebase.Firebase
8+
import dev.gitlive.firebase.FirebaseOptions
9+
import dev.gitlive.firebase.initialize
10+
import kotlinx.coroutines.GlobalScope
11+
import kotlinx.coroutines.promise
12+
import kotlin.test.BeforeTest
13+
import kotlin.test.Test
14+
import kotlin.test.assertEquals
15+
16+
//expect val context: Any
17+
18+
class FirebaseAuthTest {
19+
20+
@BeforeTest
21+
fun initializeFirebase() {
22+
Firebase.initialize(null, FirebaseOptions(
23+
applicationId ="fir-kotlin-sdk",
24+
apiKey = "AIzaSyDft_DSsVA7KPJj_GItUvMLjk6wbOdGBOs",
25+
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
26+
storageBucket = "fir-kotlin-sdk.appspot.com",
27+
projectId ="fir-kotlin-sdk"
28+
))
29+
30+
}
31+
32+
@Test
33+
fun testSignInWithUsernameAndPassword() = GlobalScope.promise {
34+
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
35+
assertEquals("mn8kgIFnxLO7il8GpTa5g0ObP6I2", result.user!!.uid)
36+
}
37+
}

firebase-common/build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ android {
2222
manifest.srcFile("src/androidMain/AndroidManifest.xml")
2323
}
2424
}
25+
testOptions {
26+
unitTests.apply {
27+
isIncludeAndroidResources = true
28+
}
29+
}
30+
packagingOptions {
31+
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
32+
}
2533
}
2634

2735
kotlin {
@@ -62,7 +70,7 @@ kotlin {
6270
}
6371
val jsMain by getting {
6472
dependencies {
65-
// implementation(npm("firebase", "6.2.3"))
73+
api(npm("firebase", "7.14.0"))
6674
api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.20.0")
6775
}
6876
}

firebase-database/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ android {
1717
manifest.srcFile("src/androidMain/AndroidManifest.xml")
1818
}
1919
}
20+
testOptions {
21+
unitTests.apply {
22+
isIncludeAndroidResources = true
23+
}
24+
}
25+
packagingOptions {
26+
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
27+
}
2028
}
2129

2230
kotlin {

firebase-firestore/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ android {
1717
manifest.srcFile("src/androidMain/AndroidManifest.xml")
1818
}
1919
}
20+
testOptions {
21+
unitTests.apply {
22+
isIncludeAndroidResources = true
23+
}
24+
}
25+
packagingOptions {
26+
pickFirst("META-INF/kotlinx-serialization-runtime.kotlin_module")
27+
}
2028
}
2129

2230
kotlin {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.gitlive.firebase.firestore

0 commit comments

Comments
 (0)