Stage 10 final
This commit is contained in:
61
test/api/api_calendar_tests.erl
Normal file
61
test/api/api_calendar_tests.erl
Normal file
@@ -0,0 +1,61 @@
|
||||
-module(api_calendar_tests).
|
||||
-export([test/0]).
|
||||
|
||||
-define(BASE_URL, "http://localhost:8080").
|
||||
|
||||
test() ->
|
||||
io:format("Testing calendar API...~n"),
|
||||
|
||||
OwnerEmail = api_test_runner:unique_email(<<"cal_owner">>),
|
||||
OtherEmail = api_test_runner:unique_email(<<"cal_other">>),
|
||||
|
||||
OwnerToken = api_test_runner:register_and_login(OwnerEmail, <<"owner123">>),
|
||||
OtherToken = api_test_runner:register_and_login(OtherEmail, <<"other123">>),
|
||||
|
||||
% TEST 1: Create personal calendar
|
||||
io:format(" TEST 1: Create personal calendar... "),
|
||||
CalId = api_test_runner:extract_json(
|
||||
api_test_runner:http_post("/v1/calendars",
|
||||
#{title => <<"Personal">>, type => <<"personal">>}, OwnerToken), <<"id">>),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 2: Create commercial calendar
|
||||
io:format(" TEST 2: Create commercial calendar... "),
|
||||
CommId = api_test_runner:extract_json(
|
||||
api_test_runner:http_post("/v1/calendars",
|
||||
#{title => <<"Commercial">>, type => <<"commercial">>}, OwnerToken), <<"id">>),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 3: List calendars
|
||||
io:format(" TEST 3: List calendars... "),
|
||||
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/calendars", OwnerToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 4: Get personal calendar (owner)
|
||||
io:format(" TEST 4: Get personal calendar... "),
|
||||
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/calendars/" ++ binary_to_list(CalId), OwnerToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 5: Get personal calendar (other - denied)
|
||||
io:format(" TEST 5: Get personal calendar (other)... "),
|
||||
{ok, {{_, 403, _}, _, _}} = api_test_runner:http_get("/v1/calendars/" ++ binary_to_list(CalId), OtherToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 6: Get commercial calendar (other - allowed)
|
||||
io:format(" TEST 6: Get commercial calendar (other)... "),
|
||||
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/calendars/" ++ binary_to_list(CommId), OtherToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 7: Update calendar
|
||||
io:format(" TEST 7: Update calendar... "),
|
||||
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_put("/v1/calendars/" ++ binary_to_list(CalId),
|
||||
#{title => <<"Updated">>}, OwnerToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
% TEST 8: Delete calendar
|
||||
io:format(" TEST 8: Delete calendar... "),
|
||||
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_delete("/v1/calendars/" ++ binary_to_list(CalId), OwnerToken),
|
||||
io:format("OK~n"),
|
||||
|
||||
io:format("~n✅ Calendar API tests passed!~n"),
|
||||
{?MODULE, ok}.
|
||||
Reference in New Issue
Block a user