Untitled

 avatar
unknown
plain_text
2 years ago
4.7 kB
5
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.user.domain.Teacher
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Course
import pt.ulisboa.tecnico.socialsoftware.tutor.execution.domain.CourseExecution


@DataJpaTest
class NewTeacherDashboardServicesTest 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 "check if the teacher dashboard only mantains statistics of 3 course executions"() {
        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())

        when: "when the dashboards are accessed"
        def teacherDashboard = teacherDashboardRepository.findAll().get(0)

        then: "the teacher dashboard onlyhave statistics of 3 years"
        teacherDashboard.getQuestionStats().size() == 3

        and: "the question stats are empty"
        teacherDashboard.getQuestionStats().get(0).getNumAvailable() == 0
        teacherDashboard.getQuestionStats().get(0).getAnsweredQuestionsUnique() == 0
        teacherDashboard.getQuestionStats().get(0).getAverageQuestionsAnswered() == 0

        teacherDashboard.getQuestionStats().get(1).getNumAvailable() == 0
        teacherDashboard.getQuestionStats().get(1).getAnsweredQuestionsUnique() == 0
        teacherDashboard.getQuestionStats().get(1).getAverageQuestionsAnswered() == 0

        teacherDashboard.getQuestionStats().get(2).getNumAvailable() == 0
        teacherDashboard.getQuestionStats().get(2).getAnsweredQuestionsUnique() == 0
        teacherDashboard.getQuestionStats().get(2).getAverageQuestionsAnswered() == 0

        and: "the element is in the database"
        teacherDashboardRepository.count() == 1
    }

    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
        questionStatsRepository.findAll().size() == 0L
        teacher.getDashboards().size() == 0L
    }


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