forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAZOO-6108: check order of users after sort/filter (2600hz#5873)
Mostly adding testing to ensure sort/filter is working as expected
- Loading branch information
1 parent
b64ebbc
commit 9992053
Showing
3 changed files
with
103 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-ifndef(CF_DIRECTORY_HRL). | ||
|
||
-record(directory_user, {first_name :: kz_term:ne_binary() | ||
,last_name :: kz_term:ne_binary() | ||
,full_name :: kz_term:ne_binary() | ||
,first_last_keys :: kz_term:ne_binary() % DTMF-version of first, last | ||
,last_first_keys :: kz_term:ne_binary() % DTMF-version of last, first | ||
,callflow_id :: kz_term:ne_binary() % what callflow to use on match | ||
,name_audio_id :: kz_term:api_binary() % pre-recorded audio of user's name | ||
}). | ||
-type directory_user() :: #directory_user{}. | ||
-type directory_users() :: [directory_user()]. | ||
|
||
-type search_field() :: 'first' | 'last' | 'both'. | ||
|
||
-record(directory, {sort_by = 'last' :: 'first' | 'last' | ||
,search_fields = 'both' :: search_field() | ||
,min_dtmf :: pos_integer() | ||
,max_dtmf :: non_neg_integer() | ||
,confirm_match = 'false' :: boolean() | ||
,digits_collected = <<>> :: binary() | ||
,users = [] :: directory_users() | ||
,curr_users = [] :: directory_users() | ||
}). | ||
-type directory() :: #directory{}. | ||
|
||
-type dtmf_action() :: 'route' | 'next' | 'start_over' | 'invalid' | 'continue'. | ||
|
||
-define(CF_DIRECTORY_HRL, 'true'). | ||
-endif. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-module(cf_directory_tests). | ||
|
||
-include_lib("eunit/include/eunit.hrl"). | ||
-include_lib("callflow/src/module/cf_directory.hrl"). | ||
|
||
-define(NAMES, [{<<"Terry">>, <<"White">>} | ||
,{<<"Empty">>, <<"158">>} | ||
,{<<"Alyssa">>, <<"Gruzwalski">>} | ||
,{<<"Lauren">>, <<"Underwood">>} | ||
,{<<"Julie">>, <<"Bloomenstein">>} | ||
,{<<"Laurie">>, <<"Zeidman">>} | ||
,{<<"Empty">>, <<"162">>} | ||
,{<<"NaChelle">>, <<"Webster">>} | ||
,{<<"Robert">>, <<"Sosin">>} | ||
,{<<"Dawna">>, <<"Wilson">>} | ||
,{<<"Greg">>, <<"Shanaberger">>} | ||
,{<<"Mort">>, <<"Noveck">>} | ||
,{<<"Rob">>, <<"Lech">>} | ||
,{<<"Jessica">>, <<"Kalvenas">>} | ||
,{<<"Ralph">>, <<"Sosin">>} | ||
,{<<"Empty">>, <<"160">>} | ||
,{<<"Daniel">>, <<"Noveck">>} | ||
]). | ||
|
||
-define(DIR_USERS, [cf_directory:get_directory_user(kz_json:from_list([{<<"first_name">>, First} | ||
,{<<"last_name">>, Last} | ||
]) | ||
,'undefined' | ||
) | ||
|| {First, Last} <- ?NAMES | ||
]). | ||
|
||
sort_order_test_() -> | ||
[#directory_user{first_name=Alpha} | _] = cf_directory:sort_users(?DIR_USERS, 'first'), | ||
[#directory_user{last_name=Omega} | _] = cf_directory:sort_users(?DIR_USERS, 'last'), | ||
[{"Sort by first name", ?_assertEqual(<<"Alyssa">>, Alpha)} | ||
,{"Sort by last name", ?_assertEqual(<<"158">>, Omega)} | ||
]. | ||
|
||
filter_users_test_() -> | ||
SortedFirst = cf_directory:sort_users(?DIR_USERS, 'first'), | ||
SortedLast = cf_directory:sort_users(?DIR_USERS, 'last'), | ||
|
||
[#directory_user{first_name=AlphaFirst} | _] | ||
= cf_directory:filter_users(SortedFirst, <<"528">>, 'first'), | ||
|
||
[#directory_user{last_name=OmegaLast | ||
,first_name=OmegaFirst | ||
} | _] | ||
= cf_directory:filter_users(SortedLast, <<"668">>, 'last'), | ||
|
||
[{"Filtered first_name sort", ?_assertEqual(<<"Lauren">>, AlphaFirst)} | ||
,{"Filtered last_name sort - last name", ?_assertEqual(<<"Noveck">>, OmegaLast)} | ||
,{"Filtered last_name sort - first name", ?_assertEqual(<<"Daniel">>, OmegaFirst)} | ||
]. |