From 34b8cd87e9c8ae0c6406a1edc12dc0a38f90a357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Coleksii-minaiev=E2=80=9D?= <“oleksii.minaiev@postindustria.com”> Date: Wed, 18 Dec 2024 15:33:23 +0200 Subject: [PATCH] FR-18978: Updated FronteggAppTest --- .../com/frontegg/android/FronteggAppTest.kt | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/android/src/test/java/com/frontegg/android/FronteggAppTest.kt b/android/src/test/java/com/frontegg/android/FronteggAppTest.kt index e68a2ba..0238175 100644 --- a/android/src/test/java/com/frontegg/android/FronteggAppTest.kt +++ b/android/src/test/java/com/frontegg/android/FronteggAppTest.kt @@ -1,9 +1,25 @@ package com.frontegg.android +import android.app.Activity +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 import com.frontegg.android.exceptions.FronteggException +import com.frontegg.android.regions.RegionConfig +import com.frontegg.android.testUtils.FakeAndroidKeyStoreProvider +import org.junit.Before import org.junit.Test +import org.junit.runner.RunWith +@RunWith(AndroidJUnit4::class) class FronteggAppTest { + private val fronteggDomain = "frontegg.test.com" + private val fronteggClientId = "Test Client Id" + private val applicationId = "Application Id" + + @Before + fun setUp() { + FakeAndroidKeyStoreProvider.setup() + } @Test fun `getInstance should throw FronteggException_FRONTEGG_APP_MUST_BE_INITIALIZED`() { @@ -13,4 +29,159 @@ class FronteggAppTest { assert(e.message == FronteggException.FRONTEGG_APP_MUST_BE_INITIALIZED) } } + + @Test + fun `init should setUp instance field`() { + FronteggApp.init( + fronteggDomain = fronteggDomain, + clientId = fronteggClientId, + context = ApplicationProvider.getApplicationContext(), + ) + + try { + FronteggApp.getInstance() + assert(true) + } catch (e: FronteggException) { + assert(false) + } + } + + @Test + fun `init should initialize all FronteggApp fields`() { + FronteggApp.init( + fronteggDomain = fronteggDomain, + clientId = fronteggClientId, + context = ApplicationProvider.getApplicationContext(), + applicationId = applicationId, + useAssetsLinks = true, + useChromeCustomTabs = true, + mainActivityClass = Activity::class.java + ) + + val fronteggApp = FronteggApp.getInstance() + + assert(fronteggApp.baseUrl == "https://$fronteggDomain") + assert(fronteggApp.clientId == fronteggClientId) + assert(fronteggApp.applicationId == applicationId) + assert(fronteggApp.useAssetsLinks) + assert(fronteggApp.useChromeCustomTabs) + assert(fronteggApp.mainActivityClass == Activity::class.java) + } + + @Test + fun `initWithRegions should initialize regions`() { + FronteggApp.initWithRegions( + regions = listOf( + RegionConfig( + key = "key 1", + baseUrl = "frontegg.test.com 1", + clientId = "Test Client Id 1", + applicationId = "Application Id 1", + ), + RegionConfig( + key = "key 2", + baseUrl = "frontegg.test.com 2", + clientId = "Test Client Id 2", + applicationId = "Application Id 2", + ) + ), + context = ApplicationProvider.getApplicationContext(), + useAssetsLinks = true, + useChromeCustomTabs = true, + mainActivityClass = Activity::class.java + ) + + val fronteggApp = FronteggApp.getInstance() + assert(fronteggApp.regions.count() == 2) + assert(fronteggApp.regions.first().key == "key 1") + assert(fronteggApp.regions.last().key == "key 2") + assert(fronteggApp.baseUrl == "") + } + + @Test + fun `initWithRegion should initialize baseUrl, clientId, and applicationId`() { + FronteggApp.initWithRegions( + regions = listOf( + RegionConfig( + key = "key 1", + baseUrl = "frontegg.test.com 1", + clientId = "Test Client Id 1", + applicationId = "Application Id 1", + ), + RegionConfig( + key = "key 2", + baseUrl = "frontegg.test.com 2", + clientId = "Test Client Id 2", + applicationId = "Application Id 2", + ) + ), + context = ApplicationProvider.getApplicationContext(), + useAssetsLinks = true, + useChromeCustomTabs = true, + mainActivityClass = Activity::class.java + ) + + val fronteggApp = FronteggApp.getInstance() + + fronteggApp.initWithRegion("key 1") + assert(fronteggApp.baseUrl == "https://frontegg.test.com 1") + assert(fronteggApp.clientId == "Test Client Id 1") + assert(fronteggApp.applicationId == "Application Id 1") + + fronteggApp.initWithRegion("key 2") + assert(fronteggApp.baseUrl == "https://frontegg.test.com 2") + assert(fronteggApp.clientId == "Test Client Id 2") + assert(fronteggApp.applicationId == "Application Id 2") + } + + @Test + fun `initWithRegion should throw RuntimeException if regions is empty`() { + FronteggApp.initWithRegions( + regions = listOf(), + context = ApplicationProvider.getApplicationContext(), + useAssetsLinks = true, + useChromeCustomTabs = true, + mainActivityClass = Activity::class.java + ) + + try { + val fronteggApp = FronteggApp.getInstance() + fronteggApp.initWithRegion("key 1") + assert(false) + } catch (e: RuntimeException) { + assert(true) + } + } + + @Test + fun `initWithRegion should throw RuntimeException if regionKey is not exists in regions`() { + FronteggApp.initWithRegions( + regions = listOf( + RegionConfig( + key = "key 1", + baseUrl = "frontegg.test.com 1", + clientId = "Test Client Id 1", + applicationId = "Application Id 1", + ), + RegionConfig( + key = "key 2", + baseUrl = "frontegg.test.com 2", + clientId = "Test Client Id 2", + applicationId = "Application Id 2", + ) + ), + context = ApplicationProvider.getApplicationContext(), + useAssetsLinks = true, + useChromeCustomTabs = true, + mainActivityClass = Activity::class.java + ) + + try { + val fronteggApp = FronteggApp.getInstance() + fronteggApp.initWithRegion("key 3") + assert(false) + } catch (e: RuntimeException) { + assert(true) + } + } } \ No newline at end of file