mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
add inbound sms api
two endpoints: * get all inbound sms for a service (you can limit to the X most recent, or filter by user's phone number [which will be normalised]) * get a summary of inbound sms for a service - returns the count of inbound sms in the database, and the date that the most recent was sent
This commit is contained in:
59
tests/app/dao/test_inbound_sms_dao.py
Normal file
59
tests/app/dao/test_inbound_sms_dao.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from datetime import datetime
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.dao.inbound_sms_dao import dao_get_inbound_sms_for_service, dao_count_inbound_sms_for_service
|
||||
|
||||
from tests.app.db import create_inbound_sms, create_service
|
||||
|
||||
|
||||
def test_get_all_inbound_sms(sample_service):
|
||||
inbound = create_inbound_sms(sample_service)
|
||||
|
||||
res = dao_get_inbound_sms_for_service(sample_service.id)
|
||||
assert len(res) == 1
|
||||
assert res[0] == inbound
|
||||
|
||||
|
||||
def test_get_all_inbound_sms_when_none_exist(sample_service):
|
||||
res = dao_get_inbound_sms_for_service(sample_service.id)
|
||||
assert len(res) == 0
|
||||
|
||||
|
||||
def test_get_all_inbound_sms_limits_and_orders(sample_service):
|
||||
with freeze_time('2017-01-01'):
|
||||
one = create_inbound_sms(sample_service)
|
||||
with freeze_time('2017-01-03'):
|
||||
three = create_inbound_sms(sample_service)
|
||||
with freeze_time('2017-01-02'):
|
||||
two = create_inbound_sms(sample_service)
|
||||
|
||||
res = dao_get_inbound_sms_for_service(sample_service.id, limit=2)
|
||||
assert len(res) == 2
|
||||
assert res[0] == three
|
||||
assert res[0].created_at == datetime(2017, 1, 3)
|
||||
assert res[1] == two
|
||||
assert res[1].created_at == datetime(2017, 1, 2)
|
||||
|
||||
|
||||
def test_get_all_inbound_sms_filters_on_service(notify_db_session):
|
||||
service_one = create_service(service_name='one')
|
||||
service_two = create_service(service_name='two')
|
||||
|
||||
sms_one = create_inbound_sms(service_one)
|
||||
sms_two = create_inbound_sms(service_two)
|
||||
|
||||
res = dao_get_inbound_sms_for_service(service_one.id)
|
||||
assert len(res) == 1
|
||||
assert res[0] == sms_one
|
||||
|
||||
|
||||
def test_count_inbound_sms_for_service(notify_db_session):
|
||||
service_one = create_service(service_name='one')
|
||||
service_two = create_service(service_name='two')
|
||||
|
||||
create_inbound_sms(service_one)
|
||||
create_inbound_sms(service_one)
|
||||
create_inbound_sms(service_two)
|
||||
|
||||
assert dao_count_inbound_sms_for_service(service_one.id) == 2
|
||||
Reference in New Issue
Block a user