CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 14: Line 14:
* response_map.rb <----------------- 74.47% coverage
* response_map.rb <----------------- 74.47% coverage


This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.
This project aims to get all the response maps to at least a 80% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.


== Team ==
== Team ==

Revision as of 01:21, 30 November 2021

Description about project

This page is a description of Expertiza final project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:

  • In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed. The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.

The breakdown of the ResponseMap model can be found here. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:

  • review_response_map.rb <--------- 92.5% coverage
  • metareview_response_map.rb <------ 23.08% coverage
  • teammate_review_response_map.rb <- no coverage
  • response_map.rb <----------------- 74.47% coverage

This project aims to get all the response maps to at least a 80% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.

Team

  • Connor Smith (cpsmith6)
  • Abir Majumder (aamajumd)
  • Quinn Dibble (qdibble)
  • Alex Carruth (agcarrut)

Test Files Involved

There are 4 test files involved in this project:

  • review_response_map_spec.rb
  • metareview_response_map_spec.rb
  • teammate_review_response_map_spec.rb
  • response_map_spec.rb

of these files, only review_response_map_spec.rb currently exists; the rest will be added.

Methods Tested Per File

review_response_map_spec.rb

Currently this file is 92.5% covered and there are no plans to cover it further.

metareview_response_map_spec.rb

The functions for metareview_response_map.rb that will be tested are:

get_all_versions

This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.

# return all the versions available for a response map.
  # a person who is doing meta review has to be able to see all the versions of review.
  def get_all_versions
    if self.review_mapping.response
      @sorted_array = []
      @prev = Response.all
      @prev.each do |element|
        @sorted_array << element if element.map_id == self.review_mapping.map_id
      end
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num
                                                                  m1.version_num <=> m2.version_num
                                                                else
                                                                  m1.version_num ? -1 : 1
                                                                end }
      # return all the lists in ascending order.
      @sorted
    end
  end

contributor

Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.

# First, find the "ReviewResponseMap" to be metareviewed;
  # Second, find the team in the "ReviewResponseMap" record.
  def contributor
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)
    AssignmentTeam.find(team_review_map.reviewee_id)
  end

questionnaire

Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.

def questionnaire
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')
end

get_title

Returns string "Metareview". We will test if this string is the same as typed out.

def get_title
    "Metareview"
end

exports

This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.

  def self.export(csv, parent_id, _options)
    mappings = Assignment.find(parent_id).metareview_mappings
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }
    mappings.each do |map|
      csv << [
        map.review_mapping.reviewee.name,
        map.reviewee.name,
        map.reviewer.name
      ]
    end
  end

export_fields

Takes a parameter called "_options" that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.

  def self.export_fields(_options)
    fields = ["contributor", "reviewed by", "metareviewed by"]
    fields
  end

import

This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.

email

This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.

  def email(defn, _participant, assignment)
    defn[:body][:type] = "Metareview"
    reviewee_user = Participant.find(reviewee_id)
    defn[:body][:obj_name] = assignment.name
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname
    defn[:to] = User.find(reviewee_user.user_id).email
    Mailer.sync_message(defn).deliver
  end

teammate_review_response_map_spec.rb

The functions for teammate_review_response_map.rb that will be tested are:

questionnaire

This function searches for a TeammateReviewQuestionnaire object and returns it.

  def questionnaire
    self.assignment.questionnaires.find_by(type: 'TeammateReviewQuestionnaire')
  end

get_title

This function returns the string "Teammate Review".

  def get_title
    "Teammate Review"
  end

teammate_response_report

This function returns the teammate response report given the reviewer ID.

  def self.teammate_response_report(id)
    TeammateReviewResponseMap.select("DISTINCT reviewer_id").where("reviewed_object_id = ?", id)
  end

email

This function sends a notification email to a student who has been reviewed by their teammate.

  # Send Teammate Review Emails
  # Refactored from email method in response.rb
  def email(defn, participant, assignment)
    defn[:body][:type] = "Teammate Review"
    participant = AssignmentParticipant.find(reviewee_id)
    topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)
    defn[:body][:obj_name] = assignment.name
    user = User.find(participant.user_id)
    defn[:body][:first_name] = user.fullname
    defn[:to] = user.email
    Mailer.sync_message(defn).deliver
  end

response_map_spec.rb

The functions for response_map.rb that will be tested are:

self.assessments_for(team)

Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses.

  # return latest versions of the responses
  def self.assessments_for(team)
    responses = []
    # stime = Time.now
    if team
      @array_sort = []
      @sort_to = []
      maps = where(reviewee_id: team.id)
      maps.each do |map|
        next if map.response.empty?
        @all_resp = Response.where(map_id: map.map_id).last
        if map.type.eql?('ReviewResponseMap')
          # If its ReviewResponseMap then only consider those response which are submitted.
          @array_sort << @all_resp if @all_resp.is_submitted
        else
          @array_sort << @all_resp
        end
        # sort all versions in descending order and get the latest one.
        # @sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num <=> m1.version_num : (m1.version_num ? -1 : 1) }
        @sort_to = @array_sort.sort # { |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at <=> m1.updated_at : (m1.version_num ? -1 : 1) }
        responses << @sort_to[0] unless @sort_to[0].nil?
        @array_sort.clear
        @sort_to.clear
      end
      responses = responses.sort {|a, b| a.map.reviewer.fullname <=> b.map.reviewer.fullname }
    end
    responses
  end

comparator

Compares two Responses version numbers and returns a -1,0, or 1 depending on which version number is greater. If there is no version number for the first response, -1 is returned, otherwise 1 is returned.

  def comparator(m1, m2)
    if m1.version_num and m2.version_num
      m2.version_num <=> m1.version_num
    elsif m1.version_num
      -1
    else
      1
    end
  end

self.reviewer_assessments_for(team, reviewer)

Gets the Responses for a team reviewed by a specific reviewer and returns the latest response.

  # return latest versions of the response given by reviewer
  def self.reviewer_assessments_for(team, reviewer)
    # get_reviewer may return an AssignmentParticipant or an AssignmentTeam
    map = where(reviewee_id: team.id, reviewer_id: reviewer.get_reviewer.id)
    Response.where(map_id: map).sort {|m1, m2| self.comparator(m1, m2) }[0]
  end

metareviewed_by?

Returns whether the Response Map has been metareviewed

  # Evaluates whether this response_map was metareviewed by metareviewer
  # @param[in] metareviewer AssignmentParticipant object
  def metareviewed_by?(metareviewer)
    MetareviewResponseMap.where(reviewee_id: self.reviewer.id, reviewer_id: metareviewer.id, reviewed_object_id: self.id).count > 0
  end

assign_metareviewer

This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).

  # Assigns a metareviewer to this review (response)
  # @param[in] metareviewer AssignmentParticipant object
  def assign_metareviewer(metareviewer)
    MetareviewResponseMap.create(reviewed_object_id: self.id,
                                 reviewer_id: metareviewer.id, reviewee_id: reviewer.id)
  end

find_team_member

This function returns the team that the reviewer is part of.

  def find_team_member
    # ACS Have metareviews done for all teams
    if self.type.to_s == "MetareviewResponseMap"
        review_mapping = ResponseMap.find_by(id: map.reviewed_object_id)
        team = AssignmentTeam.find_by(id: review_mapping.reviewee_id)
    else
        team = AssignmentTeam.find(self.reviewee_id)
    end
  end

Running Tests

  rspec ./spec/models/<test file name>