-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1339 from alphagov/add-email-subscription-metrics
Add email subscription metrics
- Loading branch information
Showing
12 changed files
with
197 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module EmailApi | ||
class PageSubscriptionsClient | ||
def initialize | ||
@email_alert_api = GdsApi.email_alert_api | ||
end | ||
|
||
def fetch(path:) | ||
response = email_alert_api.get_subscriber_list_metrics(path:) | ||
EmailApi::PageSubscriptionsResponse.new(**response.to_h.symbolize_keys) | ||
rescue GdsApi::HTTPNotFound | ||
nil | ||
end | ||
|
||
private | ||
|
||
attr_reader :email_alert_api | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module EmailApi | ||
class PageSubscriptionsResponse | ||
def initialize(all_notify_count:, subscriber_list_count:) | ||
@all_notify_count = all_notify_count | ||
@subscriber_list_count = subscriber_list_count | ||
end | ||
|
||
attr_reader :all_notify_count, :subscriber_list_count | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h2 class="section-content__header content-metrics__header"><%= t("metrics.email_subscriptions.title") %></h2> | ||
<% if @email_subscriptions.present? %> | ||
<p><strong><%= t("metrics.email_subscriptions.active_title") %>:</strong> <%= @email_subscriptions.subscriber_list_count %></p> | ||
<p><strong><%= t("metrics.email_subscriptions.total_notify_title") %>:</strong> <%=@email_subscriptions.all_notify_count %></p> | ||
<% else %> | ||
<p><%= t("metrics.email_subscriptions.no_information") %></p> | ||
<% end %> | ||
|
||
<%= render "govuk_publishing_components/components/details", { | ||
title: t("metrics.email_subscriptions.about_title") | ||
} do %> | ||
|
||
<h3 class="govuk-heading-m"><%= t("metrics.email_subscriptions.active_title") %></h3> | ||
<p class="govuk-body govuk-body-s"><%= t("metrics.email_subscriptions.active_description") %></p> | ||
|
||
<h3 class="govuk-heading-m"><%= t("metrics.email_subscriptions.total_notify_title") %></h3> | ||
<p class="govuk-body govuk-body-s"><%= t("metrics.email_subscriptions.total_notify_description") %></p> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require "gds_api/test_helpers/email_alert_api" | ||
|
||
RSpec.describe "/metrics/base/path email subscription details", type: :feature do | ||
include RequestStubs | ||
include GdsApi::TestHelpers::EmailAlertApi | ||
|
||
context "logged in as another department" do | ||
before do | ||
GDS::SSO.test_user = build(:user) | ||
stub_metrics_page(base_path: "base/path", time_period: :past_30_days) | ||
end | ||
|
||
it "does not show the Email Subscriptions title" do | ||
visit "/metrics/base/path" | ||
expect(page).not_to have_content("Email subscriptions") | ||
end | ||
end | ||
|
||
context "logged in as GDS" do | ||
before do | ||
GDS::SSO.test_user = build(:view_email_subs_user) | ||
stub_metrics_page(base_path: "base/path", time_period: :past_30_days) | ||
end | ||
|
||
context "when there are subscriptions" do | ||
before do | ||
json = { subscriber_list_count: 3, all_notify_count: 10 }.to_json | ||
stub_get_subscriber_list_metrics(path: "/base/path", response: json) | ||
end | ||
|
||
it "shows the Email subscriptions section" do | ||
visit "/metrics/base/path" | ||
expect(page).to have_content("Email subscriptions") | ||
expect(page).to have_content("Active subscribers: 3") | ||
expect(page).to have_content("Number of subscribers notified by change: 10") | ||
expect(page).not_to have_content("No subscription information found") | ||
end | ||
|
||
it "shows information on the email metrics" do | ||
visit "/metrics/base/path" | ||
[ | ||
"Active subscribers is the number of people", | ||
"Number of subscribers notified by change is the number of people", | ||
].each do |txt| | ||
expect(page).to have_content(txt) | ||
end | ||
end | ||
end | ||
|
||
context "when there is a 404 from email-alert-api" do | ||
before do | ||
stub_get_subscriber_list_metrics_not_found(path: "/base/path") | ||
end | ||
|
||
it "shows the no subscription info section" do | ||
visit "/metrics/base/path" | ||
expect(page).to have_content("Email subscriptions") | ||
expect(page).to have_content("No subscription information found") | ||
expect(page).not_to have_content("Active subscribers:") | ||
expect(page).not_to have_content("Number of subscribers notified by change:") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "rails_helper" | ||
require "gds_api/test_helpers/email_alert_api" | ||
|
||
RSpec.describe EmailApi::PageSubscriptionsClient do | ||
include GdsApi::TestHelpers::EmailAlertApi | ||
subject { described_class.new } | ||
|
||
context "when subscription metrics exist" do | ||
before do | ||
json = { subscriber_list_count: 3, all_notify_count: 10 }.to_json | ||
stub_get_subscriber_list_metrics(path: "/some/path", response: json) | ||
end | ||
|
||
it "show details for the metrics" do | ||
metrics = subject.fetch(path: "/some/path") | ||
assert_equal 3, metrics.subscriber_list_count | ||
assert_equal 10, metrics.all_notify_count | ||
end | ||
end | ||
|
||
context "when subscription metrics 404" do | ||
before do | ||
stub_get_subscriber_list_metrics_not_found(path: "/some/path") | ||
end | ||
|
||
it "show details for the metrics" do | ||
metrics = subject.fetch(path: "/some/path") | ||
assert_nil metrics | ||
end | ||
end | ||
end |