@@ -9,21 +9,22 @@ import com.watcourses.wat_courses.proto.CreateStudentProfileRequest
9
9
import com.watcourses.wat_courses.proto.Schedule
10
10
import com.watcourses.wat_courses.proto.StudentProfile
11
11
import com.watcourses.wat_courses.proto.Term
12
+ import com.watcourses.wat_courses.utils.UserSessionFactory
12
13
import org.assertj.core.api.Assertions.assertThat
13
14
import org.assertj.core.api.Assertions.assertThatThrownBy
15
+ import org.junit.jupiter.api.BeforeEach
14
16
import org.junit.jupiter.api.Test
17
+ import org.mockito.BDDMockito
15
18
import org.springframework.beans.factory.annotation.Autowired
16
19
import org.springframework.boot.test.context.SpringBootTest
20
+ import org.springframework.core.io.support.PathMatchingResourcePatternResolver
17
21
import org.springframework.test.context.ActiveProfiles
18
22
import javax.transaction.Transactional
19
23
20
24
@Transactional
21
25
@SpringBootTest
22
26
@ActiveProfiles(" test" )
23
27
class StudentProfileApiTests {
24
- @Autowired
25
- private lateinit var studentProfileApi: StudentProfileApi
26
-
27
28
@Autowired
28
29
private lateinit var dbStudentProfileRepo: DbStudentProfileRepo
29
30
@@ -33,11 +34,19 @@ class StudentProfileApiTests {
33
34
@Autowired
34
35
private lateinit var utils: Utils
35
36
37
+ @Autowired
38
+ private lateinit var userSessionFactory: UserSessionFactory
39
+
40
+ @BeforeEach
41
+ fun setup () {
42
+ utils.createCourse(* SAMPLE_PROFILE .allCourseCodes().toTypedArray())
43
+ }
44
+
36
45
@Test
37
- fun `create student profile` () {
38
- utils.createCourses( SAMPLE_PROFILE .allCourseCodes() )
39
- val studentProfile = studentProfileApi.createStudentProfile (
40
- CreateStudentProfileRequest (
46
+ fun `guest create student profile` () {
47
+ val guest = userSessionFactory.guest( )
48
+ val studentProfile = guest.createDefaultStudentProfile (
49
+ CreateDefaultStudentProfileRequest (
41
50
degrees = listOf (" Software Engineering" ),
42
51
startingYear = 2019 ,
43
52
coopStream = CoopStream .STREAM_8 ,
@@ -48,37 +57,29 @@ class StudentProfileApiTests {
48
57
}
49
58
50
59
@Test
51
- fun `create default student profile` () {
52
- utils.createCourses(SAMPLE_PROFILE .allCourseCodes())
60
+ fun `registered user can create default student profile` () {
53
61
val ownerEmail
= " [email protected] "
54
- utils.createUserWithEmail(ownerEmail)
55
- val profileWithOwnerEmail = SAMPLE_PROFILE .copy(ownerEmail = ownerEmail)
56
- val studentProfile = studentProfileApi.createDefaultStudentProfile(
62
+ val user = userSessionFactory.register(email = ownerEmail)
63
+ val studentProfile = user.createDefaultStudentProfile(
57
64
CreateDefaultStudentProfileRequest (
58
65
degrees = listOf (" Software Engineering" ),
59
66
startingYear = 2019 ,
60
- coopStream = CoopStream .STREAM_8 ,
61
- ownerEmail = ownerEmail,
67
+ coopStream = CoopStream .STREAM_8
62
68
)
63
69
)
70
+
71
+ val profileWithOwnerEmail = SAMPLE_PROFILE .copy(ownerEmail = ownerEmail)
64
72
assertThat(studentProfile).isEqualTo(profileWithOwnerEmail)
65
73
assertThat(dbStudentProfileRepo.findAll().single()!! .toProto()).isEqualTo(profileWithOwnerEmail)
66
74
assertThat(dbUserRepo.findByEmail(ownerEmail)!! .studentProfile!! .toProto()).isEqualTo(profileWithOwnerEmail)
67
75
}
68
76
69
77
@Test
70
78
fun `create or update student profile` () {
71
- utils.createCourses(SAMPLE_PROFILE .allCourseCodes())
72
- assertThatThrownBy { studentProfileApi.createOrUpdateStudentProfile(SAMPLE_PROFILE ) }
73
- .hasMessageContaining(" No owner provided" )
74
-
75
79
val ownerEmail
= " [email protected] "
76
80
val profileWithOwnerEmail = SAMPLE_PROFILE .copy(ownerEmail = ownerEmail)
77
- assertThatThrownBy { studentProfileApi.createOrUpdateStudentProfile(profileWithOwnerEmail) }
78
- .hasMessageContaining(" User with email $ownerEmail is not found" )
79
-
80
- utils.createUserWithEmail(ownerEmail)
81
- var studentProfile = studentProfileApi.createOrUpdateStudentProfile(profileWithOwnerEmail)
81
+ val user = userSessionFactory.register(email = ownerEmail)
82
+ var studentProfile = user.createOrUpdateStudentProfile(profileWithOwnerEmail)
82
83
assertThat(studentProfile).isEqualTo(profileWithOwnerEmail)
83
84
assertThat(dbStudentProfileRepo.findAll().single()!! .toProto()).isEqualTo(profileWithOwnerEmail)
84
85
assertThat(dbUserRepo.findByEmail(ownerEmail)!! .studentProfile!! .toProto()).isEqualTo(profileWithOwnerEmail)
@@ -120,8 +121,8 @@ class StudentProfileApiTests {
120
121
degrees = listOf (" Bug Engineering" ),
121
122
shortList = listOf (" CS 2077" , " SCI 238" ),
122
123
)
123
- utils.createCourses( updatedProfile.allCourseCodes())
124
- studentProfile = studentProfileApi .createOrUpdateStudentProfile(updatedProfile)
124
+ utils.createCourse( * updatedProfile.allCourseCodes().toTypedArray ())
125
+ studentProfile = user .createOrUpdateStudentProfile(updatedProfile)
125
126
assertThat(studentProfile).isEqualTo(updatedProfile)
126
127
assertThat(dbStudentProfileRepo.findAll().single()!! .toProto()).isEqualTo(updatedProfile)
127
128
assertThat(dbUserRepo.findByEmail(ownerEmail)!! .studentProfile!! .toProto()).isEqualTo(updatedProfile)
0 commit comments