CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files

From Expertiza_Wiki
Jump to navigation Jump to search

Relevant links

Github Repo : Repository

About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students. Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.

Problem statement and background

There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller. They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team

Approach Chosen & Why?

In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.

Implementation

teams_controller.rb

Scenario 1: Create teams with random names

  1. After checking for the team type and team size, call function to randomize the teams
  2. Print message "Random teams have been successfully created."
  3. Redirect to list of teams

Scenario 2: List the teams assignment wise or course wise

  1. Check if the current list to display is at assignment or course level
  2. Display the teams according to the level

Scenario 3: Create a new empty team

  1. Check if a team already exists with the same name
  2. If it doesn’t, create a new team with a name
  3. If a team is created, print "The team <team_name> has been successfully created."
  4. Redirect to list team page
  5. If error is there, fail to create a new team and redirect to new team form page

Scenario 4: Update an existing team

  1. Check if a team with new suggested name already exists
  2. If it doesn’t, update and save the new team name
  3. Print "The team <new_team_name> has been successfully updated."
  4. Redirect to list team page
  5. If error is there, fail to update team and redirect to edit team form page

Scenario 5: Delete a team

  1. Check if there is a team in waitlist for the topic that the team to be deleted holds
  2. If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.
  3. Delete the team’s records in team, teams_users and sign_up_team tables
  4. Print “"The team <team_name> has been successfully deleted."

Scenario 6: Copy existing teams from a course down to an assignment

  1. Find the course that the assignment belongs to
  2. If a course for the assignment doesn’t exist, give the error message "No course was found for this assignment."
  3. Otherwise fetch all the teams that exist in the course
  4. If no teams exist, give the error message "No teams were found when trying to inherit."
  5. Else copy all teams and assign them the new assignment id

Scenario 7: Copy existing team from assignment to course

  1. Find the assignment id to which the team belongs
  2. Find the course to which the assignment belongs
  3. If assignment doesn’t belong to a course, give the error message "This assignment is not <assignment_name> with a course."
  4. Otherwise copy team from assignment and assign it the course id
  5. Print success message "The team <team_name> was successfully copied to <course_name>"
  6. Redirect to list page

teams_users_controller.rb

Scenario 1: Add new user to the selected team.

  1. Given user is not defined: When given user is defined, link is provided to create the user.
  2. Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, "Maximum users reached" notification is flashed.
  3. Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, "Maximum users reached" notification is flashed.

Scenario 2: Delete user from the selected team.

  1. User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.

student_teams_controller.rb

The student teams controller is used to add students to the team, update team name and remove participants from team.

Scenario 1: Set the variables for view

  1. If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs, @current_due_date, @users_on_waiting_list, @teammate_review_allowed
  2. If the current user is not student or the User Ids do not match, then the return from method.

describe '#view' do
   it 'sets the student' do
     allow(AssignmentParticipant).to receive(:find).with('12345').and_return student
     allow(student_teams_controller).to receive(:current_user_id?)
     allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')
     allow(student).to receive(:user_id)
     student_teams_controller.view
   end
 end

Scenario 2: Create Student teams

  1. If team name is empty, flash an error message saying "Team name missing while creating team" and redirect to view_student_teams_path
  2. If team name is not empty and team name already in use, "Team name being created was already in use" and redirect to view_student_teams_path
  3. If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.

  describe 'POST #create' do
   before(:each) do
     @student = AssignmentParticipant.new
   end
   context 'when create Assignment team' do
     it 'flash notice when team is empty' do
       allow(AssignmentTeam).to receive(:where).with(name: , parent_id: 1).and_return(nil)
       allow(AssignmentParticipant).to receive(:find).and_return(participant)
       allow(student1).to receive(:user_id)
       session = {user:student1}
       params = {
         student_id:1,
         team:{
           name:'test'
         }
       }
       result= post :create, params, session
       expect(result.status).to eq 302
     end
   end
   context "create team" do
     it "saves the team" do
       allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)
       allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)
       allow(AssignmentParticipant).to receive(:find).and_return(participant)
       allow(student1).to receive(:user_id)
       allow(team7).to receive(:save).and_return(true)
       session = {user:student1}
       params = {
         student_id:1,
         team:{
           name:'test'
         }
       }
       result= post :create, params, session
       expect(result.status).to eq(302)
     end
   end
   context "name already in use" do
     it "flash notice" do
       allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)
       allow(AssignmentParticipant).to receive(:find).and_return(participant)
       allow(student1).to receive(:user_id)
       session = {user:student1}
       params = {
         student_id:1,
         team:{
           name:'test'
         }
       }
       result= post :create, params, session
       expect(result.status).to eq 302
     end
   end
 end

