Skip to content

Commit

Permalink
More unittests for mmynapi_decode:to_header
Browse files Browse the repository at this point in the history
Test all error checking paths in to_header/1

Signed-off-by: Essien Ita Essien <essiene@gmail.com>
  • Loading branch information
essiene committed Sep 8, 2011
1 parent 84813c9 commit a729aca
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions test/mmynapi_decode_tests.erl
Expand Up @@ -11,6 +11,37 @@ decode_header_test_() ->
{<<"vsn">>, [2,0,1]},
{<<"type">>, <<"req.sendsms">>},
{<<"system">>, <<"mmyn">>},
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))}
].
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))},
{"Error out when header JSON form is missing a 'vsn' field",
?_assertEqual({error, no_version},
mmynapi_decode:to_header({[
{<<"type">>, <<"req.sendsms">>},
{<<"system">>, <<"mmyn">>},
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))},
{"Error out when header 'vsn' field is wrong",
?_assertEqual({error, {wrong_msg_vsn, [{current_msg_vsn, [2,0,1]}, {parsed_msg_vsn,[3,2,1]}]}},
mmynapi_decode:to_header({[
{<<"type">>, <<"req.sendsms">>},
{<<"vsn">>, [3,2,1]},
{<<"system">>, <<"mmyn">>},
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))},
{"Error out when header JSON form is missing a 'type' field",
?_assertEqual({error, no_type},
mmynapi_decode:to_header({[
{<<"vsn">>, [2,0,1]},
{<<"system">>, <<"mmyn">>},
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))},
{"Error out when header JSON form is missing a 'system' field",
?_assertEqual({error, no_system},
mmynapi_decode:to_header({[
{<<"vsn">>, [2,0,1]},
{<<"type">>, <<"res.sendsms">>},
{<<"transaction_id">>, <<"0xdeadbeef">>}]}))},
{"Error out when header JSON form is missing a 'transaction_id' field",
?_assertEqual({error, no_transaction_id},
mmynapi_decode:to_header({[
{<<"vsn">>, [2,0,1]},
{<<"system">>, <<"mmyn">>},
{<<"type">>, <<"res.sendsms">>}]}))}
].

0 comments on commit a729aca

Please sign in to comment.