Skip to content

Commit

Permalink
Fix remote-config-impl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs committed Mar 22, 2022
1 parent f918365 commit 8fc57a4
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 21 deletions.
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 */
@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 */
@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 */
@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

0 comments on commit 8fc57a4

Please sign in to comment.