Scenario 3: Update team name:

  1. Find the team that should be updated.
  2. If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path
  3. If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path
  4. If there are more than one team, then show the following error message "Team name being updated to was already in use" and redirect to edit_student_teams_path.

describe '#update' do

   context 'update team name' do
     it 'update name' do
       allow(AssignmentParticipant).to receive(:find).and_return(participant)
       allow(AssignmentTeam).to receive(:find).and_return(team7)
       allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)
       allow(team7).to receive(:destroy_all)
       allow(student1).to receive(save).and_return(true)
       session = {user:student1}
       params = {
         student_id:1,
         team:{
           name:'test'
         }
       }
       result= post :update, params, session
       expect(result.status).to eq(302)
     end
   end
 end

Scenario 4: Remove team participants

  1. Find the user who has to be removed.
  2. Remove the user from team.
  3. If the team does not have any more participants, remove the team record from database.
  4. If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist
  5. Remove all the invitations sent and redirect to view_student_teams_path.

describe '#remove_participant' do
  context 'remove team user' do
    it 'remove user' do
   allow(AssignmentParticipant).to receive(:find).and_return(participant)
   allow(TeamsUser).to receive(:where).and_return(team_user1)
   allow(team_user1).to receive(:destroy_all)
   allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)
   allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)
   session = {user:student1}
   params = {
     team_id:1,
     user_id:1,
     student_id:1,
     team:{
       name:'test'
     }
   }
   result = post :remove_participant, params, session
   expect(result.status).to eq 302
   # expect(result).to redirect_to(view_student_teams_path(:student_id => 1))
    end
  end
 end

join_team_requests_controller.rb

P = Pending status
D = Denied status
A = Accepted status

Scenario 1: Creating a team request

  1. If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .
  2. If error occurs, flash error message.

Scenario 2: Decline a team request.

  1. After verifying team_user_id, change @join_team_request.status = 'D' .
  2. Redirect to view_student_teams_path

Scenario 3: Check team status.

  1. If team if full. Print error message "This team is full." .
  2. If team is not empty, print message "You are already a member of this team."

Scenario 1: Creating new advertisement for partners.

  1. We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.

Scenario 2: Updating the advertisement.

  1. We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.
  2. Update Unsuccessful : If there is an error during update then the following error message is thrown "An error occurred and your advertisement was not updated." and edit page is rendered.
  3. Update Successful : If the advertisement is successfully updated in the database then the "Your advertisement was successfully updated!" message is prompted and the user is redirected to the view_student_teams_path.

Scenario 3: Remove the advertisement.

  1. We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model.
  2. Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown "An error occurred and your advertisement was not removed." and the previous page is rendered.
  3. Remove Successful : If the advertisement is successfully removed in the database then the "Your advertisement was successfully removed!" message is prompted and the user is redirected to the view_student_teams_path.


Our Team

Yi Qiu(mentor)
Aaron Mathew (asmathew@ncsu.edu)
Priya Jakhar (pjakhar@ncsu.edu)
Supriya Krishna (sbkrishn@ncsu.edu)
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)