mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Update save_letter task to save the default letter contact block when creating the notification.
This commit is contained in:
@@ -51,7 +51,8 @@ from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
sample_job as create_sample_job,
|
||||
sample_email_template as create_sample_email_template,
|
||||
sample_notification as create_sample_notification
|
||||
sample_notification as create_sample_notification,
|
||||
sample_letter_job
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_inbound_sms,
|
||||
@@ -62,7 +63,9 @@ from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_user,
|
||||
create_reply_to_email, create_service_sms_sender, create_service_with_defined_sms_sender)
|
||||
create_reply_to_email,
|
||||
create_service_with_defined_sms_sender
|
||||
)
|
||||
|
||||
|
||||
class AnyStringWith(str):
|
||||
@@ -986,7 +989,11 @@ def test_save_sms_does_not_send_duplicate_and_does_not_put_in_retry_queue(sample
|
||||
assert not retry.called
|
||||
|
||||
|
||||
def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
def test_save_letter_saves_letter_to_database(mocker, notify_db_session):
|
||||
service = create_service()
|
||||
create_letter_contact(service=service, contact_block="Address contract", is_default=True)
|
||||
template = create_template(service=service, template_type=LETTER_TYPE)
|
||||
job = create_job(template=template)
|
||||
|
||||
mocker.patch('app.celery.tasks.create_random_identifier', return_value="this-is-random-in-real-life")
|
||||
|
||||
@@ -1000,17 +1007,17 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
'postcode': 'Flob',
|
||||
}
|
||||
notification_json = _notification_json(
|
||||
template=sample_letter_job.template,
|
||||
template=job.template,
|
||||
to='Foo',
|
||||
personalisation=personalisation,
|
||||
job_id=sample_letter_job.id,
|
||||
job_id=job.id,
|
||||
row_number=1
|
||||
)
|
||||
notification_id = uuid.uuid4()
|
||||
created_at = datetime.utcnow()
|
||||
|
||||
save_letter(
|
||||
sample_letter_job.service_id,
|
||||
job.service_id,
|
||||
notification_id,
|
||||
encryption.encrypt(notification_json),
|
||||
)
|
||||
@@ -1018,9 +1025,9 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
notification_db = Notification.query.one()
|
||||
assert notification_db.id == notification_id
|
||||
assert notification_db.to == 'Foo'
|
||||
assert notification_db.job_id == sample_letter_job.id
|
||||
assert notification_db.template_id == sample_letter_job.template.id
|
||||
assert notification_db.template_version == sample_letter_job.template.version
|
||||
assert notification_db.job_id == job.id
|
||||
assert notification_db.template_id == job.template.id
|
||||
assert notification_db.template_version == job.template.version
|
||||
assert notification_db.status == 'created'
|
||||
assert notification_db.created_at >= created_at
|
||||
assert notification_db.notification_type == 'letter'
|
||||
@@ -1028,6 +1035,7 @@ def test_save_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
assert notification_db.sent_by is None
|
||||
assert notification_db.personalisation == personalisation
|
||||
assert notification_db.reference == "this-is-random-in-real-life"
|
||||
assert notification_db.reply_to_text == "Address contract"
|
||||
|
||||
|
||||
def test_should_cancel_job_if_service_is_inactive(sample_service,
|
||||
|
||||
Reference in New Issue
Block a user