16306: Merge branch 'master'
[arvados.git] / services / api / test / unit / user_notifier_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class UserNotifierTest < ActionMailer::TestCase
8
9   # Send the email, then test that it got queued
10   test "account is setup" do
11     user = users :active
12
13     Rails.configuration.Users.UserSetupMailText = %{
14 <% if not @user.full_name.empty? -%>
15 <%= @user.full_name %>,
16 <% else -%>
17 Hi there,
18 <% end -%>
19
20 Your Arvados shell account has been set up. Please visit the virtual machines page <% if Rails.configuration.Services.Workbench1.ExternalURL %>at
21
22 <%= Rails.configuration.Services.Workbench1.ExternalURL %><%= "/" if !Rails.configuration.Services.Workbench1.ExternalURL.to_s.end_with?("/") %>users/<%= @user.uuid%>/virtual_machines <% else %><% end %>
23
24 for connection instructions.
25
26 Thanks,
27 The Arvados team.
28 }
29
30     email = UserNotifier.account_is_setup user
31
32     assert_not_nil email
33
34     # Test the body of the sent email contains what we expect it to
35     assert_equal Rails.configuration.Users.UserNotifierEmailFrom, email.from.first
36     assert_equal user.email, email.to.first
37     assert_equal 'Welcome to Arvados - account enabled', email.subject
38     assert (email.body.to_s.include? 'Your Arvados shell account has been set up'),
39         'Expected Your Arvados shell account has been set up in email body'
40     assert (email.body.to_s.include? Rails.configuration.Services.Workbench1.ExternalURL.to_s),
41         'Expected workbench url in email body'
42   end
43
44 end