-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add email volume estimates to signup confirm page
Add very rough guesses about the weekly volume of email a user can expect depending on which level of the taxonomy they sign up to. These figures are based on analysis of historical email volume.
- Loading branch information
Mo Baig
committed
Mar 26, 2017
1 parent
ce64de0
commit d4a97b2
Showing
5 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class WeeklyEmailVolume | ||
HIGH = '40-60'.freeze | ||
MEDIUM = '0-20'.freeze | ||
LOW = '0-5'.freeze | ||
|
||
def initialize(taxon) | ||
@taxon = taxon | ||
end | ||
|
||
def estimate | ||
parent_taxon = extract_parent_from(@taxon) | ||
|
||
# Is at the top of the taxonomy | ||
return HIGH if parent_taxon.blank? | ||
|
||
# Is a 2nd level taxon | ||
grandparent_taxon = extract_parent_from( | ||
fetch_content_item(parent_taxon.fetch('base_path')) | ||
) | ||
return MEDIUM if grandparent_taxon.blank? | ||
|
||
# Is a 3rd level taxon or below | ||
return LOW | ||
end | ||
|
||
private | ||
|
||
def extract_parent_from(content_item) | ||
Array(content_item.dig('links', 'parent_taxons')).first | ||
end | ||
|
||
def fetch_content_item(base_path) | ||
EmailAlertFrontend.services(:content_store).content_item(base_path) | ||
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
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,50 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe WeeklyEmailVolume do | ||
include GdsApi::TestHelpers::ContentStore | ||
|
||
describe "#estimate" do | ||
let(:top_taxon) do | ||
{ base_path: '/top', links: { parent_taxons: [] } }.deep_stringify_keys | ||
end | ||
|
||
let(:second_taxon) do | ||
{ | ||
base_path: '/second', links: { parent_taxons: [ { base_path: '/top' } ] } | ||
}.deep_stringify_keys | ||
end | ||
|
||
context 'given a top level taxon' do | ||
it 'returns a HIGH range' do | ||
expect(WeeklyEmailVolume.new(top_taxon).estimate).to eq WeeklyEmailVolume::HIGH | ||
end | ||
end | ||
|
||
context 'given a 2nd level taxon' do | ||
|
||
before do | ||
content_store_has_item(top_taxon['base_path'], top_taxon) | ||
end | ||
|
||
it 'returns a MEDIUM range' do | ||
expect(WeeklyEmailVolume.new(second_taxon).estimate).to eq WeeklyEmailVolume::MEDIUM | ||
end | ||
end | ||
|
||
context 'given a 3rd level taxon' do | ||
let(:third_taxon) do | ||
{ | ||
base_path: '/third', links: { parent_taxons: [ { base_path: '/second' } ] } | ||
}.deep_stringify_keys | ||
end | ||
|
||
before do | ||
content_store_has_item(second_taxon['base_path'], second_taxon) | ||
end | ||
|
||
it 'returns a LOW range' do | ||
expect(WeeklyEmailVolume.new(third_taxon).estimate).to eq WeeklyEmailVolume::LOW | ||
end | ||
end | ||
end | ||
end |