Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests are wip] V4 to v5 upgrade will migrate app ID #2244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ object PreferencePlayerPurchasesKeys {
object PreferenceOneSignalKeys {
// Legacy

/**
* (String) The legacy app ID from SDKs prior to 5.
*/
const val PREFS_LEGACY_APP_ID = "GT_APP_ID"

/**
* (String) The legacy player ID from SDKs prior to 5.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,27 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
sessionModel = services.getService<SessionModelStore>().model
operationRepo = services.getService<IOperationRepo>()

var forceCreateUser = false

// initWithContext is called by our internal services/receivers/activites but they do not provide
// an appId (they don't know it). If the app has never called the external initWithContext
// prior to our services/receivers/activities we will blow up, as no appId has been established.
if (appId == null && !configModel!!.hasProperty(ConfigModel::appId.name)) {
Logging.warn("initWithContext called without providing appId, and no appId has been established!")
return false
val legacyAppId =
preferencesService!!.getString(
PreferenceStores.ONESIGNAL,
PreferenceOneSignalKeys.PREFS_LEGACY_APP_ID,
)
if (legacyAppId == null) {
Logging.warn("initWithContext called without providing appId, and no appId has been established!")
return false
} else {
Logging.debug("initWithContext: using cached legacy appId $legacyAppId")
forceCreateUser = true
configModel!!.appId = legacyAppId
}
}

var forceCreateUser = false
// if the app id was specified as input, update the config model with it
if (appId != null) {
if (!configModel!!.hasProperty(ConfigModel::appId.name) || configModel!!.appId != appId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.onesignal.internal

import android.content.Context
import androidx.test.core.app.ApplicationProvider
// import com.onesignal.notifications.NotificationsModule
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import io.kotest.assertions.throwables.shouldThrowUnit
Expand Down Expand Up @@ -86,4 +89,22 @@ class OneSignalImpTests : FunSpec({
}
}
}

context("initWithContext") {
context("called without appId") {
test("has cached legacy appId should initialize") {
val os = OneSignalImp()
val context = ApplicationProvider.getApplicationContext<Context>()

os.initWithContext(context, null)


}
test("does not have cached legacy appId should return early") {
// Given
// When
// Then
}
}
}
})
Loading