Repository navigation
Fix clock-out and the midnight auto clock-out - #34
Merged
Merged
Conversation
MODE=MSSQLServer makes H2 allow only one NULL in a unique index, as SQL Server does. On SQL Server that is harmless here: Hibernate's SQL Server dialect creates filtered unique indexes (WHERE col IS NOT NULL) for nullable @OnetoOne columns. Hibernate's H2 dialect creates plain unique indexes, so under this mode a second open time clock shift (out_id NULL) was rejected in tests although SQL Server accepts it. The mode bought nothing else: the H2 dialect generates H2 SQL, and the project's @query methods are JPQL, not native SQL. [Ticket: #15] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
findCurrentTimeClockPunchSetByUser calls Instant.from() on the punch set's LocalDate, left over from the Date to LocalDate migration. It always throws, so any employee with a punch set cannot clock out, and the midnight auto-clock-out job fails too. The midnight tests also cover a second problem behind the first. The job clocks each user out through clockOut(), which looks for today's open shift. At 00:00 the shift being closed started the day before, so it would never be found. The job must close the specific shift it selected, and one bad shift must not stop the rest. [Ticket: #15] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Find today's shift with findByEmployeeAndDate instead of loading every shift for the employee and converting each LocalDate through Instant, which always threw. Removes the Calendar-based isToday helper left over from the Date to LocalDate migration. - Add closeTimeClockPunchSet to close a specific shift; clockOut uses it after finding today's shift. - The midnight job now loads only open shifts (findByOutIsNull, not every shift ever recorded) and closes each one directly, since a shift open at 00:00 started the previous day. Each shift closes in its own transaction, and a failure is logged instead of aborting the rest of the run. [Ticket: #15] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15
What
Fixes clock-out, and fixes the midnight auto-clock-out job, which had a second bug hidden behind the first.
1. Clock-out always threw.
findCurrentTimeClockPunchSetByUserpassed each shift'sLocalDatethroughInstant.from(). That conversion is impossible, because aLocalDatehas no time or zone, so it threwDateTimeExceptionfor any employee with a shift on record. This was left over from theDate→LocalDatemigration in October 2024. Today's shift is now found with the repository's existingfindByEmployeeAndDate, a database query instead of loading every shift for the employee and filtering in Java. TheCalendar-basedisTodayhelper is gone.2. The midnight job could never have worked. It clocked each open shift out through
clockOut(username), which looks for today's open shift. At 00:00, "today" is already the next day and the shift being closed started the day before, so fixing the crash alone would have turned it into aTimeClockExceptionfor every employee. The first exception also ended the loop for everyone.closeTimeClockPunchSet(shift, code)closes a specific shift.clockOutand the job both use it.findByOutIsNull) instead of every shift ever recorded.Test profile change
Writing a test with two open shifts turned up a unique-index violation on
time_clock_punch_sets.out_id. That is an artifact of the test setup, not a production bug:@OneToOnecolumns (WHERE out_id IS NOT NULL, visible indatabase_init.sql), so any number of open shifts is fine.MODE=MSSQLServerapplies SQL Server's one-NULL rule, but the H2 dialect creates plain unique indexes, so the combination rejects data SQL Server accepts.The mode is removed from the test profile. It bought nothing else: the H2 dialect generates H2 SQL, and the project's
@Querymethods are JPQL. All other suites pass unchanged, with 0 DDL errors.Tests
TimeClockServiceImpTest, Spring context + H2, committed failing first:clockedInDateTimeExceptionTimeClockExceptionSYSTEMDateTimeExceptionDateTimeExceptionFor the last test I confirmed from the log that the broken shift really does fail (
Could not auto clock out time clock punch set 1, caused by its missing pay period). The test isn't passing vacuously.38 tests passing overall.
🤖 Generated with Claude Code