@@ -6,7 +6,7 @@ import io.github.jan.supabase.auth.OtpType
6
6
import io.github.jan.supabase.auth.PKCEConstants
7
7
import io.github.jan.supabase.auth.SignOutScope
8
8
import io.github.jan.supabase.auth.auth
9
- import io.github.jan.supabase.auth.minimalSettings
9
+ import io.github.jan.supabase.auth.minimalConfig
10
10
import io.github.jan.supabase.auth.providers.Google
11
11
import io.github.jan.supabase.auth.providers.builtin.Email
12
12
import io.github.jan.supabase.auth.providers.builtin.IDToken
@@ -39,13 +39,13 @@ class AuthRequestTest {
39
39
40
40
private val configuration: SupabaseClientBuilder .() -> Unit = {
41
41
install(Auth ) {
42
- minimalSettings ()
42
+ minimalConfig ()
43
43
flowType = FlowType .PKCE
44
44
}
45
45
}
46
46
47
47
@Test
48
- fun testSignUpWithEmailNoAutoconfirm () {
48
+ fun testSignUpWithEmailNoAutoConfirm () {
49
49
runTest {
50
50
val expectedEmail
= " [email protected] "
51
51
val expectedPassword = " password"
@@ -81,7 +81,43 @@ class AuthRequestTest {
81
81
}
82
82
83
83
@Test
84
- fun testSignUpWithEmailAutoconfirm () {
84
+ fun testSignUpWithEmailAutoConfirm () {
85
+ runTest {
86
+ val expectedEmail
= " [email protected] "
87
+ val expectedPassword = " password"
88
+ val captchaToken = " captchaToken"
89
+ val userData = buildJsonObject {
90
+ put(" key" , " value" )
91
+ }
92
+ val client = createMockedSupabaseClient(configuration = configuration) {
93
+ val body = it.body.toJsonElement().jsonObject
94
+ val metaSecurity = body[" gotrue_meta_security" ]!! .jsonObject
95
+ assertMethodIs(HttpMethod .Post , it.method)
96
+ assertPathIs(" /signup" , it.url.pathAfterVersion())
97
+ assertEquals(expectedEmail, body[" email" ]?.jsonPrimitive?.content)
98
+ assertEquals(expectedPassword, body[" password" ]?.jsonPrimitive?.content)
99
+ assertEquals(captchaToken, metaSecurity[" captcha_token" ]?.jsonPrimitive?.content)
100
+ assertEquals(userData, body[" data" ]!! .jsonObject)
101
+ containsCodeChallenge(body)
102
+ respondJson(
103
+ sampleSessionWithUserData(email
= " [email protected] " , phone
= " +1234567890" )
104
+ )
105
+ }
106
+ val user = client.auth.signUpWith(Email ) {
107
+ email = expectedEmail
108
+ password = expectedPassword
109
+ this .captchaToken = captchaToken
110
+ data = userData
111
+ }
112
+ assertNotNull(user)
113
+ assertEquals(expectedEmail, user?.email, " Email should be equal" )
114
+ assertNotNull(client.auth.currentSessionOrNull(), " Session should not be null" )
115
+ assertEquals(client.auth.sessionSource(), SessionSource .SignUp (Email ))
116
+ }
117
+ }
118
+
119
+ @Test
120
+ fun testSignUpWithEmailAutoConfirmWithoutUserData () {
85
121
runTest {
86
122
val expectedEmail
= " [email protected] "
87
123
val expectedPassword = " password"
@@ -116,7 +152,7 @@ class AuthRequestTest {
116
152
}
117
153
118
154
@Test
119
- fun testSignUpWithPhoneAutoconfirm () {
155
+ fun testSignUpWithPhoneAutoConfirm () {
120
156
runTest {
121
157
val expectedPhone = " +1234567890"
122
158
val expectedPassword = " password"
@@ -135,7 +171,7 @@ class AuthRequestTest {
135
171
assertEquals(userData, body[" data" ]!! .jsonObject)
136
172
containsCodeChallenge(body)
137
173
respondJson(
138
- sampleUserSession ()
174
+ sampleSessionWithUserData ()
139
175
)
140
176
}
141
177
val user = client.auth.signUpWith(Phone ) {
@@ -144,14 +180,14 @@ class AuthRequestTest {
144
180
this .captchaToken = captchaToken
145
181
data = userData
146
182
}
147
- assertNull (user)
183
+ assertNotNull (user)
148
184
assertNotNull(client.auth.currentSessionOrNull(), " Session should not be null" )
149
185
assertEquals(client.auth.sessionSource(), SessionSource .SignUp (Phone ))
150
186
}
151
187
}
152
188
153
189
@Test
154
- fun testSignUpWithPhoneNoAutoconfirm () {
190
+ fun testSignUpWithPhoneNoAutoConfirm () {
155
191
runTest {
156
192
val expectedPhone = " +1234567890"
157
193
val expectedPassword = " password"
@@ -693,6 +729,25 @@ class AuthRequestTest {
693
729
}
694
730
""" .trimIndent()
695
731
732
+ private fun sampleSessionWithUserData (email : String? = null, phone : String? = null) = """
733
+ {
734
+ "id": "id",
735
+ "aud": "aud",
736
+ "email": "$email ",
737
+ "phone": "$phone ",
738
+ "access_token": "token",
739
+ "refresh_token": "refresh",
740
+ "token_type": "bearer",
741
+ "expires_in": 3600,
742
+ "user": {
743
+ "id": "id",
744
+ "aud": "aud",
745
+ "email": "$email ",
746
+ "phone": "$phone "
747
+ }
748
+ }
749
+ """ .trimIndent()
750
+
696
751
private fun containsCodeChallenge (body : JsonObject ) {
697
752
assertNotNull(body[" code_challenge" ])
698
753
assertEquals(PKCEConstants .CHALLENGE_METHOD , body[" code_challenge_method" ]?.jsonPrimitive?.content)
0 commit comments