Skip to content

Commit

Permalink
Merge pull request sparc-request#184 from bmic-development/kg-user_ma…
Browse files Browse the repository at this point in the history
…iler_spec

KG - User Mail Spec Random Failure Data Cleanup
  • Loading branch information
Stuart-Johnson committed Apr 3, 2017
2 parents ed5ea52 + 73d71a4 commit 1b34b9c
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 69 deletions.
170 changes: 111 additions & 59 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,74 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

require "rails_helper"

RSpec.describe UserMailer do

let_there_be_lane
let_there_be_j
fake_login_for_each_test
build_service_request_with_study
let(:identity) { create(:identity) }
let(:modified_identity) { create(:identity) }
let(:institution) { create(:institution) }
let(:provider) { create(:provider, parent: institution) }
let(:program) { create(:program, parent: provider) }
let(:service) { create(:service, organization: program) }

context "added an authorized user" do
before :each do
@modified_identity = create(:identity)
@identity = create(:identity)
@protocol_role = create(:project_role, protocol: study, identity: @modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(@identity, study, @protocol_role, 'add')
end

it "should display the 'added' message" do
# An Authorized User has been added in SparcDashboard ***(link to protocol)***
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'An Authorized User has been added in']")
expect(@mail).to have_xpath "//p//a[@href='/dashboard/protocols/#{study.id}'][text()= 'SPARCDashboard.']/@href"
end
context 'general' do
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'add')
end

it "should display the 'added' message" do
# An Authorized User has been added in SparcDashboard ***(link to protocol)***
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'An Authorized User has been added in']")
expect(@mail).to have_xpath "//p//a[@href='/dashboard/protocols/#{@protocol.id}'][text()= 'SPARCDashboard.']/@href"
end

it "should display the Protocol information table" do
protocol_information_table
end

it "should display message conclusion" do
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'Please contact the SUCCESS Center at (843) 792-8300 or success@musc.edu for assistance with this process or with any questions you may have.']")
end

it "should display the Protocol information table" do
protocol_information_table
it "should display acknowledgments" do
@protocol.service_requests.first.service_list.map{|k, v| v[:acks]}.flatten.uniq.each do |ack|
expect(@mail).to have_xpath("//p[normalize-space(text()) = '#{ack}']")
end
end
end

context 'when protocol has selected for epic' do
before do
study.update_attribute(:selected_for_epic, true)
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity, selected_for_epic: true)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'add')
end

it 'should show epic column' do
Expand All @@ -36,46 +77,61 @@
end

context 'when protocol does not have selected for epic' do
before do
study.update_attribute(:selected_for_epic, false)
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity, selected_for_epic: false)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'add')
end

it 'should not show epic col' do
user_information_table_without_epic_col
end
end
end

it "should display message conclusion" do
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'Please contact the SUCCESS Center at (843) 792-8300 or success@musc.edu for assistance with this process or with any questions you may have.']")
end
context "deleted an authorized user" do
context 'general' do
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'destroy')
end

it "should display acknowledgments" do
study.service_requests.first.service_list.map{|k, v| v[:acks]}.flatten.uniq.each do |ack|
expect(@mail).to have_xpath("//p[normalize-space(text()) = '#{ack}']")
it "should display the 'deleted' message" do
# An Authorized User has been deleted in SparcDashboard ***(link to protocol)***
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'An Authorized User has been deleted in']")
expect(@mail).to have_xpath "//p//a[@href='/dashboard/protocols/#{@protocol.id}'][text()= 'SPARCDashboard.']/@href"
end
end
end

context "deleted an authorized user" do
before :each do
@modified_identity = create(:identity)
@identity = create(:identity)
@protocol_role = create(:project_role, protocol: study, identity: @modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(@identity, study, @protocol_role, 'destroy')
end
it "should display the Protocol information table" do
protocol_information_table
end

it "should display the 'deleted' message" do
# An Authorized User has been deleted in SparcDashboard ***(link to protocol)***
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'An Authorized User has been deleted in']")
expect(@mail).to have_xpath "//p//a[@href='/dashboard/protocols/#{study.id}'][text()= 'SPARCDashboard.']/@href"
end
it "should display message conclusion" do
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'Please contact the SUCCESS Center at (843) 792-8300 or success@musc.edu for assistance with this process or with any questions you may have.']")
end

it "should display the Protocol information table" do
protocol_information_table
it "should display acknowledgments" do
@protocol.service_requests.first.service_list.map{|k, v| v[:acks]}.flatten.uniq.each do |ack|
expect(@mail).to have_xpath("//p[normalize-space(text()) = '#{ack}']")
end
end
end

context 'when protocol has selected for epic' do
before do
study.update_attribute(:selected_for_epic, true)
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity, selected_for_epic: true)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'destroy')
end

it 'should show epic column' do
Expand All @@ -84,22 +140,18 @@
end

