Skip to content

Commit f792edd

Browse files
dkrizanclaude
andcommitted
fix: revert unlimited check to < 0 — zero is a real limit
limit.limit is always set explicitly (never relies on the JPA default), so 0 means a genuine strict-zero limit rather than "unlimited". Only negative values (-1) represent unlimited. Update tests accordingly: zero-limit cases now assert that an exception is thrown rather than that the check is skipped. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dbd1ede commit f792edd

4 files changed

Lines changed: 12 additions & 19 deletions

File tree

ee/backend/app/src/main/kotlin/io/tolgee/ee/component/limitsAndReporting/generic/GenericLimitChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ open class GenericLimitChecker(
1717
fun check(required: Long?) = check { required }
1818

1919
fun check(requiredProvider: () -> Long?) {
20-
if (limit.limit <= 0) {
20+
if (limit.limit < 0) {
2121
return
2222
}
2323

ee/backend/tests/src/test/kotlin/io/tolgee/ee/unit/limitsAndReporting/GenericLimitCheckerTest.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ class GenericLimitCheckerTest {
3030
)
3131

3232
@Test
33-
fun `zero limit - no exception and provider not called`() {
34-
var providerCalled = false
35-
val checker =
36-
checker(
37-
zeroLimit(),
38-
includedProvider = {
39-
providerCalled = true
40-
RuntimeException()
41-
},
42-
)
33+
fun `zero limit - throws included exception (not treated as unlimited)`() {
34+
val checker = checker(zeroLimit())
4335

44-
assertDoesNotThrow { checker.check { 999L } }
45-
assertFalse(providerCalled)
36+
val ex = assertThrows<RuntimeException> { checker.check { 999L } }
37+
38+
assert(ex.message == "included: 999")
4639
}
4740

4841
@Test

ee/backend/tests/src/test/kotlin/io/tolgee/ee/unit/limitsAndReporting/KeysLimitCheckerTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.tolgee.ee.component.limitsAndReporting.generic.KeysLimitChecker
55
import io.tolgee.exceptions.limits.PlanLimitExceededKeysException
66
import io.tolgee.exceptions.limits.PlanSpendingLimitExceededKeysException
77
import org.assertj.core.api.Assertions.assertThat
8-
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
98
import org.junit.jupiter.api.Test
109
import org.junit.jupiter.api.assertThrows
1110

@@ -25,9 +24,10 @@ class KeysLimitCheckerTest {
2524
)
2625

2726
@Test
28-
fun `zero keys limit - no exception (unlimited detection bug fix)`() {
27+
fun `zero keys limit - throws PlanLimitExceededKeysException (zero is a real limit)`() {
2928
val checker = KeysLimitChecker(usageLimits(keys = UsageLimits.Limit(included = 0, limit = 0)))
30-
assertDoesNotThrow { checker.check { 999L } }
29+
30+
assertThrows<PlanLimitExceededKeysException> { checker.check { 999L } }
3131
}
3232

3333
@Test

ee/backend/tests/src/test/kotlin/io/tolgee/ee/unit/limitsAndReporting/StringsLimitCheckerTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.tolgee.ee.component.limitsAndReporting.generic.StringsLimitChecker
55
import io.tolgee.exceptions.limits.PlanLimitExceededStringsException
66
import io.tolgee.exceptions.limits.PlanSpendingLimitExceededStringsException
77
import org.assertj.core.api.Assertions.assertThat
8-
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
98
import org.junit.jupiter.api.Test
109
import org.junit.jupiter.api.assertThrows
1110

@@ -25,9 +24,10 @@ class StringsLimitCheckerTest {
2524
)
2625

2726
@Test
28-
fun `zero strings limit - no exception (unlimited detection bug fix)`() {
27+
fun `zero strings limit - throws PlanLimitExceededStringsException (zero is a real limit)`() {
2928
val checker = StringsLimitChecker(usageLimits(strings = UsageLimits.Limit(included = 0, limit = 0)))
30-
assertDoesNotThrow { checker.check { 999L } }
29+
30+
assertThrows<PlanLimitExceededStringsException> { checker.check { 999L } }
3131
}
3232

3333
@Test

0 commit comments

Comments
 (0)