CSC/ECE 517 Fall 2019 - E1995. Tests for email functionality

From Expertiza_Wiki
Jump to navigation Jump to search



Problem Statement and Background

Expertiza system facilitates sending emails to students and instructors on occurrence of various events or helps in taking actions on the events that occur..

Email notifications are sent out when the following events occur:

  1. An account holder is emailed when a new account is created.
  2. A confirmation email is sent to a user of the system when they reset their Expertiza account password.
  3. The author of a submission gets notified via email when a reviewer has reviewed their work and the feedback is available.
  4. The reviewer receives an email when work has been submitted/resubmitted by an author whose work needs to be reviewed.

In the current scenario, it has been identified that not all emailing functionalities are working as desired. Also, presently, there is little evidence to claim that the existing implementation is covering all cases and handling all necessary conditions.

Our project is to build robust test suite for mailer functionality that is currently implemented in Expertiza. Developing this would ensure that all the mailing features are backed up with a stronger set of test features.

Approach Chosen and Why?

In this project we have first identified all the set of scenarios where the user of the system will get an email. 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 each of the mailers will be 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 mailing feature is in resonance with the other features and works coherently.

Implementation

We have implemented tests for the following scenarios:

Scenario 1: Creating a new user Account

There are various ways to create a new user account in Expertiza. Irrespective of the user creation method, the newly added user should get notified via email when his account is created in the system. This email states the username and a randomized password to allow the user to login for the first time. Below given are the ways to create new user to system.

  • By filling a user creation form

An instructor can add a new user to the system by filling up a user creation form

  • By importing a CSV file

The instructor can add new users to the system by importing a CSV file with user information


  • By importing a CSV file to add participants to an assignment

Instructor can add participants to an assignment by importing the users from a CSV. If the user listed in the CSV does not already exist in the system, then the a new user account is created and the user is added to the assignment.


  • User requests an account

A user can request an account by filling up a form with his details. These details get saved in the requested users table. Also, the super administrator will see these details in his pending requests section. The superadmin can approve/reject such requests. If the superadmin approves a request, a new user account is created in the system and the user receives an account creation email notification

Cases Tested

The following features were checked for all cases as part of the email functionality when a new user is created

  1. Mail delivery count increased by 1 after the mail triggered by the scenario is sent
  2. Sender email-id is verified. The sender mail-id is verified to be 'expertiza.development@gmail.com'
  3. Receiver email id is checked to be equal to 'expertiza.development@gmail.com' . Since the default recipient is 'expertiza.development@gmail.com' in test environment.
  4. The subject is checked to be equal to 'Your Expertiza account and password has been created'

We considered the following cases while testing specific to the scenario where user requests an account:

  1. No email should be sent if new account requested with invalid email address
  2. Super admin should receive email about new account request with a valid email address
  3. Email notification should be sent to requester when super admin approves account creation request
  4. No email notification should be sent to requester when super admin rejects account creation request


Capybara Tests

We used Capybara to model the scenario as follows:

  • Create user through instructor filling up the form:

Admin user is created using factory class.

  1. Visit expertiza
  2. Login_as 'admin_user'
  3. Visit list of users
  4. Click New User link
  5. Fill user_name with 'teststudent'
  6. Fill user_fullname with 'test student'
  7. Fill user_email with 'test@student.com'
  8. Check checkbox to send email to user on review
  9. Click 'Create' button.


  • User requests a new account and account is created upon approval from superadmin

Super admin is created using factory class.

  1. Visit expertiza
  2. Click Request Account link
  3. Select instructor from dropdown
  4. Fill user name with 'requester1'
  5. Fill user fullname with 'requester1, requester1'
  6. Fill user email with 'test.com'
  7. Fill user_email with 'test@student.com'
  8. Select 'North Carolina State University' from user institution
  9. Click 'Create' button.
  10. Visit list of pending requests from users
  11. Requested user's status is first 'Under Review'
  12. Set status as Approved or Rejected
  13. Click on 'Submit' button

Code Snippet

  • User creation by instructor:

Instructor creates new user by filling sign-up form

  • User creation by user request

Email count should be zero when user requests new account with an invalid email

Email count should be one when user requests new account with a valid email

  • User creation by importing csv files

Import CSV to add participants to assignment

Import CSV from manage users

Scenario 2: Resetting Password

When the user tries to login, and the password entered is wrong, the user is redirected to reset password page.

Here the email-id entered is searched through the database, If such user account is found: url for reset is generated, with random token set as password is sent to the user.


Flowchart:

