CSC/ECE 517 Fall 2021 - E2133. Write tests for popup controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

The goal of this project is to add unit testing for the PopupController to raise statement coverage above 60%. See the Test Outline section for specifics of our work.

Project Introduction

The PopupController is responsible for preparing data that will be displayed in popup views. To render the data, which mostly concerns assignments, the controller makes many accesses to database tables such as Response, ResponseMap, Question, Questionnaire, Answer, and Participant. The previous team implemented some of the test cases to improve the coverage. The previous work test coverage was 96%. However, their test cases followed integration testing methodologies which were not consistent with Unit testing. We will be implementing Unit testing while retaining the current coverage.

Team

Yi Qiu (mentor)

  • Sayali Parab, snparab1704
  • Rageeni Sah, ragesah
  • Priya Jakhar, priyajakhar

Files Involved

popup_controller.rb

popup_controller_spec.rb

Running Tests

What we need to do is to set up the environment and complete the 'popup_controller_spec.rb' to finish the unit tests for popup controller. This rspec test file can be run by calling the following code:

  rspec spec/controllers/popup_controller_spec.rb

What needs to be done

1. Write RSpec unit test cases to make the statement coverage above 90%.

2. Cover as many boundary cases and the core functionality for all popup controller actions.


Test Plan

In total, we wrote tests to cover all 6 methods in the popup controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).


Popup Controller Methods

The code of the controller can be found here. The methods are:

  • action_allowed?
  • author_feedback_popup
  • team_users_popup
  • view_review_scores_popup
  • reviewer_details_popup
  • self_review_popup

Mock Models

Test Frame

Since it's unit testing, we need to test functional logic.

1. self_review_popup - This action can be called from "response_report" by clicking reviewer names from the instructor's end. In this action for the given response id maximum score is displayed. If the response id is nil maximum score is set to 5, i.e., if a question response is not reviewed then the system automatically assigns five as the maximum score for the response.

Code snippet:

describe '#self_review_popup' do
    context "when current user is the participant" do
      it "render page successfully as Instructor to get maximum_score " do
        question1 = double(:question1, questionnaire_id: 1)
        questionnaire1 = double(:questionnaire1, min_question_score: 1, max_question_score: 3, name: 'Test questionnaire')
        answer1 = double('Answer', question_id: 1)
        response1 = double('response1', response_id: 1, responses: "this is test response")
        allow(Answer).to receive_message_chain(:where, :first).with(response_id: 1).with(no_args).and_return(answer1)
        allow(Question).to receive(:find).with(1).and_return(question1)
        allow(Questionnaire).to receive(:find).and_return(questionnaire1)
        allow(Answer).to receive(:where).with("1").and_return(answer1)
        allow(Response).to receive_message_chain(:find, :average_score).with("1").with(no_args).and_return(response1)
        allow(Response).to receive_message_chain(:find, :aggregate_questionnaire_score).with("1").with(no_args).and_return(response1)
        allow(Response).to receive_message_chain(:find, :maximum_score).with("1").with(no_args).and_return(response1)
        params = {response_id: 1, user_fullname: questionnaire1.name}
        session = {user: instructor}
        get :self_review_popup, params, session
        expect(@response).to have_http_status(200)
      end
    end
  end

2. reviewer_details_popup - This action can be called from response_report by clicking reviewer names from the instructor's end. This action is responsible to fetch reviewer details: full name, user id, email, and handle.

Code snippet:

describe '#reviewer_details_popup' do
    render_views
    it "render reviewer_details_popup page successfully" do
      participant = double(:participant, user_id: 1)
      user = double(:user, fullname: "Test User", name: "Test", email: "test@gmail.com", handle: 1)
      allow(Participant).to receive(:find).with("1").and_return(participant)
      allow(User).to receive(:find).with(participant.user_id).and_return(user)
      params = {id: 1, assignment_id: 1}
      session = {user: instructor}
      get :reviewer_details_popup, params, session
      expect(@response).to have_http_status(200)
      expect(user.fullname).to eq("Test User")
      expect(user.name).to eq("Test")
      expect(user.email).to eq("test@gmail.com")
      expect(user.handle).to eq(1)
    end
  end

2. team_users_popup - This action can be called from _review_report by clicking the team reviewed link from the instructor's end. This action is responsible to fetch team details that have reviewed the assignment. details: team name, team users, max score round, total possible rounds, comments, etc.

Findings:

team_users_popup

team_users_popup.html

Params: id id2

Responses: @sum @team @assignment @team_users @reviewer_id @similar_assignments

Used variables in HTML view: @team @team_users @ip @assignment @reviewer_id response_round_ , response_id_round_ , scores_round_ , Max_score_round_ , Total_percentage_round_ , sum_round_ , total_possible_round_

Code snippet:

2. view_review_scores_popup- This action can be called from _review_report by clicking the summary link from the instructor's end. This action is responsible to fetch the details of the scores that have been received for the assignment which includes further details such as the course, assignment, questions, responses, the team responsible for the review, review summary, etc.

Findings:

View_review_scores_popup.html

Params: reviewer_id Assignment_id

Response: @review_final_versions @reviews

Used variables in HTML view: @review_final_versions keys questionnaire_id response_ids

Test cases: Reviewer_id is null Assignment_id is null Assignment.vary_by_topic true - correct results Assignment.vary_by_topic false - correct results @review_final_versions - has questionnaire_id @review_final_versions - has response_ids

Code snippet:

Results

The total coverage of the test is 63.29%, meeting our minimum coverage requirement.

Related Links

The main repository can be found here

The forked git repository for this project can be found here

Conclusion