diff --git a/drivers/place/survey_mailer.cr b/drivers/place/survey_mailer.cr index d46fc88307f..c33eff5e6e9 100644 --- a/drivers/place/survey_mailer.cr +++ b/drivers/place/survey_mailer.cr @@ -45,10 +45,13 @@ class Place::SurveyMailer < PlaceOS::Driver @[Security(Level::Support)] def send_survey_emails - invites = Array(SurveyInvite).from_json staff_api.get_survey_invites(sent: false).get.to_json + # using #get_survey_invites instead of #get_survey_invites(sent: false) + # due to `sent <> true` not being equivalent to `sent IS NOT true` in PostgreSQL + invites = Array(SurveyInvite).from_json staff_api.get_survey_invites.get.to_json sent_invites : Hash(String, Array(Int64)) = {} of String => Array(Int64) invites.each do |invite| + next if invite.sent begin if !(sent_surveys = sent_invites[invite.email]?) || !sent_surveys.includes?(invite.survey_id) sent_invites[invite.email] ||= [] of Int64 @@ -78,6 +81,6 @@ class Place::SurveyMailer < PlaceOS::Driver property survey_id : Int64 property token : String property email : String - property sent : Bool + property sent : Bool? end end diff --git a/drivers/place/survey_mailer_spec.cr b/drivers/place/survey_mailer_spec.cr index 23ca1963d3d..53ae1065eac 100644 --- a/drivers/place/survey_mailer_spec.cr +++ b/drivers/place/survey_mailer_spec.cr @@ -5,7 +5,7 @@ class StaffAPI < DriverSpecs::MockDriver def get_survey_invites(survey_id : Int64? = nil, sent : Bool? = nil) survey_id ||= 1 - unsent_invites = [ + invites = [ { id: 1, survey_id: survey_id, @@ -21,15 +21,29 @@ class StaffAPI < DriverSpecs::MockDriver sent: false, }, { - id: 2, + id: 3, survey_id: survey_id, token: "QWERTY", email: "user2@spec.test", sent: false, }, + { + id: 4, + survey_id: survey_id, + token: "QWERTY", + email: "user3@spec.test", + sent: nil, + }, + { + id: 5, + survey_id: survey_id, + token: "QWERTY", + email: "user4@spec.test", + sent: true, + }, ] - JSON.parse(unsent_invites.to_json) + JSON.parse(invites.to_json) end def update_survey_invite(token : String, email : String? = nil, sent : Bool? = nil) @@ -79,5 +93,5 @@ DriverSpecs.mock_driver "Place::StaffAPI" do }) _resp = exec(:send_survey_emails).get - system(:Mailer_1)[:sent].should eq 2 + system(:Mailer_1)[:sent].should eq 3 end