<commit_before>%% -*- coding: utf-8 -*-
-module(addlog_SUITE).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

-compile(export_all).

suite() ->
    [{timetrap,{minutes,1}}].

all() -> [
    test1,
    post_version_of_addlog_method,
    cyrillic_addlog_test,
    strange_imei_addlog_test,
    hwid,
    balance
].

% -define(POINT_PORT, 8981).

init_per_suite(Config) ->
    helper:start(Config).

end_per_suite(Config) ->
    helper:stop(Config).

init_per_testcase(_Case, Config) ->
    Imei = helper:random_string(),
    [{imei, Imei} | Config].

end_per_testcase(_Case, Config) ->
    Config.

test1(Config) ->
    Text = helper:random_string(),
    {200, _, <<"ADDLOG: OK\r\n">>} = helper:get(Config, "/addlog", #{text => Text}),

    Skey = base64:encode(?config(imei, Config)),
    [Doc] = navidb:get_logs(Skey, 20, 100000000000),
    ?assertMatch(#{system := Skey, text := Text}, Doc),
    ok.

post_version_of_addlog_method(Config) ->
    % Text = list_to_binary(helper:url_encode(helper:random_string())),
    Text = <<"Что, суки, не ждали?"/utf8>>,
    TextEncoded = list_to_binary(helper:url_encode(Text)),
    {200, _, <<"ADDLOG: OK\r\n">>} = helper:post(Config, "/addlog", #{}, TextEncoded),

    Skey = base64:encode(?config(imei, Config)),
    [Doc] = navidb:get_logs(Skey, 20, 100000000000),

    ?assertMatch(#{system := Skey, text := Text}, Doc),
    ok.

cyrillic_addlog_test(Config) ->
    Text = <<"Текст на русском и не только ."/utf8>>,<commit_msg>Добавлены символы emoji в тест с кирилическим сообщением.<commit_after>%% -*- coding: utf-8 -*-
-module(addlog_SUITE).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

-compile(export_all).

suite() ->
    [{timetrap,{minutes,1}}].

all() -> [
    test1,
    post_version_of_addlog_method,
    cyrillic_addlog_test,
    strange_imei_addlog_test,
    hwid,
    balance
].

% -define(POINT_PORT, 8981).

init_per_suite(Config) ->
    helper:start(Config).

end_per_suite(Config) ->
    helper:stop(Config).

init_per_testcase(_Case, Config) ->
    Imei = helper:random_string(),
    [{imei, Imei} | Config].

end_per_testcase(_Case, Config) ->
    Config.

test1(Config) ->
    Text = helper:random_string(),
    {200, _, <<"ADDLOG: OK\r\n">>} = helper:get(Config, "/addlog", #{text => Text}),

    Skey = base64:encode(?config(imei, Config)),
    [Doc] = navidb:get_logs(Skey, 20, 100000000000),
    ?assertMatch(#{system := Skey, text := Text}, Doc),
    ok.

post_version_of_addlog_method(Config) ->
    % Text = list_to_binary(helper:url_encode(helper:random_string())),
    Text = <<"Что, суки, не ждали?"/utf8>>,
    TextEncoded = list_to_binary(helper:url_encode(Text)),
    {200, _, <<"ADDLOG: OK\r\n">>} = helper:post(Config, "/addlog", #{}, TextEncoded),

    Skey = base64:encode(?config(imei, Config)),
    [Doc] = navidb:get_logs(Skey, 20, 100000000000),

    ?assertMatch(#{system := Skey, text := Text}, Doc),
    ok.

cyrillic_addlog_test(Config) ->
    Text = <<"Текст на русском и не только 🤘🐱🌧☠."/utf8>>,
{'fraction_non_alphanumeric': 0.18729641693811075, 'fraction_numerical': 0.031270358306188926, 'mean_word_length': 4.07603305785124, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '316104', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1218, 'n_words': 192}