forked from External/greenlight
GRN2-6: Notify admins when a approve/invite user signs up (#538)
* Notify admins when a approve/invite user signs up * Fix formating * Uses admins_url variable
This commit is contained in:
committed by
Jesus Federico
parent
83a9edf81d
commit
f88d67f6fb
@ -223,6 +223,36 @@ describe SessionsController, type: :controller do
|
||||
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
context 'registration notification emails' do
|
||||
before do
|
||||
allow(Rails.configuration).to receive(:enable_email_verification).and_return(true)
|
||||
@user = create(:user, provider: "greenlight")
|
||||
@admin = create(:user, provider: "greenlight", email: "test@example.com")
|
||||
@admin.add_role :admin
|
||||
end
|
||||
|
||||
it "should notify admin on new user signup with approve/reject registration" do
|
||||
allow_any_instance_of(Registrar).to receive(:approval_registration).and_return(true)
|
||||
|
||||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:bn_launcher]
|
||||
|
||||
expect { get :omniauth, params: { provider: 'bn_launcher' } }
|
||||
.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
|
||||
it "should notify admin on new user signup with invite registration" do
|
||||
allow_any_instance_of(Registrar).to receive(:invite_registration).and_return(true)
|
||||
|
||||
invite = Invitation.create(email: "user@google.com", provider: "greenlight")
|
||||
@request.session[:invite_token] = invite.invite_token
|
||||
|
||||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:bn_launcher]
|
||||
|
||||
expect { get :omniauth, params: { provider: 'bn_launcher' } }
|
||||
.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should not create session without omniauth env set for bn_launcher" do
|
||||
|
@ -186,6 +186,17 @@ describe UsersController, type: :controller do
|
||||
before do
|
||||
allow_any_instance_of(Registrar).to receive(:invite_registration).and_return(true)
|
||||
allow(Rails.configuration).to receive(:allow_user_signup).and_return(true)
|
||||
@user = create(:user, provider: "greenlight")
|
||||
@admin = create(:user, provider: "greenlight", email: "test@example.com")
|
||||
@admin.add_role :admin
|
||||
end
|
||||
|
||||
it "should notify admins that user signed up" do
|
||||
params = random_valid_user_params
|
||||
invite = Invitation.create(email: params[:user][:email], provider: "greenlight")
|
||||
@request.session[:invite_token] = invite.invite_token
|
||||
|
||||
expect { post :create, params: params }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
|
||||
it "rejects the user if they are not invited" do
|
||||
@ -240,6 +251,9 @@ describe UsersController, type: :controller do
|
||||
before do
|
||||
allow_any_instance_of(Registrar).to receive(:approval_registration).and_return(true)
|
||||
allow(Rails.configuration).to receive(:allow_user_signup).and_return(true)
|
||||
@user = create(:user, provider: "greenlight")
|
||||
@admin = create(:user, provider: "greenlight", email: "test@example.com")
|
||||
@admin.add_role :admin
|
||||
end
|
||||
|
||||
it "allows any user to sign up" do
|
||||
@ -265,6 +279,14 @@ describe UsersController, type: :controller do
|
||||
|
||||
expect(u.has_role?(:pending)).to eq(true)
|
||||
end
|
||||
|
||||
it "notifies admins that a user signed up" do
|
||||
allow(Rails.configuration).to receive(:enable_email_verification).and_return(true)
|
||||
|
||||
params = random_valid_user_params
|
||||
|
||||
expect { post :create, params: params }.to change { ActionMailer::Base.deliveries.count }.by(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user