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

Improve feature toggle API to actually use default value #1822

Merged
merged 4 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix remote-config-impl tests
  • Loading branch information
aitorvs committed Mar 22, 2022
commit 8fc57a4290c4f4641dcc639fd46bca94a457b754
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ package com.duckduckgo.remote.messaging.impl

import com.duckduckgo.remote.messaging.api.RemoteMessage
import com.duckduckgo.remote.messaging.api.RemoteMessagingRepository
import com.duckduckgo.remote.messaging.impl.matchers.AndroidAppAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.DeviceAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.UserAttributeMatcher
import com.duckduckgo.remote.messaging.impl.di.DeviceAttrMatcher
import com.duckduckgo.remote.messaging.impl.di.UserAttrMatcher
import com.duckduckgo.remote.messaging.impl.matchers.AttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.EvaluationResult
import com.duckduckgo.remote.messaging.impl.matchers.toResult
import com.duckduckgo.remote.messaging.impl.models.MatchingAttribute
import com.duckduckgo.remote.messaging.impl.models.RemoteConfig
import com.duckduckgo.remote.messaging.impl.matchers.EvaluationResult
import com.duckduckgo.remote.messaging.impl.models.MatchingAttribute.Unknown
import timber.log.Timber

class RemoteMessagingConfigMatcher(
val deviceAttributeMatcher: DeviceAttributeMatcher,
val androidAppAttributeMatcher: AndroidAppAttributeMatcher,
@DeviceAttrMatcher val deviceAttributeMatcher: AttributeMatcher,
@DeviceAttrMatcher val androidAppAttributeMatcher: AttributeMatcher,
val remoteMessagingRepository: RemoteMessagingRepository,
val userAttributeMatcher: UserAttributeMatcher
@UserAttrMatcher val userAttributeMatcher: AttributeMatcher
) {
private val matchers = listOf(deviceAttributeMatcher, androidAppAttributeMatcher, userAttributeMatcher)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.remote.messaging.impl.di

import javax.inject.Qualifier

/** Identifies a coroutine scope type that is scope to the app lifecycle */
aitorvs marked this conversation as resolved.
Show resolved Hide resolved
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class AndroidAppAttrMatcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.remote.messaging.impl.di

import javax.inject.Qualifier

/** Identifies a coroutine scope type that is scope to the app lifecycle */
aitorvs marked this conversation as resolved.
Show resolved Hide resolved
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class DeviceAttrMatcher
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.duckduckgo.remote.messaging.api.RemoteMessagingRepository
import com.duckduckgo.remote.messaging.impl.*
import com.duckduckgo.remote.messaging.impl.mappers.RemoteMessagingConfigJsonMapper
import com.duckduckgo.remote.messaging.impl.matchers.AndroidAppAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.AttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.DeviceAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.UserAttributeMatcher
import com.duckduckgo.remote.messaging.impl.network.RemoteMessagingService
Expand Down Expand Up @@ -129,37 +130,40 @@ class DataSourceModule {
@Provides
@SingleInstanceIn(AppScope::class)
fun providesRemoteMessagingConfigMatcher(
deviceAttributeMatcher: DeviceAttributeMatcher,
androidAppAttributeMatcher: AndroidAppAttributeMatcher,
@DeviceAttrMatcher deviceAttributeMatcher: AttributeMatcher,
@AndroidAppAttrMatcher androidAppAttributeMatcher: AttributeMatcher,
remoteMessagingRepository: RemoteMessagingRepository,
userAttributeMatcher: UserAttributeMatcher
@UserAttrMatcher userAttributeMatcher: AttributeMatcher
): RemoteMessagingConfigMatcher {
return RemoteMessagingConfigMatcher(deviceAttributeMatcher, androidAppAttributeMatcher, remoteMessagingRepository, userAttributeMatcher)
}

@Provides
@SingleInstanceIn(AppScope::class)
@AndroidAppAttrMatcher
fun providesAndroidAppAttributeMatcher(
appProperties: AppProperties,
appBuildConfig: AppBuildConfig
): AndroidAppAttributeMatcher {
): AttributeMatcher {
return AndroidAppAttributeMatcher(appProperties, appBuildConfig)
}

@Provides
@SingleInstanceIn(AppScope::class)
@DeviceAttrMatcher
fun providesDeviceAttributeMatcher(
appBuildConfig: AppBuildConfig,
appProperties: AppProperties
): DeviceAttributeMatcher {
): AttributeMatcher {
return DeviceAttributeMatcher(appBuildConfig, appProperties)
}

@Provides
@SingleInstanceIn(AppScope::class)
@UserAttrMatcher
fun providesUserAttributeMatcher(
userBrowserProperties: UserBrowserProperties
): UserAttributeMatcher {
): AttributeMatcher {
return UserAttributeMatcher(userBrowserProperties)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.remote.messaging.impl.di

import javax.inject.Qualifier

/** Identifies a coroutine scope type that is scope to the app lifecycle */
aitorvs marked this conversation as resolved.
Show resolved Hide resolved
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class UserAttrMatcher
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package com.duckduckgo.remote.messaging.impl

import com.duckduckgo.app.CoroutineTestRule
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.remote.messaging.api.RemoteMessagingRepository
import com.duckduckgo.remote.messaging.fixtures.JsonRemoteMessageOM.aJsonRemoteMessagingConfig
import com.duckduckgo.remote.messaging.fixtures.RemoteMessagingConfigOM.aRemoteMessagingConfig
import com.duckduckgo.remote.messaging.impl.mappers.RemoteMessagingConfigJsonMapper
import com.duckduckgo.remote.messaging.impl.matchers.AttributeMatcher
import com.duckduckgo.remote.messaging.store.RemoteMessagingConfigRepository
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.mock
Expand All @@ -29,25 +31,38 @@ import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.threeten.bp.LocalDateTime
import org.threeten.bp.format.DateTimeFormatter
import java.util.*

@ExperimentalCoroutinesApi
class RealRemoteMessagingConfigProcessorTest {

@get:Rule var coroutineRule = CoroutineTestRule()

private val remoteMessagingConfigJsonMapper = mock<RemoteMessagingConfigJsonMapper>()
private val appBuildConfig: AppBuildConfig = mock()
private val remoteMessagingConfigJsonMapper = RemoteMessagingConfigJsonMapper(appBuildConfig)
private val remoteMessagingConfigRepository = mock<RemoteMessagingConfigRepository>()
private val remoteMessagingRepository = mock<RemoteMessagingRepository>()
private val remoteMessagingConfigMatcher = mock<RemoteMessagingConfigMatcher>()
private val remoteMessagingConfigMatcher = RemoteMessagingConfigMatcher(
mock<AttributeMatcher>(),
mock<AttributeMatcher>(),
mock<RemoteMessagingRepository>(),
mock<AttributeMatcher>(),
)

private val testee = RealRemoteMessagingConfigProcessor(
remoteMessagingConfigJsonMapper, remoteMessagingConfigRepository, remoteMessagingRepository, remoteMessagingConfigMatcher
)

@Before
fun setup() {
whenever(appBuildConfig.deviceLocale).thenReturn(Locale.US)
}

@Test
fun whenNewVersionThenEvaluate() = runTest {
whenever(remoteMessagingConfigRepository.get()).thenReturn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package com.duckduckgo.remote.messaging.impl
import com.duckduckgo.remote.messaging.api.RemoteMessagingRepository
import com.duckduckgo.remote.messaging.fixtures.RemoteMessageOM.aMediumMessage
import com.duckduckgo.remote.messaging.fixtures.RemoteMessageOM.aSmallMessage
import com.duckduckgo.remote.messaging.impl.matchers.AndroidAppAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.DeviceAttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.AttributeMatcher
import com.duckduckgo.remote.messaging.impl.matchers.EvaluationResult
import com.duckduckgo.remote.messaging.impl.matchers.UserAttributeMatcher
import com.duckduckgo.remote.messaging.impl.models.MatchingAttribute
import com.duckduckgo.remote.messaging.impl.models.MatchingAttribute.Api
import com.duckduckgo.remote.messaging.impl.models.MatchingAttribute.Bookmarks
Expand All @@ -40,9 +38,9 @@ import org.junit.Test

class RemoteMessagingConfigMatcherTest {

private val deviceAttributeMatcher: DeviceAttributeMatcher = mock()
private val androidAppAttributeMatcher: AndroidAppAttributeMatcher = mock()
private val userAttributeMatcher: UserAttributeMatcher = mock()
private val deviceAttributeMatcher: AttributeMatcher = mock()
private val androidAppAttributeMatcher: AttributeMatcher = mock()
private val userAttributeMatcher: AttributeMatcher = mock()
private val remoteMessagingRepository: RemoteMessagingRepository = mock()

private val testee = RemoteMessagingConfigMatcher(
Expand Down