launchmaxxing/tests/test_state.py
caelum0x 99d4f4f2ad feat: v2 -- SQLite history, submission tracking, launch-copy generator, outreach pipeline, UTM builder, status dashboard, launch report
Genuine v2 pass (not a cosmetic bump), grounded in a fresh competitive
landscape pass (Product Hunt alternatives, what's actually current in
2026, real founder pain points around launch checklists and outreach):

- launchmaxxing.db: local SQLite history layer (submission events,
  outreach contacts, content drafts, UTM links) alongside the existing
  JSON current-status state file. Still zero signup, zero server.
- submit: new primary command for directory submissions with full
  history (submit --history); platform-status kept as a working
  deprecated alias.
- content: local, template-based launch-copy generator for Product Hunt
  (tagline/description, limits enforced, hype words flagged), Show HN
  (real title format, hype stripped, 80-char limit), X/Twitter thread,
  Reddit post, LinkedIn post. No LLM call, no API key, deterministic.
- outreach: local creator/press/community/user contact pipeline plus
  per-channel cold-message drafts.
- utm: local UTM link builder with per-directory source/medium defaults,
  saved locally for whatever analytics you already run.
- track: cross-cutting status dashboard (directories/checklist/outreach/
  content) with stale/overdue reminders.
- report: shareable one-page Markdown launch summary.
- catalog: grew from 18 to 24 directories after verifying 6 new 2026
  entries live (PeerPush, Turbo0, Smol Launch, StartupBase, Microlaunch,
  Findly Tools); new ai_discovery category for AI-assistant-optimized
  listings like PeerPush.

173/173 tests passing, 98% coverage (up from 67/67 at 94%). Ruff-clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-18 14:37:01 +03:00

139 lines
6.4 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from launchmaxxing import state
def test_load_missing_file_returns_empty_state(tmp_path: Path) -> None:
result = state.load(tmp_path / "nope.json")
assert result == {"products": {}, "pain_point_drafts": []}
def test_load_corrupt_file_returns_empty_state(tmp_path: Path) -> None:
path = tmp_path / "state.json"
path.write_text("not json{{", encoding="utf-8")
assert state.load(path) == {"products": {}, "pain_point_drafts": []}
def test_save_then_load_round_trips(tmp_path: Path) -> None:
path = tmp_path / "sub" / "state.json"
app_state = state.load(path)
state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="submitted")
state.save(app_state, path)
reloaded = state.load(path)
assert reloaded["products"]["Acme"]["platforms"]["product_hunt"]["status"] == "submitted"
def test_set_platform_status_rejects_unknown_platform() -> None:
app_state = state.load(Path("/nonexistent"))
with pytest.raises(ValueError):
state.set_platform_status(app_state, product_name="Acme", platform_id="not_real", status="submitted")
def test_set_platform_status_rejects_bad_status() -> None:
app_state = state.load(Path("/nonexistent"))
with pytest.raises(ValueError):
state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="bogus")
def test_set_platform_status_sets_submitted_at_once() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
row = state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="submitted")
assert row["submitted_at"] is not None
first_submitted_at = row["submitted_at"]
row2 = state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="live")
assert row2["submitted_at"] == first_submitted_at
def test_set_platform_status_not_started_clears_submitted_at() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="live")
row = state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="not_started")
assert row["submitted_at"] is None
def test_get_platform_statuses_empty_for_unknown_product() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
assert state.get_platform_statuses(app_state, "Nobody") == {}
def test_set_step_status_rejects_unknown_step() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
with pytest.raises(ValueError):
state.set_step_status(app_state, product_name="Acme", step_key="not_real", status="done")
def test_set_step_status_round_trips() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
state.set_step_status(app_state, product_name="Acme", step_key="cold_outreach", status="done", note="emailed 20")
row = state.get_step_statuses(app_state, "Acme")["cold_outreach"]
assert row["status"] == "done"
assert row["note"] == "emailed 20"
def test_product_name_required() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
with pytest.raises(ValueError):
state.set_step_status(app_state, product_name=" ", step_key="cold_outreach", status="done")
def test_add_pain_point_drafts_dedupes_by_url_and_query() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
threads = [{"thread_url": "https://reddit.com/x/1", "thread_title": "T", "snippet": "s", "subreddit": "SaaS",
"upvotes": 5, "age_days": 1, "draft_reply": "r"}]
first = state.add_pain_point_drafts(app_state, query="q", product_name="Acme", threads=threads)
second = state.add_pain_point_drafts(app_state, query="q", product_name="Acme", threads=threads)
assert len(first) == 1
assert len(second) == 1
assert len(app_state["pain_point_drafts"]) == 1
def test_list_pain_point_drafts_filters_by_status_and_product() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
threads = [{"thread_url": "https://reddit.com/x/1", "thread_title": "T", "snippet": "s", "subreddit": "SaaS",
"upvotes": 5, "age_days": 1, "draft_reply": "r"}]
state.add_pain_point_drafts(app_state, query="q", product_name="Acme", threads=threads)
assert len(state.list_pain_point_drafts(app_state, status="drafted")) == 1
assert len(state.list_pain_point_drafts(app_state, status="approved")) == 0
assert len(state.list_pain_point_drafts(app_state, product_name="Other")) == 0
def test_set_draft_status_updates_and_rejects_bad_status() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
threads = [{"thread_url": "https://reddit.com/x/1", "thread_title": "T", "snippet": "s", "subreddit": "SaaS",
"upvotes": 5, "age_days": 1, "draft_reply": "r"}]
[draft] = state.add_pain_point_drafts(app_state, query="q", product_name="Acme", threads=threads)
updated = state.set_draft_status(app_state, draft["id"], "approved")
assert updated["status"] == "approved"
with pytest.raises(ValueError):
state.set_draft_status(app_state, draft["id"], "posted")
with pytest.raises(ValueError):
state.set_draft_status(app_state, "missing-id", "approved")
def test_default_path_uses_env_override(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LAUNCHMAXXING_STATE", "/tmp/custom-state.json")
assert state.default_path() == Path("/tmp/custom-state.json")
monkeypatch.delenv("LAUNCHMAXXING_STATE")
assert state.default_path() == state.DEFAULT_STATE_PATH
def test_get_product_created_at_set_on_first_touch() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
assert state.get_product_created_at(app_state, "Acme") is None
state.set_step_status(app_state, product_name="Acme", step_key="cold_outreach", status="pending")
created_at = state.get_product_created_at(app_state, "Acme")
assert created_at is not None
def test_get_product_created_at_stable_across_updates() -> None:
app_state = {"products": {}, "pain_point_drafts": []}
state.set_step_status(app_state, product_name="Acme", step_key="cold_outreach", status="pending")
first = state.get_product_created_at(app_state, "Acme")
state.set_platform_status(app_state, product_name="Acme", platform_id="product_hunt", status="submitted")
second = state.get_product_created_at(app_state, "Acme")
assert first == second