CSC/ECE 517 Fall 2016/E1668.Test e-mailing functionality

From Expertiza_Wiki
Revision as of 21:22, 28 October 2016 by Ychen75 (talk | contribs) (→‎Tests)
Jump to navigation Jump to search

E1668 -Test e-mailling functionality

Background

There are various ways to use e-mail functionality in the Expertiza. To name a few examples: users should get welcome emails once they register successfully, they should get reminder emails if they missed deadline of submission of their works, they should receive notification emails when other users review their homework, or others finish reviewing one of their reviews. All of these above are functions belongs to emailing. However, currently there is no test for these functions in the Expertise, which should be added to ensure valid usage of e-mailling features.

Project Requirements

(1) Feature tests should be written with the use of RSpec for the e-mailing functionality.

(2) All test examples should be written with the use of fixtures, such as assignment record or participant record.

(3) Capybara should be used when interacting with the Expertise and writing these feature tests.

(4) All possible valid or invalid cases for email functionality should be included in the tests.

Tests

Our tests files are located in the email_notification_spec.rb and edit_emails_spec.rb. Below are the tests in the "edit_emails_spec.rb", whose functions mostly involve update emailing options in the profile page:

(1) Testing email address can be edited successfully in the profile tab. Users can update their email addresses anytime by clicking the profile button in the header after they log in. They can fill in the new address in the "E-maill address" tab. We test if new address can be filled in successfully by using Capybara:

   describe 'email address' do
     it 'should edit email address' do
       fill_in 'E-mail address', with: 'ychen75@ncsu.edu'
       expect(find_field('E-mail address').value).to eq 'ychen75@ncsu.edu'
     end
   end


(2) Testing email option can be checked successfully in the profile tab. There are three attributes related to email functionality when we define a user: email_on_review, email_on_submission, email_on_review_of_review. These boolean values can be reset in the profile page under E-mail options checkbox can be checked/unchecked can be checked/unchecked successfully. We first test that if the 'When someone else reviews my work' checkbox by using Capybara:

   context 'When someone else reviews my work' do
       it "should check 'When someone else reviews my work' option" do
         find(:css, "#user_email_on_review").set(true)
          review_box = find('#user_email_on_review')
         expect(review_box).to be_checked
       end
    end  

Then, test that if 'When someone else reviews my work' checkbox can be checked/unchecked successfully:

 context 'When someone else reviews my work' do
       it "should check 'When someone else reviews my work' option" do
         find(:css, "#user_email_on_review").set(true)
         review_box = find('#user_email_on_review')
         expect(review_box).to be_checked
       end
     it "should uncheck 'When someone else reviews my work' option" do
         find(:css, "#user_email_on_review").set(false)  
         review_box = find('#user_email_on_review')
         expect(review_box).not_to be_checked
       end
     end

test that if the 'When someone else submits work I am assigned to review' checkbox can be checked/unchecked successfully:

   context 'When someone else submits work I am assigned to review' do
       it "should check 'When someone else submits work I am assigned to review' option" do
         find(:css, "#user_email_on_submission").set(true)
         review_box = find('#user_email_on_submission')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'When someone else submits work I am assigned to review' option" do
         find(:css, "#user_email_on_submission").set(false)
         review_box = find('#user_email_on_submission')
         expect(review_box).not_to be_checked
       end
   end

test that if the "When someone else reviews one of my reviews (metareviews my work)" checkbox can be checked/unchecked successfully:

   context 'When someone else reviews one of my reviews (metareviews my work)' do
       it "should check 'When someone else reviews one of my reviews (metareviews my work)' option" do
         find(:css, "#user_email_on_review_of_review").set(true)
         review_box = find('#user_email_on_review_of_review')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'When someone else reviews one of my reviews (metareviews my work)' option" do
         find(:css, "#user_email_on_review_of_review").set(false)
         review_box = find('#user_email_on_review_of_review')
         expect(review_box).not_to be_checked
       end
     end

test that if the "Send me copies of emails sent for assignments" checkbox can be checked/unchecked successfully:

   context 'Send me copies of emails sent for assignments' do
       it "should check 'Send me copies of emails sent for assignments' option" do
         review_box = find('#user_copy_of_emails')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'Send me copies of emails sent for assignments' option" do
         review_box = find(:css, "#user_copy_of_emails")
         expect(review_box).not_to be_checked
       end
     end

Below are the tests located in the email_notification_spec.rb file, we use a gem named 'capybara-email' to open the email we intend to send and check for the content for related mailing task:

(3) Testing email can be sent to users successfully if they reset their password. Users can reset their password if they forget about their previous ones. They can get a new password in email sent by the Expertiza system.

feature 'Reset password mailer' do

 background do
   FactoryGirl.create :student
   # will clear the message queue
   clear_emails
   visit 'password_retrieval/forgotten'
   find('input#user_email', visible: false).set('expertiza@mailinator.com')
   click_button 'Request password'
   # will find an email sent to expertiza.development@gmail.com and set `current_email`
   open_email('expertiza.development@gmail.com')
 end
 scenario 'testing for content' do
   expect(page).to have_current_path('/password_retrieval/forgotten')
   expect(current_email).to have_content 'Your Expertiza password has been reset. We strongly recommend that you change the password the next time you access the application.'
   expect(current_email).to have_content 'User Name'
   expect(current_email).to have_content 'New password'
 end

end

(4) Testing welcome email can be sent to users successfully if they sign up successfully.

(5) Testing email notification can be sent to the users successfully once their assigned homework get updated.

(6) Testing email can be sent to the users successfully once their work get reviewed.

Proposed future work

Reference