
    o5j	                         d dl m Z  d dlZd dlZd dlmZ d dlmZmZ  G d dej                        Z	e
dk(  r ej                          yy)    )datetimeN)ZoneInfo)TenantStore_timeclock_cutoff_afterc                   $    e Zd ZddZddZddZy)TimeclockAutoCloseTestsNc                     t        d      }t        ddddd|      }| j                  t        |      t        ddddd|             y )	NEurope/Rome              tzinfor   r   r   assertEqualr   selfrome
started_ats      3apps/backend-hub/tests/test_timeclock_auto_close.py4test_cutoff_is_same_day_for_shift_started_before_sixzLTimeclockAutoCloseTests.test_cutoff_is_same_day_for_shift_started_before_six
   sI    &dAr1b>
0<htQPRTUWXae>fg    c                     t        d      }t        ddddd|      }| j                  t        |      t        ddddd	|             y )
Nr
   r   r         *   r   r   r   r   r   s      r   3test_cutoff_is_next_day_for_shift_started_after_sixzKTimeclockAutoCloseTests.test_cutoff_is_next_day_for_shift_started_after_six   sI    &dAr2r$?
0<htQPRTUWXae>fgr   c           
         t        j                  d      }t         j                  |_        |j	                  d       |j	                  d       t        j                  t
              }t        dddddt        d	      
      }|j                  ||      }|j                  ||      }|j	                  d      j                         }|j                          | j                  t        |      d       | j                  |g        | j                  |d   d       | j                  |d   d       | j                  |d   d       | j                  d|d          y )Nz:memory:a  
            CREATE TABLE tenant_timeclock_entries (
                id TEXT PRIMARY KEY,
                user_id TEXT NOT NULL,
                user_name TEXT,
                started_at TEXT NOT NULL,
                ended_at TEXT,
                duration_seconds INTEGER,
                ended_source TEXT,
                notes TEXT,
                updated_at TEXT
            )
            z
            INSERT INTO tenant_timeclock_entries (id, user_id, user_name, started_at)
            VALUES ('shift-1', 'user-1', 'Dipendente', '2026-06-18T16:42:00+02:00')
            r   r   r      r   r
   r   )nowziSELECT ended_at, duration_seconds, ended_source, notes FROM tenant_timeclock_entries WHERE id = 'shift-1'   ended_atz2026-06-19T06:00:00+02:00duration_secondsi  ended_sourceautomatic_cutoff_06_00z06:00notes)sqlite3connectRowrow_factoryexecuter   __new__r   r   +_auto_close_timeclock_entries_in_connectionfetchonecloser   lenassertIn)r   
connectionstorer"   firstsecondsaveds          r   'test_stale_shift_is_closed_idempotentlyz?TimeclockAutoCloseTests.test_stale_shift_is_closed_idempotently   s>   __Z0
!(
	
 		
 ##K0tQAq-1HIAA*RUAVBB:SVBW""w

(* 	 	UQ'$z*,GH12E:~.0HIguW~.r   )returnN)__name__
__module____qualname__r   r   r9    r   r   r   r   	   s    h
h
'/r   r   __main__)r   r)   unittestzoneinfor   app.services.tenant_storer   r   TestCaser   r;   mainr>   r   r   <module>rE      sA        J2/h// 2/j zHMMO r   