1
1
package com.hrv.mart.backendauth.controller
2
2
3
- import com.hrv.mart.authlibrary.model.Auth
3
+ import com.hrv.mart.authlibrary.model.AppWriteAuth
4
4
import com.hrv.mart.authlibrary.model.AuthRequest
5
+ import com.hrv.mart.authlibrary.model.AuthWithUserType
5
6
import com.hrv.mart.authlibrary.model.UserType
6
- import com.hrv.mart.backendauth.repository.AuthRepository
7
+ import com.hrv.mart.backendauth.repository.AppWriteAuthRepository
8
+ import com.hrv.mart.backendauth.repository.AuthWithUserTypeRepository
7
9
import com.hrv.mart.backendauth.repository.KafkaRepository
8
10
import com.hrv.mart.backendauth.service.AuthService
9
11
import io.appwrite.exceptions.AppwriteException
@@ -18,28 +20,44 @@ import reactor.test.StepVerifier
18
20
import java.util.*
19
21
20
22
class AuthControllerTest {
21
- private val mockAuthRepository = mock(AuthRepository ::class .java)
23
+ private val mockAppWriteAuthRepository = mock(AppWriteAuthRepository ::class .java)
22
24
private val mockKafkaRepository = mock(KafkaRepository ::class .java)
25
+ private val mockAuthWithUserTypeRepository = mock(AuthWithUserTypeRepository ::class .java)
23
26
private val response = mock(ServerHttpResponse ::class .java)
24
27
25
- private val authService = AuthService (mockAuthRepository, mockKafkaRepository)
28
+ private val authService = AuthService (
29
+ mockAppWriteAuthRepository,
30
+ mockAuthWithUserTypeRepository,
31
+ mockKafkaRepository
32
+ )
26
33
private val authController = AuthController (authService)
27
34
28
35
@Test
29
36
fun `should return login successful message if jwt is valid` (): Unit = runBlocking {
30
37
val jwt = " A_VALID_JWT"
31
38
val userType = UserType .USER
32
39
33
- val auth = Auth (
40
+ val auth = AppWriteAuth (
41
+ userId = UUID .randomUUID().toString(),
34
42
email = " test@test.com" ,
35
43
emailVerification = true ,
36
44
createdAt = Date ().toString(),
37
45
updatedAt = Date ().toString(),
38
46
name = " Test User"
39
47
)
48
+ val authWithUserType = AuthWithUserType (
49
+ userId = auth.userId,
50
+ userType = userType
51
+ )
40
52
doReturn(Mono .just(auth))
41
- .`when `(mockAuthRepository )
53
+ .`when `(mockAppWriteAuthRepository )
42
54
.getAuthAccount(jwt)
55
+ doReturn(Mono .just(authWithUserType))
56
+ .`when `(mockAuthWithUserTypeRepository)
57
+ .findByUserId(auth.userId)
58
+ doReturn(Mono .just(true ))
59
+ .`when `(mockAuthWithUserTypeRepository)
60
+ .existsByUserId(auth.userId)
43
61
doReturn(Mono .empty<SenderResult <Void >>())
44
62
.`when `(mockKafkaRepository)
45
63
.createUser(auth.toUser())
@@ -61,7 +79,7 @@ class AuthControllerTest {
61
79
62
80
63
81
doReturn(Mono .error<AppwriteException >(AppwriteException (" JWT is invalid" )))
64
- .`when `(mockAuthRepository )
82
+ .`when `(mockAppWriteAuthRepository )
65
83
.getAuthAccount(jwt)
66
84
67
85
StepVerifier
0 commit comments