diff --git a/app/build.gradle b/app/build.gradle index 530f79359..df5a53915 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,6 +50,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'com.google.firebase:firebase-auth-ktx:21.0.1' implementation 'com.squareup.okhttp3:okhttp:4.9.0' testImplementation 'junit:junit:4.13.2' testImplementation 'org.json:json:20180813' @@ -68,6 +69,7 @@ dependencies { implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.gms:play-services-auth:20.1.0' implementation ('com.github.bumptech.glide:glide:4.13.0', { exclude group: 'com.android.support' }) @@ -111,4 +113,4 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea connectedCheck { finalizedBy jacocoTestReport -} +} \ No newline at end of file diff --git a/app/google-services.json b/app/google-services.json index f21f26f92..1e11dcf3a 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -13,6 +13,14 @@ } }, "oauth_client": [ + { + "client_id": "7687769601-4jlovmab1k6hbdq12ik9mlp7m0789ibs.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "ch.sdp.vibester", + "certificate_hash": "2d58d515333158e4e3bdd8157eb8d4d4df103cb0" + } + }, { "client_id": "7687769601-qiqrp6kt48v89ub76k9lkpefh9ls36ha.apps.googleusercontent.com", "client_type": 3 @@ -36,4 +44,4 @@ } ], "configuration_version": "1" -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt new file mode 100644 index 000000000..fab09bd17 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/SignInActivityTest.kt @@ -0,0 +1,89 @@ +package ch.sdp.vibester + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import ch.sdp.vibester.auth.FireBaseAuthenticator +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import kotlin.random.Random + + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class SignInActivityTest { + + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("ch.sdp.vibester", appContext.packageName) + } + + @get:Rule + val testRule = ActivityScenarioRule( + Register::class.java + ) + + + @Test + fun logInCorrect() { + val username = "john@test.com" + val password = "password" + onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) + onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) + onView(withId(R.id.logIn)).perform(click()) + Thread.sleep(3_000) + onView(withId(R.id.email)).check(matches(withText("john@test.com"))) + } + + @Test + fun logInIncorrect() { + val username = "johnyyy@test.com" + val password = "password" + onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) + onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) + onView(withId(R.id.logIn)).perform(click()) + Thread.sleep(3_000) + onView(withId(R.id.email)).check(matches(withText("Authentication error"))) + } + + @Test + fun createAccountIncorrect() { + val username = "john@test.com" + val password = "password" + onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) + onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) + onView(withId(R.id.createAcc)).perform(click()) + Thread.sleep(3_000) + onView(withId(R.id.email)).check(matches(withText("Authentication error"))) + } + + @Test + fun createAccountCorrect() { + val randomInt = Random.nextInt(0, 10000) + val password = "password" + val username = randomInt.toString().plus("@gg.com") + onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard()) + onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard()) + onView(withId(R.id.createAcc)).perform(click()) + Thread.sleep(3_000) + onView(withId(R.id.email)).check(matches(withText(randomInt.toString().plus("@gg.com")))) + } + + + +} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/WelcomeScreenTest.kt b/app/src/androidTest/java/ch/sdp/vibester/WelcomeScreenTest.kt index f13390b84..7facc8992 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/WelcomeScreenTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/WelcomeScreenTest.kt @@ -55,7 +55,7 @@ class WelcomeScreenTest { @Test fun checkIntentOnSettings(){ //FILLER TESTING onView(withId(R.id.welcome_settings)).perform(click()) - intended(hasComponent(GameSetupScreen::class.java.name)) + intended(hasComponent(Register::class.java.name)) } /* diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5ede2fe17..e19b26012 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,10 @@ - + + + + + diff --git a/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt b/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt index d09ecde5b..3b87fec7e 100644 --- a/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt @@ -19,6 +19,5 @@ class GreetingActivity : AppCompatActivity() { textViewActivity.text = "Hello $name!" - } } \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/Register.kt b/app/src/main/java/ch/sdp/vibester/Register.kt new file mode 100644 index 000000000..18cfc07e5 --- /dev/null +++ b/app/src/main/java/ch/sdp/vibester/Register.kt @@ -0,0 +1,124 @@ +package ch.sdp.vibester + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Button +import android.widget.EditText +import android.widget.TextView +import android.widget.Toast +import ch.sdp.vibester.auth.FireBaseAuthenticator +import com.google.android.gms.auth.api.signin.GoogleSignIn +import com.google.android.gms.auth.api.signin.GoogleSignInClient +import com.google.android.gms.auth.api.signin.GoogleSignInOptions +import com.google.android.gms.tasks.Task +import com.google.firebase.auth.AuthResult + +class Register : AppCompatActivity() { + +// private lateinit var googleSignInClient: GoogleSignInClient + + private lateinit var authenticator: FireBaseAuthenticator + + private lateinit var email: TextView + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_google_log_in) + +// @FixMe +// Commenting this for now until we find a proper way to test it, then will merge it to main + +// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) +// .requestEmail() +// .build() + +// googleSignInClient = GoogleSignIn.getClient(this, gso) + + // Initialize Firebase Auth + authenticator = FireBaseAuthenticator() + + val btCreateAcc = findViewById