Skip to content

Commit

Permalink
Merge pull request #12 from aitormagan/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aitormagan authored Jul 27, 2021
2 parents 114ce01 + 6b4bb05 commit 6f530b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ custom:
pro: "vaccine-notifications-pro"
throughput:
dev: 1
pro: 10
pro: 2
update_centres_time:
dev: 21600
pro: 1200
Expand Down
5 changes: 5 additions & 0 deletions src/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def handle_generic_message(update):
if age >= min_years:
message = "‼️ ¡Ey! Parece que el sistema ya te permite pedir cita. Hazlo ya en 🔗 " \
"https://autocitavacuna.sanidadmadrid.org/ohcitacovid/"
elif age < 12:
message = "Lo siento 🥺, pero no hay vacunas 💉 aprobadas para menores de 12 años y por tanto no parece " \
"que el sistema te vaya a permitir en algún momento solicitar cita. Aún así, siempre puedes " \
"consultar /currentage para obtener la edad mínima con la que el sistema de autocita permite " \
"pedir citas."
else:
user_notification = db.get_user_notification(user_id)
db.save_notification(user_id, user_name, age)
Expand Down
32 changes: 29 additions & 3 deletions tests/unit/test_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ def test_given_age_above_min_years_when_handle_generic_then_you_can_already_join
get_min_years_mock.assert_called_once_with()


@patch("src.message_handler.db.get_min_years", return_value=45)
@patch("src.message_handler.get_age", return_value=11)
@patch("src.message_handler.db")
def test_given_age_above_min_years_when_handle_generic_then_you_can_already_join(db_mock, get_age_mock,
get_min_years_mock):
text = MagicMock()
user_id = MagicMock()
first_name = "Aitor"

result = message_handler.handle_generic_message({
"message": {
"text": text,
"from": {
"id": user_id,
"first_name": first_name
}
}
})

assert "aprobadas para menores de 12 años" in result

get_age_mock.assert_called_once_with(text)
get_min_years_mock.assert_called_once_with()
db_mock.save_notification.assert_not_called()


@patch("src.message_handler.db.get_min_years", return_value=45)
@patch("src.message_handler.get_age", return_value=None)
def test_given_no_age_when_handle_generic_then_not_understood(get_age_mock, get_min_years_mock):
Expand All @@ -69,7 +95,7 @@ def test_given_no_age_when_handle_generic_then_not_understood(get_age_mock, get_

@freeze_time("2021-06-23")
@patch("src.message_handler.db.get_min_years", return_value=45)
@patch("src.message_handler.get_age", return_value=44)
@patch("src.message_handler.get_age", return_value=12)
@patch("src.message_handler.db")
def test_given_below_when_handle_generic_then_subscription(db_mock, get_age_mock, get_min_years_mock):
text = MagicMock()
Expand All @@ -87,12 +113,12 @@ def test_given_below_when_handle_generic_then_subscription(db_mock, get_age_mock
}
})

assert "permita pedir cita a gente nacida en 1977" in result
assert "permita pedir cita a gente nacida en 2009" in result
assert "Ya tenías" not in result

get_age_mock.assert_called_once_with(text)
get_min_years_mock.assert_called_once_with()
db_mock.save_notification.assert_called_once_with(user_id, first_name, 44)
db_mock.save_notification.assert_called_once_with(user_id, first_name, 12)


@freeze_time("2021-06-23")
Expand Down

0 comments on commit 6f530b2

Please sign in to comment.