diff --git a/app/models/concerns/mailable.rb b/app/models/concerns/mailable.rb index f727701d9..0769c58bb 100644 --- a/app/models/concerns/mailable.rb +++ b/app/models/concerns/mailable.rb @@ -28,7 +28,7 @@ def send_welcome_email reset_url = ENV['BRACCO_URL'] + "/reset" title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: New Account" - account_type = self.class.name == "Provider" ? member_type : client_type + account_type = self.class.name == "Provider" ? member_type.humanize : client_type.humanize text = User.format_message_text(template: "users/welcome.text.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) html = User.format_message_html(template: "users/welcome.html.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) @@ -48,7 +48,7 @@ def send_welcome_email def send_delete_email title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: Account Deleted" - account_type = self.class.name == "Provider" ? member_type : client_type + account_type = self.class.name == "Provider" ? member_type.humanize : client_type.humanize text = User.format_message_text(template: "users/delete.text.erb", title: title, contact_name: name, name: symbol) html = User.format_message_html(template: "users/delete.html.erb", title: title, contact_name: name, name: symbol) diff --git a/spec/concerns/mailable_spec.rb b/spec/concerns/mailable_spec.rb index b038859a3..75790be8c 100644 --- a/spec/concerns/mailable_spec.rb +++ b/spec/concerns/mailable_spec.rb @@ -2,7 +2,7 @@ describe "Mailable", type: :model, vcr: true do let(:token) { User.generate_token } - let(:provider) { create(:provider, symbol: "DATACITE") } + let(:provider) { create(:provider, symbol: "DATACITE", name: "DataCite", system_email: "test@datacite.org") } let(:client) { create(:client, symbol: "DATACITE.DATACITE", name: "DataCite Repository", system_email: "test@datacite.org", provider: provider) } let(:title) { "DataCite Fabrica" } @@ -55,4 +55,12 @@ expect(Client.send_notification_to_slack(text, options)).to eq("ok") end end + + context "send_notification_to_slack provider" do + it "succeeds" do + text = "Using system email #{provider.system_email}." + options = { title: "TEST: new provider account #{provider.symbol} created." } + expect(Client.send_notification_to_slack(text, options)).to eq("ok") + end + end end diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml index 4d93e4e03..2d448694a 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 20 Apr 2020 09:51:19 GMT + - Mon, 20 Apr 2020 14:48:47 GMT Server: - Apache Vary: @@ -31,7 +31,7 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - r + - h X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: @@ -41,10 +41,10 @@ http_interactions: Content-Type: - text/html X-Via: - - haproxy-www-9hkc + - haproxy-www-8gaq body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Mon, 20 Apr 2020 09:51:19 GMT + recorded_at: Mon, 20 Apr 2020 14:48:48 GMT recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml new file mode 100644 index 000000000..363740b7b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml @@ -0,0 +1,50 @@ +--- +http_interactions: +- request: + method: post + uri: "" + body: + encoding: US-ASCII + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+provider+account+DATACITE+created.%22%2C%22text%22%3A%22Using+system+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 20 Apr 2020 14:48:48 GMT + Server: + - Apache + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Slack-Backend: + - h + X-Frame-Options: + - SAMEORIGIN + Access-Control-Allow-Origin: + - "*" + Content-Length: + - '22' + Content-Type: + - text/html + X-Via: + - haproxy-www-8k7d + body: + encoding: ASCII-8BIT + string: ok + http_version: null + recorded_at: Mon, 20 Apr 2020 14:48:48 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml index e9ecaf7cf..9bbcc6da2 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 20 Apr 2020 09:51:18 GMT + - Mon, 20 Apr 2020 14:48:46 GMT Server: - Apache Vary: @@ -31,7 +31,7 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - r + - h X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: @@ -41,10 +41,10 @@ http_interactions: Content-Type: - text/html X-Via: - - haproxy-www-y6ft + - haproxy-www-s8m4 body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Mon, 20 Apr 2020 09:51:18 GMT + recorded_at: Mon, 20 Apr 2020 14:48:47 GMT recorded_with: VCR 5.1.0