Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

강의 이수 변경사항 테스트코드 작성 #524

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ data class LectureResponse(
email = student.user!!.email,
name = student.user!!.name,
grade = student.grade,
classNumber = student.number,
classNumber = student.classRoom,
number = student.number,
phoneNumber = student.user!!.phoneNumber,
school = student.club.school.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class LectureServiceImplTest : BehaviorSpec({
val completeDate = LocalDate.MAX
val startTime = LocalTime.MIN
val endTime = LocalTime.MAX
val essentialComplete = false

val lectureDate = fixture<LectureDate> {
property(LectureDate::completeDate) { completeDate }
Expand Down Expand Up @@ -524,6 +525,7 @@ class LectureServiceImplTest : BehaviorSpec({
property(Lecture::division) { division }
property(Lecture::line) { line }
property(Lecture::department) { department }
property(Lecture::essentialComplete) { essentialComplete }
}

val lectureDateResponse = fixture<LectureDateResponse> {
Expand Down Expand Up @@ -557,6 +559,7 @@ class LectureServiceImplTest : BehaviorSpec({
property(LectureDetailsResponse::locationDetails) { details }
property(LectureDetailsResponse::locationX) { x }
property(LectureDetailsResponse::locationY) { y }
property(LectureDetailsResponse::essentialComplete) { essentialComplete }
}

every { userUtil.queryCurrentUser() } returns user
Expand Down Expand Up @@ -586,7 +589,7 @@ class LectureServiceImplTest : BehaviorSpec({
}
}

//signUpLecture 테스트 코드
// signUpLecture 테스트 코드
Given("Lecture id가 주어질 때") {

val userId = UUID.randomUUID()
Expand Down Expand Up @@ -1108,6 +1111,7 @@ class LectureServiceImplTest : BehaviorSpec({
// queryAllSignedUpLectures 테스트 코드
Given("lecture id가 주어질 때") {
val studentUserId = UUID.randomUUID()

val studentEmail = "email"
val studentName = "name"
val studentPhoneNumber = "phoneNumber"
Expand All @@ -1117,13 +1121,13 @@ class LectureServiceImplTest : BehaviorSpec({
property(User::id) { studentUserId }
property(User::name) { studentName }
property(User::email) { studentEmail }
property(User::phoneNumber) { studentPhoneNumber}
property(User::phoneNumber) { studentPhoneNumber }
}
val studentUserB = fixture<User>{
property(User::id) { studentUserId }
property(User::name) { studentName }
property(User::email) { studentEmail }
property(User::phoneNumber) { studentPhoneNumber}
property(User::phoneNumber) { studentPhoneNumber }
}

val school = fixture<School> {
Expand Down Expand Up @@ -1285,6 +1289,83 @@ class LectureServiceImplTest : BehaviorSpec({

}

// querySignedUpStudentDetails 테스트 코드
Given("Lecture id와 student id가 주어질 때") {
val email = "email"
val name = "name"
val phoneNumber = "01000000000"
val studentUser = fixture<User> {
property(User::email) { email }
property(User::name) { name }
property(User::phoneNumber) { phoneNumber }
}

val schoolName = "school"
val school = fixture<School> {
property(School::name) { schoolName }
}

val clubName = "club"
val club = fixture<Club> {
property(Club::name) { clubName }
property(Club::school) { school }
}

val studentId = UUID.randomUUID()
val cohort = 1
val grade = 1
val classRoom = 1
val number = 1

val student = fixture<Student> {
property(Student::id) { studentId }
property(Student::user) { studentUser }
property(Student::club) { club }
property(Student::grade) { grade }
property(Student::classRoom) { classRoom }
property(Student::number) { number }
property(Student::cohort) { cohort }
}

val lectureId = UUID.randomUUID()
val lecture = fixture<Lecture> {
property(Lecture::id) { lectureId }
}

val completeStatus = CompleteStatus.NOT_COMPLETED_YET

val registeredLecture = fixture<RegisteredLecture> {
property(RegisteredLecture::lecture) { lecture }
property(RegisteredLecture::student) { student }
property(RegisteredLecture::completeStatus) { completeStatus }
}

val currentCompletedDate = LocalDate.MIN

val response = LectureResponse.signedUpDetailOf(student, completeStatus, currentCompletedDate)

every { studentRepository.findByIdOrNull(studentId) } returns student
every { registeredLectureRepository.findByLectureIdAndStudentId(lectureId, studentId) } returns registeredLecture
every { lectureDateRepository.findByCurrentCompletedDate(lectureId) } returns currentCompletedDate

When("강의에 신청한 학생의 상세 정보를 조회하면") {
val result = lectureServiceImpl.querySignedUpStudentDetails(lectureId, studentId)
Then("result와 response가 같아야 한다") {
result shouldBe response
}
}

When("학생이 해당 강의를 신청하지 않았다면") {
every { registeredLectureRepository.findByLectureIdAndStudentId(lectureId, studentId) } returns null

Then("UnSignedUpLectureException이 발생해야 한다.") {
shouldThrow<UnSignedUpLectureException> {
lectureServiceImpl.querySignedUpStudentDetails(lectureId, studentId)
}
}
}
}

// updateLectureCompleteStatus 테스트 코드
Given("lecture id와 student id, isComplete가 주어질 때"){
val lectureId = UUID.randomUUID()
Expand Down Expand Up @@ -1320,6 +1401,7 @@ class LectureServiceImplTest : BehaviorSpec({
property(Student::club) { clubA }
property(Student::grade) { 1 }
}
val students = listOf(student)

val teacherUser = fixture<User> {
property(User::authority) { Authority.ROLE_TEACHER }
Expand Down Expand Up @@ -1370,22 +1452,23 @@ class LectureServiceImplTest : BehaviorSpec({
property(RegisteredLecture::student) { student }
property(RegisteredLecture::completeStatus) { CompleteStatus.COMPLETED_IN_1RD }
}
val registeredLectures = listOf(updatedRegisteredLecture)

every { studentRepository.findByIdIn(studentIds) } returns students
every { teacherRepository.findByUser(teacherUser) } returns teacher
every { bbozzakRepository.findByUser(bbozzakUser) } returns bbozzak
every { studentRepository.findByIdOrNull(studentId) } returns student
every { lectureRepository.findByIdOrNull(lectureId) } returns lecture

every { registeredLectureRepository.findByLectureIdAndStudentId(lectureId, studentId) } returns registeredLecture
every { registeredLectureRepository.save(any()) } returns updatedRegisteredLecture
every { registeredLectureRepository.findByStudentAndLecture(student, lecture) } returns registeredLecture
every { registeredLectureRepository.saveAll(any<List<RegisteredLecture>>()) } returns registeredLectures

When("현재 로그인 한 유저가 Bbozzak이나 Teacher이고, 학생과 같은 동아리에 소속되어있으면"){
every { userUtil.queryCurrentUser() } returns teacherUser

lectureServiceImpl.updateLectureCompleteStatus(lectureId, studentIds)

Then("registerdLecture 가 저장이 되어야 한다.") {
verify(exactly = 1) { registeredLectureRepository.save(any()) }
verify(exactly = 1) { registeredLectureRepository.saveAll(any<List<RegisteredLecture>>()) }
}
}

Expand All @@ -1405,7 +1488,7 @@ class LectureServiceImplTest : BehaviorSpec({
lectureServiceImpl.updateLectureCompleteStatus(lectureId, studentIds)

Then("registerdLecture 가 저장이 되어야 한다.") {
verify(exactly = 1) { registeredLectureRepository.save(any()) }
verify(exactly = 1) { registeredLectureRepository.saveAll(any<List<RegisteredLecture>>()) }
}
}

Expand All @@ -1415,7 +1498,7 @@ class LectureServiceImplTest : BehaviorSpec({
lectureServiceImpl.updateLectureCompleteStatus(lectureId, studentIds)

Then("registerdLecture 가 저장이 되어야 한다.") {
verify(exactly = 1) { registeredLectureRepository.save(any()) }
verify(exactly = 1) { registeredLectureRepository.saveAll(any<List<RegisteredLecture>>()) }
}
}

Expand Down
Loading