Invite manager specs

This commit is contained in:
Matt-Yorkley
2017-09-29 16:52:10 +01:00
parent b64327fbb3
commit 128ca3b1ef
4 changed files with 82 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ class EnterpriseMailer < Spree::BaseMailer
def manager_invitation(enterprise, user)
@enterprise = enterprise
@instance = Spree::Config[:site_name]
@instance_email = Spree::Config[:preferred_mails_from]
@instance_email = from_address
subject = t('enterprise_mailer.invite_manager.subject', enterprise: @enterprise.name)

View File

@@ -634,5 +634,41 @@ module Admin
end
end
end
describe "#invite_manager" do
context "when given email matches an existing user" do
let!(:existing_user) { create(:user) }
let!(:enterprise) { create(:enterprise) }
let(:admin) { create(:admin_user) }
before do
controller.stub spree_current_user: admin
end
it "returns an error" do
spree_post :invite_manager, {email: user.email, enterprise: enterprise.id}
expect(response.status).to eq 422
expect(json_response['errors']).to eq I18n.t('admin.enterprises.invite_manager.user_already_exists')
end
end
context "signing up a new user" do
let!(:enterprise) { create(:enterprise) }
let(:admin) { create(:admin_user) }
before do
controller.stub spree_current_user: admin
end
it "creates a new user, sends an invitation email, and returns the user id" do
spree_post :invite_manager, {email: 'un.registered@email.com', enterprise: enterprise.id}
expect(Delayed::Job.last.payload_object.class.to_s).to eq('ManagerInvitationJob')
expect(response.status).to eq 200
expect(json_response['user']).to eq Spree::User.find_by_email('un.registered@email.com').id
end
end
end
end
end

View File

@@ -114,7 +114,9 @@ feature %q{
# user3 has been added and has an unconfirmed email address
expect(page).to have_css "tr#manager-#{user3.id}"
expect(page).to have_css 'i.unconfirmed'
within "tr#manager-#{user3.id}" do
expect(page).to have_css 'i.unconfirmed'
end
end
end
@@ -133,6 +135,31 @@ feature %q{
end
end
end
it "can invite unregistered users to be managers" do
new_email = 'new@manager.com'
find('a.button.help-modal').click
expect(page).to have_css '#invite-manager-modal'
within '#invite-manager-modal' do
fill_in 'invite_email', with: new_email
click_button I18n.t('js.admin.modals.invite')
expect(page).to have_content I18n.t('user_invited', email: new_email)
click_button I18n.t('js.admin.modals.close')
end
new_user = Spree::User.find_by_email_and_confirmed_at(new_email, nil)
expect(Enterprise.managed_by(new_user)).to include enterprise
within 'table.managers' do
expect(page).to have_content new_email
within "tr#manager-#{new_user.id}" do
expect(page).to have_css 'i.unconfirmed'
end
end
end
end
end

View File

@@ -2,15 +2,27 @@ require 'spec_helper'
describe EnterpriseMailer do
let!(:enterprise) { create(:enterprise) }
let!(:user) { create(:user) }
before do
ActionMailer::Base.deliveries = []
end
it "should send a welcome email when given an enterprise" do
EnterpriseMailer.welcome(enterprise).deliver
ActionMailer::Base.deliveries.count.should == 1
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq "#{enterprise.name} is now on #{Spree::Config[:site_name]}"
describe "#welcome" do
it "should send a welcome email when given an enterprise" do
EnterpriseMailer.welcome(enterprise).deliver
ActionMailer::Base.deliveries.count.should == 1
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq "#{enterprise.name} is now on #{Spree::Config[:site_name]}"
end
end
describe "#manager_invitation" do
it "should send a manager invitation email when given an enterprise and user" do
EnterpriseMailer.manager_invitation(enterprise, user).deliver
expect(ActionMailer::Base.deliveries.count).to eq 1
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to eq "#{enterprise.name} has invited you to be a manager"
end
end
end