diff --git a/app/models/external_events/enrollment_event_notification.rb b/app/models/external_events/enrollment_event_notification.rb index 605201237..95b08083f 100644 --- a/app/models/external_events/enrollment_event_notification.rb +++ b/app/models/external_events/enrollment_event_notification.rb @@ -65,7 +65,7 @@ def drop_if_already_processed! :enrollment_action_uri => enrollment_action ) if found_event.any? - if is_reterm_with_earlier_date? + if is_eligible_term? false else response_with_publisher do |result_publisher| @@ -295,6 +295,15 @@ def is_reterm_with_earlier_date? # terminating policy again with earlier termina (existing_policy.present? && existing_policy.terminated? && existing_policy.policy_end > extract_enrollee_end(subscriber)) end + def is_eligible_term? + return false unless is_termination? + return false unless extract_enrollee_end(subscriber).present? + return false if existing_policy.blank? + return true unless existing_policy.terminated? + + existing_policy.terminated? && existing_policy.policy_end > extract_enrollee_end(subscriber) + end + def enrollment_action @enrollment_action ||= extract_enrollment_action(enrollment_event_xml) end diff --git a/spec/models/external_events/enrollment_event_notification_spec.rb b/spec/models/external_events/enrollment_event_notification_spec.rb index 386c3db57..839060ee1 100644 --- a/spec/models/external_events/enrollment_event_notification_spec.rb +++ b/spec/models/external_events/enrollment_event_notification_spec.rb @@ -728,7 +728,7 @@ allow(subject).to receive(:is_termination?).and_return(true) allow(subject).to receive(:hbx_enrollment_id).and_return(hbx_enrollment_id) allow(subject).to receive(:enrollment_action).and_return("urn:openhbx:terms:v1:enrollment#terminate_enrollment") - allow(subject).to receive(:is_reterm_with_earlier_date?).and_return(true) + allow(subject).to receive(:is_eligible_term?).and_return(true) end it "returns false" do @@ -744,7 +744,7 @@ allow(subject).to receive('response_with_publisher').and_yield(result_publisher) allow(subject).to receive(:hbx_enrollment_id).and_return(hbx_enrollment_id) allow(subject).to receive(:enrollment_action).and_return("urn:openhbx:terms:v1:enrollment#terminate_enrollment") - allow(subject).to receive(:is_reterm_with_earlier_date?).and_return(false) + allow(subject).to receive(:is_eligible_term?).and_return(false) end it "returns notify event already processed" do