mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
return fake "received_by_notify" status for letter notifications
created and sending aren't quite as helpful for letters, since their journey through notify and our providers is so different to emails/sms. So instead, we should return estimated_dispatch_date (in a future PR) and the status should just read received_by_notify
This commit is contained in:
@@ -797,6 +797,9 @@ NOTIFICATION_STATUS_TYPES_NON_BILLABLE = list(set(NOTIFICATION_STATUS_TYPES) - s
|
|||||||
|
|
||||||
NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notify_status_type')
|
NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notify_status_type')
|
||||||
|
|
||||||
|
NOTIFICATION_STATUS_LETTER_RECEIVED = 'received_by_notify'
|
||||||
|
NOTIFICATION_STATUS_LETTER_RECEIVED_PRETTY = 'Received by Notify'
|
||||||
|
|
||||||
|
|
||||||
class NotificationStatusTypes(db.Model):
|
class NotificationStatusTypes(db.Model):
|
||||||
__tablename__ = 'notification_status_types'
|
__tablename__ = 'notification_status_types'
|
||||||
@@ -962,17 +965,29 @@ class Notification(db.Model):
|
|||||||
'sent': 'Sent internationally'
|
'sent': 'Sent internationally'
|
||||||
},
|
},
|
||||||
'letter': {
|
'letter': {
|
||||||
'failed': 'Failed',
|
|
||||||
'technical-failure': 'Technical failure',
|
'technical-failure': 'Technical failure',
|
||||||
'temporary-failure': 'Temporary failure',
|
'sending': NOTIFICATION_STATUS_LETTER_RECEIVED_PRETTY,
|
||||||
'permanent-failure': 'Permanent failure',
|
'created': NOTIFICATION_STATUS_LETTER_RECEIVED_PRETTY,
|
||||||
'delivered': 'Delivered',
|
|
||||||
'sending': 'Sending',
|
|
||||||
'created': 'Sending',
|
|
||||||
'sent': 'Delivered'
|
|
||||||
}
|
}
|
||||||
}[self.template.template_type].get(self.status, self.status)
|
}[self.template.template_type].get(self.status, self.status)
|
||||||
|
|
||||||
|
def get_letter_status(self):
|
||||||
|
"""
|
||||||
|
Return the notification_status, as we should present for letters. The distinction between created and sending is
|
||||||
|
a bit more confusing for letters, not to mention that there's no concept of temporary or permanent failure yet.
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
# this should only ever be called for letter notifications - it makes no sense otherwise and I'd rather not
|
||||||
|
# get the two code flows mixed up at all
|
||||||
|
assert self.notification_type == LETTER_TYPE
|
||||||
|
|
||||||
|
if self.status == NOTIFICATION_CREATED or NOTIFICATION_SENDING:
|
||||||
|
return NOTIFICATION_STATUS_LETTER_RECEIVED
|
||||||
|
else:
|
||||||
|
# Currently can only be technical-failure
|
||||||
|
return status
|
||||||
|
|
||||||
def serialize_for_csv(self):
|
def serialize_for_csv(self):
|
||||||
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
||||||
serialized = {
|
serialized = {
|
||||||
@@ -1007,7 +1022,7 @@ class Notification(db.Model):
|
|||||||
"line_6": None,
|
"line_6": None,
|
||||||
"postcode": None,
|
"postcode": None,
|
||||||
"type": self.notification_type,
|
"type": self.notification_type,
|
||||||
"status": self.status,
|
"status": self.get_letter_status() if self.notification_type == LETTER_TYPE else self.status,
|
||||||
"template": template_dict,
|
"template": template_dict,
|
||||||
"body": self.content,
|
"body": self.content,
|
||||||
"subject": self.subject,
|
"subject": self.subject,
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ def test_notification_for_csv_returns_correct_job_row_number(notify_db, notify_d
|
|||||||
('sms', 'temporary-failure', 'Phone not accepting messages right now'),
|
('sms', 'temporary-failure', 'Phone not accepting messages right now'),
|
||||||
('sms', 'permanent-failure', 'Phone number doesn’t exist'),
|
('sms', 'permanent-failure', 'Phone number doesn’t exist'),
|
||||||
('sms', 'sent', 'Sent internationally'),
|
('sms', 'sent', 'Sent internationally'),
|
||||||
('letter', 'permanent-failure', 'Permanent failure'),
|
('letter', 'created', 'Received by Notify'),
|
||||||
('letter', 'delivered', 'Delivered')
|
('letter', 'sending', 'Received by Notify'),
|
||||||
|
('letter', 'technical-failure', 'Technical failure')
|
||||||
])
|
])
|
||||||
def test_notification_for_csv_returns_formatted_status(
|
def test_notification_for_csv_returns_formatted_status(
|
||||||
notify_db,
|
notify_db,
|
||||||
|
|||||||
Reference in New Issue
Block a user