Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email history #1339

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
148 changes: 74 additions & 74 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,60 @@ GEM
specs:
aasm (5.5.0)
concurrent-ruby (~> 1.0)
actioncable (6.1.7.2)
actionpack (= 6.1.7.2)
activesupport (= 6.1.7.2)
actioncable (6.1.7.3)
actionpack (= 6.1.7.3)
activesupport (= 6.1.7.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7.2)
actionpack (= 6.1.7.2)
activejob (= 6.1.7.2)
activerecord (= 6.1.7.2)
activestorage (= 6.1.7.2)
activesupport (= 6.1.7.2)
actionmailbox (6.1.7.3)
actionpack (= 6.1.7.3)
activejob (= 6.1.7.3)
activerecord (= 6.1.7.3)
activestorage (= 6.1.7.3)
activesupport (= 6.1.7.3)
mail (>= 2.7.1)
actionmailer (6.1.7.2)
actionpack (= 6.1.7.2)
actionview (= 6.1.7.2)
activejob (= 6.1.7.2)
activesupport (= 6.1.7.2)
actionmailer (6.1.7.3)
actionpack (= 6.1.7.3)
actionview (= 6.1.7.3)
activejob (= 6.1.7.3)
activesupport (= 6.1.7.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.7.2)
actionview (= 6.1.7.2)
activesupport (= 6.1.7.2)
actionpack (6.1.7.3)
actionview (= 6.1.7.3)
activesupport (= 6.1.7.3)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7.2)
actionpack (= 6.1.7.2)
activerecord (= 6.1.7.2)
activestorage (= 6.1.7.2)
activesupport (= 6.1.7.2)
actiontext (6.1.7.3)
actionpack (= 6.1.7.3)
activerecord (= 6.1.7.3)
activestorage (= 6.1.7.3)
activesupport (= 6.1.7.3)
nokogiri (>= 1.8.5)
actionview (6.1.7.2)
activesupport (= 6.1.7.2)
actionview (6.1.7.3)
activesupport (= 6.1.7.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.7.2)
activesupport (= 6.1.7.2)
activejob (6.1.7.3)
activesupport (= 6.1.7.3)
globalid (>= 0.3.6)
activemodel (6.1.7.2)
activesupport (= 6.1.7.2)
activerecord (6.1.7.2)
activemodel (= 6.1.7.2)
activesupport (= 6.1.7.2)
activestorage (6.1.7.2)
actionpack (= 6.1.7.2)
activejob (= 6.1.7.2)
activerecord (= 6.1.7.2)
activesupport (= 6.1.7.2)
activemodel (6.1.7.3)
activesupport (= 6.1.7.3)
activerecord (6.1.7.3)
activemodel (= 6.1.7.3)
activesupport (= 6.1.7.3)
activestorage (6.1.7.3)
actionpack (= 6.1.7.3)
activejob (= 6.1.7.3)
activerecord (= 6.1.7.3)
activesupport (= 6.1.7.3)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7.2)
activesupport (6.1.7.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -114,9 +114,9 @@ GEM
bson (4.15.0)
builder (3.2.4)
byebug (11.1.3)
cancancan (3.4.0)
cancancan (3.5.0)
coderay (1.1.3)
concurrent-ruby (1.2.0)
concurrent-ruby (1.2.2)
console (1.13.1)
fiber-local
countries (5.3.1)
Expand Down Expand Up @@ -146,7 +146,7 @@ GEM
phonelib
rest-client (~> 2.0)
validates_email_format_of
devise (4.8.1)
devise (4.9.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand Down Expand Up @@ -224,7 +224,7 @@ GEM
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.0.1)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
Expand All @@ -237,7 +237,7 @@ GEM
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
mini_portile2 (2.8.1)
minitest (5.17.0)
minitest (5.18.0)
mongo (2.18.2)
bson (>= 4.14.1, < 5.0.0)
mongoid (7.5.2)
Expand Down Expand Up @@ -270,7 +270,7 @@ GEM
orm_adapter (0.5.0)
os_map_ref (0.5.0)
parallel (1.22.1)
parser (3.2.0.0)
parser (3.2.1.1)
ast (~> 2.4.1)
phonelib (0.6.55)
protocol-hpack (1.4.2)
Expand All @@ -288,23 +288,23 @@ GEM
pry (>= 0.13, < 0.15)
public_suffix (5.0.0)
racc (1.6.2)
rack (2.2.6.2)
rack (2.2.6.4)
rack-test (2.0.2)
rack (>= 1.3)
rails (6.1.7.2)
actioncable (= 6.1.7.2)
actionmailbox (= 6.1.7.2)
actionmailer (= 6.1.7.2)
actionpack (= 6.1.7.2)
actiontext (= 6.1.7.2)
actionview (= 6.1.7.2)
activejob (= 6.1.7.2)
activemodel (= 6.1.7.2)
activerecord (= 6.1.7.2)
activestorage (= 6.1.7.2)
activesupport (= 6.1.7.2)
rails (6.1.7.3)
actioncable (= 6.1.7.3)
actionmailbox (= 6.1.7.3)
actionmailer (= 6.1.7.3)
actionpack (= 6.1.7.3)
actiontext (= 6.1.7.3)
actionview (= 6.1.7.3)
activejob (= 6.1.7.3)
activemodel (= 6.1.7.3)
activerecord (= 6.1.7.3)
activestorage (= 6.1.7.3)
activesupport (= 6.1.7.3)
bundler (>= 1.15.0)
railties (= 6.1.7.2)
railties (= 6.1.7.3)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
Expand All @@ -315,19 +315,19 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (6.1.7.2)
actionpack (= 6.1.7.2)
activesupport (= 6.1.7.2)
railties (6.1.7.3)
actionpack (= 6.1.7.3)
activesupport (= 6.1.7.3)
method_source
rake (>= 12.2)
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
rbtree3 (0.7.0)
regexp_parser (2.6.2)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
regexp_parser (2.7.0)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -358,26 +358,26 @@ GEM
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.11.1)
rubocop (1.44.1)
rubocop (1.48.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-capybara (2.17.0)
rubocop-ast (1.27.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.1)
rubocop (~> 1.41)
rubocop-rspec (2.18.1)
rubocop-rspec (2.19.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sassc (2.4.0)
ffi (~> 1.9)
Expand Down Expand Up @@ -412,12 +412,12 @@ GEM
thor (1.2.1)
tilt (2.0.10)
timecop (0.9.6)
timeout (0.3.1)
timeout (0.3.2)
timers (4.3.3)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (2.0.5)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uk_postcode (2.1.8)
unaccent (0.4.0)
Expand All @@ -444,7 +444,7 @@ GEM
websocket-extensions (0.1.5)
wicked_pdf (2.6.3)
activesupport
zeitwerk (2.6.6)
zeitwerk (2.6.7)

PLATFORMS
ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module CanHaveRegistrationAttributes
field :registrationType, as: :registration_type, type: String
field :reg_uuid, type: String # Used by waste-carriers-frontend
field :uuid, type: String
field :email_history, type: Array, default: []
# rubocop:enable Layout/LineLength

# Deprecated attributes
Expand Down Expand Up @@ -101,6 +102,8 @@ module CanHaveRegistrationAttributes
end
}

scope :not_selected_for_email, ->(template_id) { where.not("email_history.template_id": template_id) }

def self.telephone_regex(term)
# Clone the search term so we can modify it here without impacting other searches
search_term = term.dup
Expand Down
1 change: 1 addition & 0 deletions app/models/waste_carriers_engine/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Registration
scope :active, -> { where("metaData.status" => "ACTIVE") }
scope :expired_at_end_of_today, -> { where(:expires_on.lte => Time.now.in_time_zone("London").end_of_day) }
scope :upper_tier, -> { where(tier: UPPER_TIER) }
scope :lower_tier, -> { where(tier: LOWER_TIER) }
scope :active_and_expired, -> { where("metaData.status" => { :$in => %w[ACTIVE EXPIRED] }) }
scope :not_cancelled, -> { where("metaData.status" => { :$nin => %w[INACTIVE] }) }

Expand Down
33 changes: 33 additions & 0 deletions spec/models/waste_carriers_engine/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,39 @@ module WasteCarriersEngine
end
end

describe ".not_selected_for_email" do
let(:registration) { create(:registration, :has_required_data) }
let(:template_id) { "12345" }

context "when the registration has not been selected for any emails" do
it "returns the registration" do
expect(described_class.not_selected_for_email(template_id)).to include(registration)
end
end

context "when the registration has been selected for a different email" do
before do
registration.email_history << { email_type: "foo", template_id: "54321", time: Time.zone.now }
registration.save!
end

it "returns the registration" do
expect(described_class.not_selected_for_email(template_id)).to include(registration)
end
end

context "when the registration has been selected for this email" do
before do
registration.email_history << { email_type: "foo", template_id: template_id, time: Time.zone.now }
registration.save!
end

it "does not return the registration" do
expect(described_class.not_selected_for_email(template_id)).not_to include(registration)
end
end
end

describe "status" do
it_behaves_like "Can check registration status",
factory: :registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it "can only transition to either #{next_state}" do
permitted_states = Helpers::WorkflowStates.permitted_states(subject)

expect(permitted_states).to match_array([next_state])
expect(permitted_states).to contain_exactly(next_state)
end

it "changes to #{next_state} after the 'next' event" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it "can only transition to either #{next_state} or #{alt_state}" do
permitted_states = Helpers::WorkflowStates.permitted_states(a_subject)

expect(permitted_states).to match_array([next_state, alt_state])
expect(permitted_states).to contain_exactly(next_state, alt_state)
end

it "changes to #{next_state} after the 'next' event" do
Expand All @@ -40,7 +40,7 @@
it "can only transition to either #{next_state}" do
permitted_states = Helpers::WorkflowStates.permitted_states(a_subject)

expect(permitted_states).to match_array([next_state])
expect(permitted_states).to contain_exactly(next_state)
end

it "changes to #{next_state} after the 'next' event" do
Expand Down