Skip to content

Commit 6406a0d

Browse files
committedDec 8, 2024
AND-20047 Exclude dedicated id ranges
1 parent 7652be4 commit 6406a0d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎analytics-processor/src/jvmTest/kotlin/mega/privacy/mobile/analytics/processor/identifier/LegacyIdGeneratorTest.kt

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import mega.privacy.mobile.analytics.processor.identifier.model.GenerateLegacyId
55
import org.junit.jupiter.api.Test
66
import org.junit.jupiter.api.TestInstance
77
import org.junit.jupiter.api.assertThrows
8+
import org.junit.jupiter.params.ParameterizedTest
9+
import org.junit.jupiter.params.provider.MethodSource
10+
import kotlin.streams.asStream
811

912
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1013
class LegacyIdGeneratorTest {
@@ -72,4 +75,20 @@ class LegacyIdGeneratorTest {
7275

7376
assertThrows<IllegalStateException> { underTest(request) }
7477
}
78+
79+
@ParameterizedTest
80+
@MethodSource(value = ["rangeSource"])
81+
fun `test that exception is thrown if id falls within 300 000 to 499 999`(legacyId: Int) {
82+
val eventName = "eventName"
83+
84+
val request = GenerateLegacyIdRequest(
85+
legacyId = legacyId,
86+
eventName = eventName,
87+
currentIdMap = emptyMap(),
88+
)
89+
90+
assertThrows<IllegalStateException> { underTest(request) }
91+
}
92+
93+
private fun rangeSource() = (300_000..499_999).step(1000).asSequence().asStream()
7594
}

‎analytics-processor/src/main/kotlin/mega/privacy/mobile/analytics/processor/identifier/LegacyIdGenerator.kt

+6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ class LegacyIdGenerator : IdGenerator<GenerateLegacyIdRequest> {
99

1010
override fun invoke(request: GenerateLegacyIdRequest): Map<String, Int> {
1111
val idMap = request.currentIdMap.toMutableMap()
12+
13+
checkRestrictedRange(request)
1214
checkExistingIds(idMap, request)
1315
idMap.putIfAbsent(request.eventName, request.legacyId)
1416
return idMap
1517
}
1618

19+
private fun checkRestrictedRange(request: GenerateLegacyIdRequest) {
20+
if ((300_000..499_999).contains(request.legacyId)) throw IllegalStateException("Id provided, ${request.legacyId}, is not allowed to fall within the range 300 000 to 499 999")
21+
}
22+
1723
private fun checkExistingIds(
1824
idMap: MutableMap<String, Int>,
1925
request: GenerateLegacyIdRequest,

0 commit comments

Comments
 (0)
Please sign in to comment.