from typer.testing import CliRunner

import os

from timerdo.main import app, sqlite_file_name
from timerdo.tables import ToDo, Timer
from sqlmodel import create_engine, Session, select
from datetime import datetime, timedelta

try:
    os.rename('/home/cmts/.config/timerdo/timerdo_db.db',
              '/home/cmts/.config/timerdo/timerdo_db_moved.db')
except FileNotFoundError:
    pass


sqlite_url = f'sqlite:///{sqlite_file_name}'

engine = create_engine(sqlite_url, echo=True)

runner = CliRunner()


def test_add_none():
    """Test add function with no argument"""
    result = runner.invoke(app, ['add'])

    assert result.exit_code == 2


def test_add_task():
    """Test add function with task argument"""
    task = 'test add'
    result = runner.invoke(app, ['add', task])
    with Session(engine) as session:
        query = session.exec(