-
Notifications
You must be signed in to change notification settings - Fork 6
[Android] Поддержка таргетинга visit для in-app #3211 #441
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package cloud.mindbox.mobile_sdk.inapp.domain.models | |
|
|
||
| import cloud.mindbox.mobile_sdk.di.mindboxInject | ||
| import cloud.mindbox.mobile_sdk.logger.mindboxLogD | ||
| import cloud.mindbox.mobile_sdk.repository.MindboxPreferences | ||
|
|
||
| internal interface ITargeting { | ||
| fun checkTargeting(data: TargetingData): Boolean | ||
|
|
@@ -34,6 +35,13 @@ internal enum class Kind { | |
| NEGATIVE | ||
| } | ||
|
|
||
| internal enum class KindVisit { | ||
| GTE, | ||
| LTE, | ||
| EQUALS, | ||
| NOT_EQUALS | ||
| } | ||
|
|
||
| internal enum class KindAny { | ||
| ANY, | ||
| NONE, | ||
|
|
@@ -338,4 +346,49 @@ internal sealed class TreeTargeting(open val type: String) : | |
| return false | ||
| } | ||
| } | ||
|
|
||
| internal data class VisitNode(override val type: String, val kind: KindVisit, val value: Long) : | ||
| TreeTargeting(type) { | ||
|
|
||
| override fun checkTargeting(data: TargetingData): Boolean { | ||
| val userVisitCount = MindboxPreferences.userVisitCount.toLong() | ||
| return when (kind) { | ||
| KindVisit.GTE -> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем скобки ставить? мне нравится больше когда в одну строку
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я обычно всегда ставлю, на случай, что если придется что-то дописывать, то не пришлось бы их ставить потом. А у нас нет нигде какого-то код стайла, чтобы посмотреть как лучше писать |
||
| value >= userVisitCount | ||
| } | ||
|
|
||
| KindVisit.LTE -> { | ||
| value <= userVisitCount | ||
| } | ||
|
|
||
| KindVisit.EQUALS -> { | ||
| value == userVisitCount | ||
| } | ||
|
|
||
| KindVisit.NOT_EQUALS -> { | ||
| value != userVisitCount | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override suspend fun fetchTargetingInfo(data: TargetingData) { | ||
| return | ||
| } | ||
|
|
||
| override fun hasSegmentationNode(): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| override fun hasGeoNode(): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| override fun hasOperationNode(): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| override suspend fun getOperationsSet(): Set<String> { | ||
| return emptySet() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1651,6 +1651,204 @@ internal class InAppValidatorTest { | |
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and its valid with gte`() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь бы получше было что-то такое validate targeting dto |
||
| assertTrue( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "gte", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and its valid with lte`() { | ||
| assertTrue( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "lte", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and its valid with equals`() { | ||
| assertTrue( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "equals", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and its valid with not equals`() { | ||
| assertTrue( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "notEquals", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and type is null`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = null, kind = "notBlank", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and type is blank`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "", kind = "notBlank", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and kind is null`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = null, value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and kind is blank`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and kind is unknown`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "notBlank", value = 1L | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and value is null`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "notBlank", value = null | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `validate targeting dto is visit node and value is less than 1`() { | ||
| assertFalse( | ||
| inAppValidator.validateInApp( | ||
| InAppStub.getInAppDto().copy( | ||
| targeting = InAppStub.getTargetingVisitNodeDto().copy( | ||
| type = "notBlank", kind = "notBlank", value = 0 | ||
| ), form = InAppStub.getInAppDto().form?.copy( | ||
| variants = listOf( | ||
| InAppStub.getModalWindowDto() | ||
| .copy(type = "def") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `in-app version is lower than required`() { | ||
| val lowInAppVersion = Constants.SDK_VERSION_NUMERIC - 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А 0 не может быть?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
согласен что > 0
"value": 1 // required long > 0