Stage 10 final

This commit is contained in:
2026-04-22 23:15:20 +03:00
parent e3a08cfa04
commit 081dcf9588
85 changed files with 2116 additions and 160 deletions

View File

@@ -0,0 +1,36 @@
-module(api_subscription_tests).
-export([test/0]).
-define(BASE_URL, "http://localhost:8080").
test() ->
io:format("Testing subscription API...~n"),
UserEmail = api_test_runner:unique_email(<<"sub_user">>),
UserToken = api_test_runner:register_and_login(UserEmail, <<"user123">>),
% TEST 1: Get subscription (free)
io:format(" TEST 1: Get subscription (free)... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/subscription", UserToken),
io:format("OK~n"),
% TEST 2: Create commercial calendar (auto-activates trial)
io:format(" TEST 2: Create commercial calendar... "),
api_test_runner:extract_json(
api_test_runner:http_post("/v1/calendars",
#{title => <<"Commercial">>, type => <<"commercial">>}, UserToken), <<"id">>),
io:format("OK~n"),
% TEST 3: Get subscription (trial)
io:format(" TEST 3: Get subscription (trial)... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/subscription", UserToken),
io:format("OK~n"),
% TEST 4: Activate paid subscription
io:format(" TEST 4: Activate paid subscription... "),
{ok, {{_, 201, _}, _, _}} = api_test_runner:http_post("/v1/subscription",
#{action => <<"activate">>, plan => <<"monthly">>, payment_info => #{card => <<"4242">>}}, UserToken),
io:format("OK~n"),
io:format("~n✅ Subscription API tests passed!~n"),
{?MODULE, ok}.