Untitled

 avatar
unknown
plain_text
2 years ago
2.8 kB
6
Indexable
package pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.service

import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.test.context.TestConfiguration
import pt.ulisboa.tecnico.socialsoftware.tutor.BeanConfiguration
import pt.ulisboa.tecnico.socialsoftware.tutor.SpockTest
import pt.ulisboa.tecnico.socialsoftware.tutor.exceptions.ErrorMessage
import pt.ulisboa.tecnico.socialsoftware.tutor.exceptions.TutorException
import pt.ulisboa.tecnico.socialsoftware.tutor.user.domain.Teacher
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Course
import pt.ulisboa.tecnico.socialsoftware.tutor.execution.domain.CourseExecution
import spock.lang.Unroll


@DataJpaTest
class RemoveServiceTest extends SpockTest {
    def teacher
    def course

    def setup() {
        teacher = new Teacher(USER_1_NAME, false)
        userRepository.save(teacher)
        course = new Course(COURSE_1_NAME, Course.Type.EXTERNAL)
        courseRepository.save(course)


    }

    def createCourseExecution(acronym, academicTerm, date) {
        def courseExecution = new CourseExecution(course, acronym, academicTerm, course.getType(), date)
        courseExecutionRepository.save(courseExecution)
        return courseExecution
    }

    def "remove a dashboard"() {
        given: "4 course executions"
        def courseExecution1 = createCourseExecution(COURSE_1_ACRONYM, "1 Semestre 2017/2018", LOCAL_DATE_BEFORE)
        def courseExecution2 = createCourseExecution(COURSE_2_ACRONYM, "1 Semestre 2018/2019", LOCAL_DATE_YESTERDAY)
        def courseExecution3 = createCourseExecution("C32", "1 Semestre 2019/2020", LOCAL_DATE_TODAY)
        def courseExecution4 = createCourseExecution("C42", "1 Semestre 2020/2021", LOCAL_DATE_TOMORROW)

        and: "the course executions are associated with a teacher"
        teacher.addCourse(courseExecution1)
        teacher.addCourse(courseExecution2)
        teacher.addCourse(courseExecution3)
        teacher.addCourse(courseExecution4)

        and: "the TeacherDashboardDto's are created"
        teacherDashboardService.getTeacherDashboard(courseExecution1.getId(), teacher.getId())
        def teacherDashboard1 = teacherDashboardRepository.findAll().get(0)

        when: "the user removes the dashboard"
        teacherDashboardService.removeTeacherDashboard(teacherDashboard1.getId())

        then: "the dashboard is removed"
        teacherDashboardRepository.findAll().size() == 0L
        studentStatsRepository.findAll().size() == 0L
        teacher.getDashboards().size() == 0L
    }

    @TestConfiguration
    static class LocalBeanConfiguration extends BeanConfiguration {}
}
Editor is loading...