Cases Tested

  • User enters email id which is not associated with any account
  1. No e-mail should be sent
  • User enters email id that's present in the user database

The following features were checked inside 'it blocks' as part of verifying email functionality

  1. Mail delivery count increased by 1 after the mail triggered by the scenario is sent
  2. The sender mail-id is verified to be 'expertiza.development@gmail.com'
  3. Receiver email id is checked to be equal to 'expertiza.development@gmail.com' . Since all mails triggered have a record in 'expertiza.development@gmail.com' when executed in test environment.
  4. The subject is checked to be equal to 'Expertiza password reset'


Files associated with this functionality:

  1. spec/controllers/PasswordRetrievalController
  2. app/controllers/PasswordRetrievalController
  3. app/mailers/mailer.rb
  4. app/helper/mailer_helper.rb

Capybara Tests

We used Capybara to model the scenario with following steps:

  1. Visit expertiza home page
  2. Click 'Forgot password?' link
  3. After rediection to password retrieval page
  4. Fill in user email field with 'expertiza@mailinator.com'
  5. Click on 'Request password' button


Code Snippet

If the email id is not associated with any existing account, then email count will be zero

If the email id is associated with an existing account, then email count will be one

Scenario 3. Authors get mail on receiving review

Whenever someone reviews other student or team’s work, then that student or all the members of that team should get notified through the email stating that new peer review is available for your work. Even when the reviewer updates the reviews, then also that student or all the team members should get notified that updated comments are present on their submitted work.

Files associated with this functionality:

  1. app/controllers/response_controller.rb
  2. app/models/review_response_map.rb

Scenario 4. Reviewer gets mail when authors resubmit work

This will be mainly the case when there will be more than one round of the submission. After the first submission, some users will be assigned to review the submitted work. Now, in second round of the submission, whenever author resubmits or edit their work, then in that case all the reviewers assigned to that author should get email notification stating new submission is available for them to review.

Files associated with this functionality:

  1. app/controllers/submitted_content_controller.rb
  2. app/helpers/mailer_helper.rb

Fixing out of scope bugs

Account Creation

When student accounts are created by importing a CSV file on the Users page, they receive e-mails with their user-ID and password. However, if an account is created by adding them as participants to an assignment when they don't already have an account, e-mail notification is not being sent.

What we fixed

The issue here was that an already existing user in the system will not get added as a participant on the assignment.

We fixed the issue by creating a new user if one doesn't exist and we enabling the email functionality by adding the .deliver_now method

This method invokes the mailer to deliver an email immediately.

Now that we have enabled the email functionality irrespective of where a new user is created from, we don't need to explicitly call the mailer from each location where new user is created. The email body was inconsistent across different scenarios. We had fixed this as well.

Capybara Tests

If the user does not exist in the system, new user account (if there is sufficient information about the user to create a new Expertiza account) is created

If the user already exists as a participant on the assignment, do nothing Add the user to the assignment as a participant; otherwise.

This way, the user(whether newly created or already an Expertiza user) gets added on the assignment as a participant.

Code Snippet

addition of deliver method to the statement triggered the mail to be sent. The message is also modified such the it is uniform throughout

instead of return unless, changed to if statement and return separately

Author should receive email notification upon review submission

After the reviewer submits the review, the author should get an email notification about this. Also, the instructor should receive an email about the same. This function is not currently working in the beta version.

What we fixed

We have added a new method named send_email_to_reviewee which will trigger an email to the author. The function call to this method is added to the 'update' and 'create' methods of Response Controller that will be called on submission/updation of review

Code Snippet

This method calls the email function to notify the reviewee


Reviewer will receive an email notification upon resubmission of the work by the author

For the assignments which have multiple submission rounds, after review round if the author changes the work, the reviewer should be notified of this change. Also, if at all the author resubmits the work, the reviewer as well as the instructor should get an email about the change that was done. This is not currently functional in expertiza beta. As discussed with our mentor, we have successfully fixed that issue and now in both of the cases as discussed above, the intended users( author in first scenario and reviewer and instructor in second one) are receiving the email notification.

What we fixed

We have added a new method 'email_all_reviewers' to submitted_content_controller which will send an email to all the reviewers of the work.

Code Snippet


Our Team

  1. Mohit Jain(mentor)
  2. Vishva Shah (vpshah@ncsu.edu)
  3. Urvish Vasani (uvasani@ncsu.edu)
  4. Tanvi Pandit(tmpandi2@ncsu.edu)
  5. Swathi Dinakaran(sdinaka@ncsu.edu)

References

Expertiza on GitHub click here

To visit our forked repo, click here

View our pull request here