37 lines
1.3 KiB
Erlang
37 lines
1.3 KiB
Erlang
-module(api_tickets_tests).
|
|
-export([test/0]).
|
|
|
|
-define(BASE_URL, "http://localhost:8080").
|
|
|
|
test() ->
|
|
io:format("Testing tickets API...~n"),
|
|
|
|
AdminToken = api_test_runner:get_admin_token(),
|
|
UserToken = api_test_runner:get_user_token(),
|
|
|
|
% TEST 1: Report error
|
|
io:format(" TEST 1: Report error... "),
|
|
TicketId = api_test_runner:extract_json(
|
|
api_test_runner:http_post("/v1/tickets",
|
|
#{error_message => <<"Test bug">>, stacktrace => <<"line 1">>}, UserToken), <<"id">>),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 2: Admin views tickets
|
|
io:format(" TEST 2: Admin views tickets... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/admin/tickets", AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 3: Update ticket status
|
|
io:format(" TEST 3: Update ticket status... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_put("/v1/admin/tickets/" ++ binary_to_list(TicketId),
|
|
#{action => <<"status">>, status => <<"in_progress">>}, AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 4: Close ticket
|
|
io:format(" TEST 4: Close ticket... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_put("/v1/admin/tickets/" ++ binary_to_list(TicketId),
|
|
#{action => <<"close">>}, AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
io:format("~n✅ Tickets API tests passed!~n"),
|
|
{?MODULE, ok}. |