mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-09-30 15:53:13 +00:00
Some checks failed
Build Lambda Layer / build (push) Has been cancelled
* feat(meals): dual-read week keys and meal-to-Flex join (PLAT-134) * style(meals): apply ruff format (PLAT-134) * docs(meals): clarify week-key dual-read is same-instant (PLAT-134)
161 lines
4.2 KiB
Python
161 lines
4.2 KiB
Python
"""Tests for meal-order to Flex worker email join (fixture-driven, no HTTP)."""
|
|
|
|
import inspect
|
|
|
|
from shared.flex_join import JoinReport, JoinRow, join_orders_to_workers
|
|
|
|
|
|
def test_business_email_match():
|
|
orders = [
|
|
{"employee_email": "pat@seahaven.com", "employee_name": "Pat", "total": 12}
|
|
]
|
|
workers = [
|
|
{
|
|
"workerId": "W1",
|
|
"business_email": "pat@seahaven.com",
|
|
"personal_email": "pat@gmail.com",
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers, week="2026-W34")
|
|
|
|
assert report == JoinReport(
|
|
matched=(
|
|
JoinRow(
|
|
employee_email="pat@seahaven.com",
|
|
worker_id="W1",
|
|
matched_on="business",
|
|
),
|
|
),
|
|
unmatched=(),
|
|
week="2026-W34",
|
|
)
|
|
|
|
|
|
def test_fallback_to_personal_when_business_missing():
|
|
orders = [{"employee_email": "pat@gmail.com"}]
|
|
workers = [
|
|
{
|
|
"workerId": "W1",
|
|
"business_email": "",
|
|
"personal_email": " PAT@gmail.com ",
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert report.matched == (
|
|
JoinRow(
|
|
employee_email="pat@gmail.com",
|
|
worker_id="W1",
|
|
matched_on="personal",
|
|
),
|
|
)
|
|
assert report.unmatched == ()
|
|
|
|
|
|
def test_fallback_to_personal_when_business_mismatches():
|
|
orders = [{"employee_email": "alex@gmail.com"}]
|
|
workers = [
|
|
{
|
|
"workerId": "W2",
|
|
"business_email": "alex@seahaven.com",
|
|
"personal_email": "alex@gmail.com",
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert report.matched[0].matched_on == "personal"
|
|
assert report.matched[0].worker_id == "W2"
|
|
assert report.unmatched == ()
|
|
|
|
|
|
def test_unmatched_leftover():
|
|
orders = [
|
|
{"employee_email": "pat@seahaven.com"},
|
|
{"employee_email": "unknown@example.com"},
|
|
]
|
|
workers = [
|
|
{
|
|
"workerId": "W1",
|
|
"business_email": "pat@seahaven.com",
|
|
"personal_email": "pat@gmail.com",
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert len(report.matched) == 1
|
|
assert report.unmatched == ("unknown@example.com",)
|
|
|
|
|
|
def test_business_wins_over_personal_if_both_present():
|
|
orders = [{"employee_email": "sam@seahaven.com"}]
|
|
workers = [
|
|
{
|
|
"workerId": "W-personal",
|
|
"business_email": "other@seahaven.com",
|
|
"personal_email": "sam@seahaven.com",
|
|
},
|
|
{
|
|
"workerId": "W-business",
|
|
"business_email": "sam@seahaven.com",
|
|
"personal_email": "sam@gmail.com",
|
|
},
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert report.matched == (
|
|
JoinRow(
|
|
employee_email="sam@seahaven.com",
|
|
worker_id="W-business",
|
|
matched_on="business",
|
|
),
|
|
)
|
|
assert report.unmatched == ()
|
|
|
|
|
|
def test_same_worker_business_and_personal_same_email_is_business():
|
|
orders = [{"employee_email": "lee@seahaven.com"}]
|
|
workers = [
|
|
{
|
|
"workerId": "W3",
|
|
"business_email": "lee@seahaven.com",
|
|
"personal_email": "lee@seahaven.com",
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert report.matched[0].matched_on == "business"
|
|
assert report.matched[0].worker_id == "W3"
|
|
|
|
|
|
def test_nested_communications_used_when_flat_keys_missing():
|
|
orders = [{"employee_email": "pat@seahaven.com"}]
|
|
workers = [
|
|
{
|
|
"workerId": "W1",
|
|
"communications": [
|
|
{"type": "BUSINESS", "uri": "pat@seahaven.com"},
|
|
{"type": "PERSONAL", "uri": "pat@gmail.com"},
|
|
],
|
|
}
|
|
]
|
|
|
|
report = join_orders_to_workers(orders, workers)
|
|
|
|
assert report.matched[0].matched_on == "business"
|
|
assert report.matched[0].worker_id == "W1"
|
|
|
|
|
|
def test_flex_join_has_no_paychex_http():
|
|
import shared.flex_join as flex_join
|
|
|
|
source = inspect.getsource(flex_join)
|
|
assert "urllib" not in source
|
|
assert "api.paychex.com" not in source
|
|
assert "requests" not in source
|
|
assert "http.client" not in source
|