context 'when protocol does not have selected for epic' do
before do
study.update_attribute(:selected_for_epic, false)
before :each do
@protocol = create(:study_without_validations, :funded, :federal, primary_pi: identity, selected_for_epic: false)
@sr = create(:service_request_without_validations, protocol: @protocol)
@ssr = create(:sub_service_request_without_validations, service_request: @sr, protocol: @protocol, organization: program)
@li = create(:line_item, sub_service_request: @ssr, service_request: @sr, service: service)
@protocol_role = create(:project_role, protocol: @protocol, identity: modified_identity, project_rights: 'approve', role: 'consultant')
@mail = UserMailer.authorized_user_changed(identity, @protocol, @protocol_role, 'destroy')
end

it 'should not show epic col' do
user_information_table_without_epic_col
end
end

it "should display message conclusion" do
expect(@mail).to have_xpath("//p[normalize-space(text()) = 'Please contact the SUCCESS Center at (843) 792-8300 or success@musc.edu for assistance with this process or with any questions you may have.']")
end

it "should display acknowledgments" do
study.service_requests.first.service_list.map{|k, v| v[:acks]}.flatten.uniq.each do |ack|
expect(@mail).to have_xpath("//p[normalize-space(text()) = '#{ack}']")
end
end
end
end
end
40 changes: 30 additions & 10 deletions spec/support/user_mailer_emails/tables.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module EmailHelpers

def protocol_information_table
expect(@mail).to have_xpath "//table//strong[text()='Study Information']"
expect(@mail).to have_xpath "//th[text()='Study ID']/following-sibling::td[text()='#{study.id}']"
expect(@mail).to have_xpath "//th[text()='Short Title']/following-sibling::td[text()='#{study.short_title}']"
expect(@mail).to have_xpath "//th[text()='Study Title']/following-sibling::td[text()='#{study.title}']"
expect(@mail).to have_xpath "//th[text()='Sponsor Name']/following-sibling::td[text()='#{study.sponsor_name}']"
expect(@mail).to have_xpath "//th[text()='Funding Source']/following-sibling::td[text()='#{study.funding_source.capitalize}']"
expect(@mail).to have_xpath "//th[text()='Study ID']/following-sibling::td[text()='#{@protocol.id}']"
expect(@mail).to have_xpath "//th[text()='Short Title']/following-sibling::td[text()='#{@protocol.short_title}']"
expect(@mail).to have_xpath "//th[text()='Study Title']/following-sibling::td[text()='#{@protocol.title}']"
expect(@mail).to have_xpath "//th[text()='Sponsor Name']/following-sibling::td[text()='#{@protocol.sponsor_name}']"
expect(@mail).to have_xpath "//th[text()='Funding Source']/following-sibling::td[text()='#{@protocol.funding_source.capitalize}']"
end

def user_information_table_with_epic_col
expect(@mail).to have_xpath "//table//strong[text()='User Information']"
expect(@mail).to have_xpath "//th[text()='User Modification']/following-sibling::th[text()='Contact Information']/following-sibling::th[text()='Role']/following-sibling::th[text()='SPARC Proxy Rights']/following-sibling::th[text()='Epic Access']"
expect(@mail).to have_xpath "//td[text()=\"#{@modified_identity.full_name}\"]/following-sibling::td[text()=\"#{@modified_identity.email}\"]/following-sibling::td[text()='#{@modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.display_rights}']"
if @modified_identity.project_roles.first.epic_access == false
expect(@mail).to have_xpath "//td[text()=\"#{modified_identity.full_name}\"]/following-sibling::td[text()=\"#{modified_identity.email}\"]/following-sibling::td[text()='#{modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{modified_identity.project_roles.first.display_rights}']"
if modified_identity.project_roles.first.epic_access == false
expect(@mail).to have_xpath "//td[text()='No']"
else
expect(@mail).to have_xpath "//td[text()='Yes']"
Expand All @@ -24,9 +44,9 @@ def user_information_table_without_epic_col
expect(@mail).to have_xpath "//table//strong[text()='User Information']"
expect(@mail).to have_xpath "//th[text()='User Modification']/following-sibling::th[text()='Contact Information']/following-sibling::th[text()='Role']/following-sibling::th[text()='SPARC Proxy Rights']"
expect(@mail).not_to have_xpath "//following-sibling::th[text()='Epic Access']"
expect(@mail).to have_xpath "//td[text()=\"#{@modified_identity.full_name}\"]/following-sibling::td[text()=\"#{@modified_identity.email}\"]/following-sibling::td[text()='#{@modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{@modified_identity.project_roles.first.display_rights}']"
expect(@mail).to have_xpath "//td[text()=\"#{modified_identity.full_name}\"]/following-sibling::td[text()=\"#{modified_identity.email}\"]/following-sibling::td[text()='#{modified_identity.project_roles.first.role.upcase}']/following-sibling::td[text()='#{modified_identity.project_roles.first.display_rights}']"

if @modified_identity.project_roles.first.epic_access == false
if modified_identity.project_roles.first.epic_access == false
expect(@mail).not_to have_xpath "//td[text()='No']"
else
expect(@mail).not_to have_xpath "//td[text()='Yes']"
Expand All @@ -38,4 +58,4 @@ def user_information_table_without_epic_col
config.include EmailHelpers
config.include EmailSpec::Helpers
config.include EmailSpec::Matchers
end
end

0 comments on commit 1b34b9c

Please sign in to comment.