fix: correctly calculate due dates for contract and invoice uploads
This commit is contained in:
@@ -83,6 +83,36 @@ class DispositionRepositoryTest extends KernelTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A short-notice assignment can end before the normal $deadlineDays window would even
|
||||
* start. Without the short-notice branch, that disposition's reminder day falls on or
|
||||
* after guardUploadContract() already blocks the upload, and gets missed by the
|
||||
* assignment-end-not-yet-reached guard on the normal branch.
|
||||
*/
|
||||
public function testContractReminderHasAShortNoticeBranchForEarlyAssignmentEnds(): void
|
||||
{
|
||||
$dql = $this->contractQuery()->getDQL();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'assignment.dateTo IS NOT NULL AND assignment.dateTo > :tomorrow',
|
||||
$dql
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'assignment.dateTo IS NOT NULL AND assignment.dateTo = :tomorrow',
|
||||
$dql
|
||||
);
|
||||
}
|
||||
|
||||
public function testContractReminderBindsTomorrowAsADateAndNotATimestamp(): void
|
||||
{
|
||||
$query = $this->contractQuery(5);
|
||||
|
||||
$this->assertSame(
|
||||
(new \DateTimeImmutable('today +1 day'))->format('Y-m-d'),
|
||||
$query->getParameter('tomorrow')->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The bug that killed this query: destination.dateTo and assignment.dateTo are DATE columns,
|
||||
* and Doctrine binds a DateTimeImmutable as 'Y-m-d H:i:s', which a DATE never equals.
|
||||
@@ -132,11 +162,48 @@ class DispositionRepositoryTest extends KernelTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* findOverdueContracts() lacked the assignment-status and teamer.deletedAt filters that
|
||||
* getContractReminderQuery() has, so the admin list and the reminder mail disagreed on
|
||||
* which dispositions counted, despite the docblock's claim that they stay in sync.
|
||||
*/
|
||||
public function testOverdueContractsSharesTheReminderQueryScope(): void
|
||||
{
|
||||
$dql = $this->overdueContractsQuery()->getDQL();
|
||||
|
||||
$this->assertStringContainsString('teamer.deletedAt IS NULL', $dql);
|
||||
$this->assertStringContainsString('assignment.status NOT IN(:assignmentStatus)', $dql);
|
||||
}
|
||||
|
||||
/**
|
||||
* findOverdueContracts() used to anchor on now(), while the reminder query anchors on
|
||||
* midnight - the two disagreed on the boundary for part of each day. dueDate also has to
|
||||
* land the day *after* the reminder day, so a disposition stays included from the same
|
||||
* calendar day its reminder mail goes out rather than the day after.
|
||||
*/
|
||||
public function testOverdueContractsAnchorsOnTheSameDayTheReminderGoesOut(): void
|
||||
{
|
||||
$query = $this->overdueContractsQuery(5);
|
||||
|
||||
$dueDate = $query->getParameter('dueDate')->getValue();
|
||||
|
||||
$this->assertSame('00:00:00', $dueDate->format('H:i:s'));
|
||||
$this->assertSame(
|
||||
(new \DateTimeImmutable('today'))->modify('-4 days')->format('Y-m-d'),
|
||||
$dueDate->format('Y-m-d')
|
||||
);
|
||||
}
|
||||
|
||||
private function contractQuery(int $deadlineDays = 5): Query
|
||||
{
|
||||
return $this->repository()->getContractReminderQuery($deadlineDays);
|
||||
}
|
||||
|
||||
private function overdueContractsQuery(int $deadlineDays = 5): Query
|
||||
{
|
||||
return $this->repository()->getOverdueContractsQuery($deadlineDays);
|
||||
}
|
||||
|
||||
private function invoiceQuery(?\DateTimeImmutable $endDate = null): Query
|
||||
{
|
||||
return $this
|
||||
|
||||
Reference in New Issue
Block a user