Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions drivers/place/survey_mailer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
22 changes: 18 additions & 4 deletions drivers/place/survey_mailer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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