Untitled

 avatar
unknown
plain_text
2 years ago
3.4 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.question.domain.Question
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Course
import pt.ulisboa.tecnico.socialsoftware.tutor.user.domain.Teacher
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.TeacherDashboard
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.QuestionStats


@DataJpaTest
class CreateQuestionStatsTest extends SpockTest {
    def teacher
    def teacherDashboard

    def setup() {
        createExternalCourseAndExecution()
        teacher = new Teacher(USER_1_NAME, false)
        teacherDashboard = new TeacherDashboard(externalCourseExecution, teacher)

    }

    def "test with zero questions"() {
        when:
        def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
        questionStats.update()

        then:
        questionStats.getNumAvailable() == 0
    }

    def "Creation of one question available"() {
        given:
        def course = new Course(COURSE_2_NAME, Course.Type.TECNICO)
        courseRepository.save(course)

        Question question = new Question()
        question.setKey(1)
        question.setStatus(Question.Status.AVAILABLE)
        question.setCourse(externalCourse)
        question.setTitle(QUESTION_1_TITLE)

        course.addQuestion(question)
        externalCourseExecution.setCourse(course)

        when:
        def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
        questionStats.update()

        then:
        questionStats.getCourseExecution() == externalCourseExecution
        questionStats.getNumAvailable() == 1

        //verificar isto
        and: "disable one test and see if getNum update"
        question.setStatus(Question.Status.DISABLED)
        questionStats.update()
        questionStats.getNumAvailable() == 0
    }

    def "Creation of two questions available"() {
        given:
        def course = new Course(COURSE_2_NAME, Course.Type.TECNICO)
        courseRepository.save(course)

        Question question = new Question()
        question.setKey(1)
        question.setStatus(Question.Status.AVAILABLE)
        question.setCourse(externalCourse)
        question.setTitle(QUESTION_1_TITLE)
        Question question2 = new Question()
        question2.setKey(2)
        question2.setStatus(Question.Status.AVAILABLE)
        question2.setCourse(externalCourse)
        question2.setTitle(QUESTION_2_TITLE)

        course.addQuestion(question)
        course.addQuestion(question2)
        externalCourseExecution.setCourse(course)

        when:
        def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
        questionStats.update()

        then:
        questionStats.getCourseExecution() == externalCourseExecution
        questionStats.getNumAvailable() == 2
    }


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