Skip to content

Commit c1b4b5d

Browse files
committed
test(services/flipcash): add error hierarchy tests
Covers LoginError, RegisterError, EmailVerificationError, PhoneVerificationError, PlacePoolBetError, and GetJwtError.
1 parent 735562e commit c1b4b5d

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

  • services/flipcash/src/test/kotlin/com/flipcash/services/models
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package com.flipcash.services.models
2+
3+
import com.getcode.utils.CodeServerError
4+
import kotlin.test.Test
5+
import kotlin.test.assertEquals
6+
import kotlin.test.assertIs
7+
import kotlin.test.assertNull
8+
import kotlin.test.assertSame
9+
10+
class ErrorsTest {
11+
12+
// -- LoginError --
13+
14+
@Test
15+
fun `LoginError subtypes are Throwable`() {
16+
assertIs<Throwable>(LoginError.InvalidTimestamp())
17+
assertIs<Throwable>(LoginError.Denied())
18+
assertIs<Throwable>(LoginError.Unrecognized())
19+
assertIs<Throwable>(LoginError.Other())
20+
}
21+
22+
@Test
23+
fun `LoginError subtypes are CodeServerError`() {
24+
assertIs<CodeServerError>(LoginError.InvalidTimestamp())
25+
assertIs<CodeServerError>(LoginError.Denied())
26+
assertIs<CodeServerError>(LoginError.Unrecognized())
27+
assertIs<CodeServerError>(LoginError.Other())
28+
}
29+
30+
@Test
31+
fun `LoginError InvalidTimestamp has expected message`() {
32+
assertEquals("Invalid timestamp", LoginError.InvalidTimestamp().message)
33+
}
34+
35+
@Test
36+
fun `LoginError Other preserves cause`() {
37+
val root = RuntimeException("something broke")
38+
val error = LoginError.Other(root)
39+
assertSame(root, error.cause)
40+
assertEquals("something broke", error.message)
41+
}
42+
43+
@Test
44+
fun `LoginError Other with null cause has null message`() {
45+
val error = LoginError.Other(null)
46+
assertNull(error.cause)
47+
assertNull(error.message)
48+
}
49+
50+
// -- RegisterError --
51+
52+
@Test
53+
fun `RegisterError InvalidSignature has expected message`() {
54+
assertEquals("Invalid signature", RegisterError.InvalidSignature().message)
55+
}
56+
57+
@Test
58+
fun `RegisterError subtypes are CodeServerError`() {
59+
assertIs<CodeServerError>(RegisterError.InvalidSignature())
60+
assertIs<CodeServerError>(RegisterError.Denied())
61+
assertIs<CodeServerError>(RegisterError.Unrecognized())
62+
assertIs<CodeServerError>(RegisterError.Other())
63+
}
64+
65+
@Test
66+
fun `RegisterError Other preserves cause`() {
67+
val root = IllegalStateException("bad state")
68+
val error = RegisterError.Other(root)
69+
assertSame(root, error.cause)
70+
assertEquals("bad state", error.message)
71+
}
72+
73+
// -- EmailVerificationError --
74+
75+
@Test
76+
fun `EmailVerificationError has expected variants`() {
77+
assertIs<EmailVerificationError>(EmailVerificationError.Denied())
78+
assertIs<EmailVerificationError>(EmailVerificationError.RateLimited())
79+
assertIs<EmailVerificationError>(EmailVerificationError.InvalidEmailAddress())
80+
assertIs<EmailVerificationError>(EmailVerificationError.InvalidVerificationCode())
81+
assertIs<EmailVerificationError>(EmailVerificationError.NoVerification())
82+
assertIs<EmailVerificationError>(EmailVerificationError.Unrecognized())
83+
assertIs<EmailVerificationError>(EmailVerificationError.Other())
84+
}
85+
86+
@Test
87+
fun `EmailVerificationError messages are correct`() {
88+
assertEquals("Rate limited", EmailVerificationError.RateLimited().message)
89+
assertEquals("Invalid email address", EmailVerificationError.InvalidEmailAddress().message)
90+
assertEquals("Invalid verification code", EmailVerificationError.InvalidVerificationCode().message)
91+
assertEquals("No verification", EmailVerificationError.NoVerification().message)
92+
}
93+
94+
// -- PhoneVerificationError --
95+
96+
@Test
97+
fun `PhoneVerificationError UnsupportedPhoneType has expected message`() {
98+
assertEquals("Unsupported phone type", PhoneVerificationError.UnsupportedPhoneType().message)
99+
}
100+
101+
@Test
102+
fun `PhoneVerificationError subtypes are CodeServerError`() {
103+
assertIs<CodeServerError>(PhoneVerificationError.Denied())
104+
assertIs<CodeServerError>(PhoneVerificationError.RateLimited())
105+
assertIs<CodeServerError>(PhoneVerificationError.InvalidPhoneNumber())
106+
assertIs<CodeServerError>(PhoneVerificationError.UnsupportedPhoneType())
107+
assertIs<CodeServerError>(PhoneVerificationError.InvalidVerificationCode())
108+
assertIs<CodeServerError>(PhoneVerificationError.NoVerification())
109+
}
110+
111+
// -- PlacePoolBetError --
112+
113+
@Test
114+
fun `PlacePoolBetError has specific variants with expected messages`() {
115+
assertEquals("Pool not found", PlacePoolBetError.PoolNotFound().message)
116+
assertEquals("Pool closed", PlacePoolBetError.PoolClosed().message)
117+
assertEquals("Bet already made", PlacePoolBetError.BetAlreadyMade().message)
118+
assertEquals("Max bets received", PlacePoolBetError.MaxBetsReceived().message)
119+
assertEquals("Bet outcome solidified", PlacePoolBetError.BetOutcomeSolidified().message)
120+
}
121+
122+
@Test
123+
fun `PlacePoolBetError subtypes are CodeServerError`() {
124+
assertIs<CodeServerError>(PlacePoolBetError.PoolNotFound())
125+
assertIs<CodeServerError>(PlacePoolBetError.PoolClosed())
126+
assertIs<CodeServerError>(PlacePoolBetError.BetAlreadyMade())
127+
assertIs<CodeServerError>(PlacePoolBetError.MaxBetsReceived())
128+
}
129+
130+
// -- GetJwtError --
131+
132+
@Test
133+
fun `GetJwtError has expected variants with correct messages`() {
134+
assertEquals("Unsupported provider", GetJwtError.UnsupportedProvider().message)
135+
assertEquals("Invalid api key", GetJwtError.InvalidApiKey().message)
136+
assertEquals("Phone verification required", GetJwtError.PhoneVerificationRequired().message)
137+
assertEquals("Email verification required", GetJwtError.EmailVerificationRequired().message)
138+
assertEquals("Denied", GetJwtError.Denied().message)
139+
}
140+
141+
@Test
142+
fun `GetJwtError subtypes are CodeServerError`() {
143+
assertIs<CodeServerError>(GetJwtError.UnsupportedProvider())
144+
assertIs<CodeServerError>(GetJwtError.InvalidApiKey())
145+
assertIs<CodeServerError>(GetJwtError.PhoneVerificationRequired())
146+
assertIs<CodeServerError>(GetJwtError.EmailVerificationRequired())
147+
assertIs<CodeServerError>(GetJwtError.Denied())
148+
assertIs<CodeServerError>(GetJwtError.Unrecognized())
149+
assertIs<CodeServerError>(GetJwtError.Other())
150+
}
151+
152+
@Test
153+
fun `GetJwtError Other preserves cause`() {
154+
val root = RuntimeException("jwt failure")
155+
val error = GetJwtError.Other(root)
156+
assertSame(root, error.cause)
157+
assertEquals("jwt failure", error.message)
158+
}
159+
}

0 commit comments

Comments
 (0)