package kz.konturai.parser.service;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class SocialPostTextFormatterTest {

    @Test
    void buildPostTextShouldAlwaysAppendContactsBeforeHashtags() {
        String text = SocialPostTextFormatter.buildPostText("Новый продукт", List.of("ai", "#crm"));

        assertEquals(
                "Новый продукт\n\n" +
                        "telegram - https://t.me/konturaibot\n" +
                        "номер для звонка - tel:+77273901485\n\n" +
                        "#ai #crm",
                text);
    }

    @Test
    void buildPostTextShouldIncludeContactsWhenPostTextAndHashtagsAreMissing() {
        String text = SocialPostTextFormatter.buildPostText(null, List.of());

        assertEquals(SocialPostTextFormatter.CONTACTS_BLOCK, text);
    }

    @Test
    void buildPostTextShouldPreserveContactsWithinTelegramLimit() {
        String longPostText = "A".repeat(1_100);

        String text = SocialPostTextFormatter.buildPostText(longPostText, List.of("marketing"), 120);

        assertTrue(text.length() <= 120);
        assertTrue(text.contains("telegram - https://t.me/konturaibot"));
        assertTrue(text.contains("номер для звонка - tel:+77273901485"));
        assertTrue(text.endsWith("#marketing"));
    }
}
