Skip to content

Commit 1a075a0

Browse files
feat: Add tests back for citations
1 parent 0ef2c8b commit 1a075a0

File tree

3 files changed

+84
-23
lines changed

3 files changed

+84
-23
lines changed

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def convert_markdown_to_slack(body: str) -> str:
279279
body = re.sub(r"\*\*([^*]+)\*\*", r"*\1*", body)
280280

281281
# 4. Handle Lists (Handle various bullet points and dashes, inc. unicode support)
282-
body = re.sub(r"(\u2022|-|•)\s", r"\n\g<0>", body)
282+
body = re.sub(r"\s+(?:-|\u2022)(\s*)", r"\n- ", body)
283283

284284
# 5. Convert Markdown Links [text](url) to Slack <url|text>
285285
body = re.sub(r"\[([^\]]+)\]\(([^\)]+)\)", r"<\2|\1>", body)

packages/slackBotFunction/tests/test_slack_events/test_slack_events_citations.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,7 @@ def test_create_response_body_creates_body_with_lists(
569569
del sys.modules["app.slack.slack_events"]
570570
from app.slack.slack_events import _create_response_body
571571

572-
dirty_input = (
573-
"Header text"
574-
"\\n- Standard Dash" # Literal \n + dash
575-
"-No Space Dash" # Dash with no spacing
576-
"– En Dash" # Unicode En-dash
577-
"— Em Dash" # Unicode Em-dash
578-
"\n▪ Square Bullet" # Real newline + Square
579-
" ‣ Triangle Bullet" # Space + Triangle
580-
" ◦ Hollow Bullet" # Space + Hollow
581-
"\\n• Standard Bullet" # Literal \n + Bullet
582-
)
572+
dirty_input = "Header text - Standard Dash -No Space Dash • Standard Bullet -NoSpace-NoSpace"
583573

584574
# perform operation
585575
response = _create_response_body(
@@ -603,17 +593,7 @@ def test_create_response_body_creates_body_with_lists(
603593
citation_element = response[1]["elements"][0]
604594
citation_value = json.loads(citation_element["value"])
605595

606-
expected_output = (
607-
"Header text\n"
608-
"- Standard Dash\n"
609-
"- No Space Dash\n"
610-
"- En Dash\n"
611-
"- Em Dash\n"
612-
"- Square Bullet\n"
613-
"- Triangle Bullet\n"
614-
"- Hollow Bullet\n"
615-
"- Standard Bullet"
616-
)
596+
expected_output = "Header text\n- Standard Dash\n- No Space Dash\n- Standard Bullet\n- NoSpace-NoSpace"
617597
assert expected_output in citation_value.get("body")
618598

619599

packages/slackBotFunction/tests/test_slack_events/test_slack_events_messages.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,84 @@ def test_cleanup_previous_unfeedback_qa_same_message(
416416

417417
# assertions
418418
mock_delete_state_information.assert_not_called()
419+
420+
421+
def test_create_response_body_creates_body_with_markdown_formatting(
422+
mock_get_parameter: Mock,
423+
mock_env: Mock,
424+
):
425+
"""Test regex text processing functionality within process_async_slack_event"""
426+
# delete and import module to test
427+
if "app.slack.slack_events" in sys.modules:
428+
del sys.modules["app.slack.slack_events"]
429+
from app.slack.slack_events import _create_response_body
430+
431+
# perform operation
432+
response = _create_response_body(
433+
citations=[],
434+
feedback_data={},
435+
response_text="**Bold**, __italics__, *markdown italics*, and `code`.",
436+
)
437+
438+
# assertions
439+
assert len(response) > 0
440+
assert response[0]["type"] == "section"
441+
442+
response_value = response[0]["text"]["text"]
443+
444+
assert "*Bold*, _italics_, _markdown italics_, and `code`." in response_value
445+
446+
447+
def test_create_response_body_creates_body_with_lists(
448+
mock_get_parameter: Mock,
449+
mock_env: Mock,
450+
):
451+
"""Test regex text processing functionality within process_async_slack_event"""
452+
# delete and import module to test
453+
if "app.slack.slack_events" in sys.modules:
454+
del sys.modules["app.slack.slack_events"]
455+
from app.slack.slack_events import _create_response_body
456+
457+
dirty_input = "Header text - Standard Dash -No Space Dash • Standard Bullet -NoSpace-NoSpace"
458+
459+
# perform operation
460+
response = _create_response_body(
461+
citations=[],
462+
feedback_data={},
463+
response_text=dirty_input,
464+
)
465+
466+
# assertions
467+
assert len(response) > 0
468+
assert response[0]["type"] == "section"
469+
470+
response_value = response[0]["text"]["text"]
471+
472+
expected_output = "Header text\n- Standard Dash\n- No Space Dash\n- Standard Bullet\n- NoSpace-NoSpace"
473+
assert expected_output in response_value
474+
475+
476+
def test_create_response_body_creates_body_without_encoding_errors(
477+
mock_get_parameter: Mock,
478+
mock_env: Mock,
479+
):
480+
"""Test regex text processing functionality within process_async_slack_event"""
481+
# delete and import module to test
482+
if "app.slack.slack_events" in sys.modules:
483+
del sys.modules["app.slack.slack_events"]
484+
from app.slack.slack_events import _create_response_body
485+
486+
# perform operation
487+
response = _create_response_body(
488+
citations=[],
489+
feedback_data={},
490+
response_text="» Tabbing Issue. ⢠Bullet point issue.",
491+
)
492+
493+
# assertions
494+
assert len(response) > 0
495+
assert response[0]["type"] == "section"
496+
497+
response_value = response[0]["text"]["text"]
498+
499+
assert "Tabbing Issue.\n- Bullet point issue." in response_value

0 commit comments

Comments
 (0)