18948: Update test.
[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.UserNotifierEmailBcc = ConfigLoader.to_OrderedOptions({"bcc-notify@example.com"=>{},"bcc-notify2@example.com"=>{}})
14     Rails.configuration.Users.UserSetupMailText = %{
15 <% if not @user.full_name.empty? -%>
16 <%= @user.full_name %>,
17 <% else -%>
18 Hi there,
19 <% end -%>
20
21 Your Arvados shell account has been set up. Please visit the virtual machines page <% if Rails.configuration.Services.Workbench1.ExternalURL %>at
22
23 <%= Rails.configuration.Services.Workbench1.ExternalURL %><%= "/" if !Rails.configuration.Services.Workbench1.ExternalURL.to_s.end_with?("/") %>users/<%= @user.uuid%>/virtual_machines <% else %><% end %>
24
25 for connection instructions.
26
27 Thanks,
28 The Arvados team.
29 }
30
31     email = UserNotifier.account_is_setup user
32
33     assert_not_nil email
34
35     # Test the body of the sent email contains what we expect it to
36     assert_equal Rails.configuration.Users.UserNotifierEmailFrom, email.from.first
37     assert_equal Rails.configuration.Users.UserNotifierEmailBcc.stringify_keys.keys, email.bcc
38     assert_equal user.email, email.to.first
39     assert_equal 'Welcome to Arvados - account enabled', email.subject
40     assert (email.body.to_s.include? 'Your Arvados shell account has been set up'),
41         'Expected Your Arvados shell account has been set up in email body'
42     assert (email.body.to_s.include? Rails.configuration.Services.Workbench1.ExternalURL.to_s),
43         'Expected workbench url in email body'
44   end
45
46 end