@@ -43,7 +43,7 @@ class AuthRequestTest {
43
43
}
44
44
45
45
@Test
46
- fun testSignUpWithEmailNoAutoconfirm () {
46
+ fun testSignUpWithEmailNoAutoConfirm () {
47
47
runTest {
48
48
val expectedEmail
= " [email protected] "
49
49
val expectedPassword = " password"
@@ -79,7 +79,43 @@ class AuthRequestTest {
79
79
}
80
80
81
81
@Test
82
- fun testSignUpWithEmailAutoconfirm () {
82
+ fun testSignUpWithEmailAutoConfirm () {
83
+ runTest {
84
+ val expectedEmail
= " [email protected] "
85
+ val expectedPassword = " password"
86
+ val captchaToken = " captchaToken"
87
+ val userData = buildJsonObject {
88
+ put(" key" , " value" )
89
+ }
90
+ val client = createMockedSupabaseClient(configuration = configuration) {
91
+ val body = it.body.toJsonElement().jsonObject
92
+ val metaSecurity = body[" gotrue_meta_security" ]!! .jsonObject
93
+ assertMethodIs(HttpMethod .Post , it.method)
94
+ assertPathIs(" /signup" , it.url.pathAfterVersion())
95
+ assertEquals(expectedEmail, body[" email" ]?.jsonPrimitive?.content)
96
+ assertEquals(expectedPassword, body[" password" ]?.jsonPrimitive?.content)
97
+ assertEquals(captchaToken, metaSecurity[" captcha_token" ]?.jsonPrimitive?.content)
98
+ assertEquals(userData, body[" data" ]!! .jsonObject)
99
+ containsCodeChallenge(body)
100
+ respondJson(
101
+ sampleSessionWithUserData(email
= " [email protected] " , phone
= " +1234567890" )
102
+ )
103
+ }
104
+ val user = client.auth.signUpWith(Email ) {
105
+ email = expectedEmail
106
+ password = expectedPassword
107
+ this .captchaToken = captchaToken
108
+ data = userData
109
+ }
110
+ assertNotNull(user)
111
+ assertEquals(expectedEmail, user?.email, " Email should be equal" )
112
+ assertNotNull(client.auth.currentSessionOrNull(), " Session should not be null" )
113
+ assertEquals(client.auth.sessionSource(), SessionSource .SignUp (Email ))
114
+ }
115
+ }
116
+
117
+ @Test
118
+ fun testSignUpWithEmailAutoConfirmWithoutUserData () {
83
119
runTest {
84
120
val expectedEmail
= " [email protected] "
85
121
val expectedPassword = " password"
@@ -114,7 +150,7 @@ class AuthRequestTest {
114
150
}
115
151
116
152
@Test
117
- fun testSignUpWithPhoneAutoconfirm () {
153
+ fun testSignUpWithPhoneAutoConfirm () {
118
154
runTest {
119
155
val expectedPhone = " +1234567890"
120
156
val expectedPassword = " password"
@@ -133,7 +169,7 @@ class AuthRequestTest {
133
169
assertEquals(userData, body[" data" ]!! .jsonObject)
134
170
containsCodeChallenge(body)
135
171
respondJson(
136
- sampleUserSession ()
172
+ sampleSessionWithUserData ()
137
173
)
138
174
}
139
175
val user = client.auth.signUpWith(Phone ) {
@@ -142,14 +178,14 @@ class AuthRequestTest {
142
178
this .captchaToken = captchaToken
143
179
data = userData
144
180
}
145
- assertNull (user)
181
+ assertNotNull (user)
146
182
assertNotNull(client.auth.currentSessionOrNull(), " Session should not be null" )
147
183
assertEquals(client.auth.sessionSource(), SessionSource .SignUp (Phone ))
148
184
}
149
185
}
150
186
151
187
@Test
152
- fun testSignUpWithPhoneNoAutoconfirm () {
188
+ fun testSignUpWithPhoneNoAutoConfirm () {
153
189
runTest {
154
190
val expectedPhone = " +1234567890"
155
191
val expectedPassword = " password"
@@ -690,6 +726,25 @@ class AuthRequestTest {
690
726
}
691
727
""" .trimIndent()
692
728
729
+ private fun sampleSessionWithUserData (email : String? = null, phone : String? = null) = """
730
+ {
731
+ "id": "id",
732
+ "aud": "aud",
733
+ "email": "$email ",
734
+ "phone": "$phone ",
735
+ "access_token": "token",
736
+ "refresh_token": "refresh",
737
+ "token_type": "bearer",
738
+ "expires_in": 3600,
739
+ "user": {
740
+ "id": "id",
741
+ "aud": "aud",
742
+ "email": "$email ",
743
+ "phone": "$phone "
744
+ }
745
+ }
746
+ """ .trimIndent()
747
+
693
748
private fun containsCodeChallenge (body : JsonObject ) {
694
749
assertNotNull(body[" code_challenge" ])
695
750
assertEquals(PKCEConstants .CHALLENGE_METHOD , body[" code_challenge_method" ]?.jsonPrimitive?.content)
0 commit comments