"""用户下拉选项:同部门优先排序。""" from app.services.user_select_options import prioritize_caller_dept_options def test_prioritize_caller_dept_keeps_relative_order(): options = [ {"label": "外1", "value": "a", "deptId": "d2"}, {"label": "同1", "value": "b", "deptId": "d1"}, {"label": "外2", "value": "c", "deptId": "d3"}, {"label": "同2", "value": "d", "deptId": "d1"}, {"label": "无部门", "value": "e", "deptId": ""}, ] out = prioritize_caller_dept_options(options, "d1") assert [x["value"] for x in out] == ["b", "d", "a", "c", "e"] def test_prioritize_caller_dept_noop_without_caller_dept(): options = [ {"label": "a", "value": "a", "deptId": "d1"}, {"label": "b", "value": "b", "deptId": "d2"}, ] assert prioritize_caller_dept_options(options, "") == options assert prioritize_caller_dept_options(options, " ") == options def test_prioritize_caller_dept_empty_list(): assert prioritize_caller_dept_options([], "d1") == []