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

Fix setting consentGiven throwing if called before initWithContext #2200

Merged
merged 1 commit into from
Oct 4, 2024
Merged
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 @@ -126,8 +126,9 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
}

// Services required by this class
private val operationRepo: IOperationRepo
get() = services.getService()
// WARNING: OperationRepo depends on OperationModelStore which in-turn depends
// on ApplicationService.appContext being non-null.
private var operationRepo: IOperationRepo? = null
private val identityModelStore: IdentityModelStore
get() = services.getService()
private val propertiesModelStore: PropertiesModelStore
Expand Down Expand Up @@ -208,6 +209,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
// get the current config model, if there is one
configModel = services.getService<ConfigModelStore>().model
sessionModel = services.getService<SessionModelStore>().model
operationRepo = services.getService<IOperationRepo>()

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,52 @@ class OneSignalImpTests : FunSpec({
// Then
exception.message shouldBe "Must call 'initWithContext' before 'logout'"
}

// consentRequired probably should have thrown like the other OneSignal methods in 5.0.0,
// but we can't make a breaking change to an existing API.
context("consentRequired") {
context("before initWithContext") {
test("set should not throw") {
// Given
val os = OneSignalImp()
// When
os.consentRequired = false
os.consentRequired = true
// Then
// Test fails if the above throws
}
test("get should not throw") {
// Given
val os = OneSignalImp()
// When
println(os.consentRequired)
// Then
// Test fails if the above throws
}
}
}

// consentGiven probably should have thrown like the other OneSignal methods in 5.0.0,
// but we can't make a breaking change to an existing API.
context("consentGiven") {
context("before initWithContext") {
test("set should not throw") {
// Given
val os = OneSignalImp()
// When
os.consentGiven = true
os.consentGiven = false
// Then
// Test fails if the above throws
}
test("get should not throw") {
// Given
val os = OneSignalImp()
// When
println(os.consentGiven)
// Then
// Test fails if the above throws
}
}
}
})
Loading