forked from OpenTelecom/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrossbar_doc_tests.erl
48 lines (40 loc) · 2.29 KB
/
crossbar_doc_tests.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2011-2018, 2600Hz
%%% @doc
%%% @author Karl Anderson
%%% @author James Aimonetti
%%% @end
%%%-----------------------------------------------------------------------------
-module(crossbar_doc_tests).
-include_lib("eunit/include/eunit.hrl").
patch_test_() ->
RequestData = kz_json:from_list([{<<"enabled">>, 'true'}]),
ExistingDoc = kz_json:from_list([{<<"foo">>, <<"bar">>}
,{<<"enabled">>, 'false'}
,{<<"elbow">>, <<"grease">>}
]),
PatchedJObj = crossbar_doc:patch_the_doc(RequestData, ExistingDoc),
[?_assert(kz_json:is_true(<<"enabled">>, PatchedJObj))].
patch_recursive_test_() ->
RequestData = kz_json:from_list([{<<"enabled">>, 'true'}
,{<<"sip">>, kz_json:from_list([{<<"username">>, <<"me123">>}])}
,{<<"new">>, <<"field">>}
,{<<"nested">>, kz_json:from_list([{<<"another">>, <<"one">>}])}
]),
ExistingDoc = kz_json:from_list([{<<"foo">>, <<"bar">>}
,{<<"enabled">>, 'false'}
,{<<"elbow">>, <<"grease">>}
,{<<"sip">>, kz_json:from_list([{<<"username">>, <<"foo">>}
,{<<"password">>, <<"bar">>}
]
)
}
]),
PatchedJObj = crossbar_doc:patch_the_doc(RequestData, ExistingDoc),
[?_assert(kz_json:is_true(<<"enabled">>, PatchedJObj))
,?_assertMatch(<<"grease">>, kz_json:get_value(<<"elbow">>, PatchedJObj))
,?_assertMatch(<<"field">>, kz_json:get_value(<<"new">>, PatchedJObj))
,?_assertMatch(<<"one">>, kz_json:get_value([<<"nested">>, <<"another">>], PatchedJObj))
,?_assertMatch(<<"me123">>, kz_json:get_value([<<"sip">>, <<"username">>], PatchedJObj))
,?_assertMatch(<<"bar">>, kz_json:get_value([<<"sip">>, <<"password">>], PatchedJObj))
].