|
| 1 | +-module(my_first_nova_products_controller_tests). |
| 2 | +-include_lib("eunit/include/eunit.hrl"). |
| 3 | + |
| 4 | +list_returns_products_test() -> |
| 5 | + Req = #{}, |
| 6 | + Result = my_first_nova_products_controller:list(Req), |
| 7 | + ?assertMatch({json, #{products := [_|_]}}, Result). |
| 8 | + |
| 9 | +show_existing_product_test() -> |
| 10 | + Req = #{bindings => #{<<"id">> => <<"1">>}}, |
| 11 | + Result = my_first_nova_products_controller:show(Req), |
| 12 | + ?assertMatch({json, #{id := 1, name := _, price := _}}, Result). |
| 13 | + |
| 14 | +create_with_valid_params_test() -> |
| 15 | + Req = #{params => #{<<"name">> => <<"Widget">>, <<"price">> => 999}}, |
| 16 | + Result = my_first_nova_products_controller:create(Req), |
| 17 | + ?assertMatch({json, 201, #{}, #{id := 3, name := <<"Widget">>, price := 999}}, Result). |
| 18 | + |
| 19 | +create_missing_params_test() -> |
| 20 | + Req = #{}, |
| 21 | + Result = my_first_nova_products_controller:create(Req), |
| 22 | + ?assertMatch({status, 422, _, _}, Result). |
| 23 | + |
| 24 | +update_product_test() -> |
| 25 | + Req = #{bindings => #{<<"id">> => <<"1">>}, |
| 26 | + params => #{<<"name">> => <<"Updated">>, <<"price">> => 1500}}, |
| 27 | + Result = my_first_nova_products_controller:update(Req), |
| 28 | + ?assertMatch({json, #{id := 1, name := <<"Updated">>, price := 1500}}, Result). |
| 29 | + |
| 30 | +delete_product_test() -> |
| 31 | + Req = #{bindings => #{<<"id">> => <<"1">>}}, |
| 32 | + Result = my_first_nova_products_controller:delete(Req), |
| 33 | + ?assertMatch({status, 204}, Result). |
0 commit comments