36 lines
1.3 KiB
Erlang
36 lines
1.3 KiB
Erlang
-module(api_subscription_tests).
|
|
-export([test/0]).
|
|
|
|
-define(BASE_URL, api_test_runner:get_base_url()).
|
|
|
|
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}. |