Skip to content

Commit

Permalink
feat: Add display until support to IRFO GV Permit type (dvsa/olcs-bac…
Browse files Browse the repository at this point in the history
…kend#190)

* feat: Add display until support to IRFO GV Permit type

* feat: Add display until support to IRFO GV Permit type
  • Loading branch information
fibble authored Jun 26, 2024
1 parent 4369ab1 commit c09ac36
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function handleQuery(QueryInterface $query)
{
$repo = $this->getRepo();

$records = $repo->fetchActiveRecords();

return [
'result' => $this->resultList(
$repo->fetchList($query, Query::HYDRATE_OBJECT)
),
'count' => $repo->fetchCount($query),
'result' => $this->resultList($records),
'count' => count($records),
];
}
}
15 changes: 15 additions & 0 deletions app/api/module/Api/src/Domain/Repository/IrfoGvPermitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ protected function applyListFilters(QueryBuilder $qb, QueryInterface $query)
{
$qb->orderBy($this->alias . '.description', 'ASC');
}

public function fetchActiveRecords()
{
$doctrineQb = $this->createQueryBuilder();

$doctrineQb->where($doctrineQb->expr()->orX(
$doctrineQb->expr()->isNull($this->alias . '.displayUntil'),
$doctrineQb->expr()->gte($this->alias . '.displayUntil', ':today')
))
->setParameter('today', new \DateTime(), \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE);

$doctrineQb->orderBy($this->alias . '.description', 'ASC');

return $doctrineQb->getQuery()->getResult();
}
}
40 changes: 40 additions & 0 deletions app/api/module/Api/src/Entity/Irfo/AbstractIrfoGvPermitType.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ abstract class AbstractIrfoGvPermitType implements BundleSerializableInterface,
*/
protected $description;

/**
* Display until
*
* @var \DateTime
*
* @ORM\Column(type="date", name="display_until", nullable=true)
*/
protected $displayUntil;

/**
* Identifier - Id
*
Expand Down Expand Up @@ -156,6 +165,37 @@ public function getDescription()
return $this->description;
}

/**
* Set the display until
*
* @param \DateTime $displayUntil new value being set
*
* @return IrfoGvPermitType
*/
public function setDisplayUntil($displayUntil)
{
$this->displayUntil = $displayUntil;

return $this;
}

/**
* Get the display until date
*
* @param bool $asDateTime If true will always return a \DateTime (or null) never a string datetime
*
* @return \DateTime|string
*/
public function getDisplayUntil($asDateTime = false)
{
if ($asDateTime === true) {
return $this->asDateTime($this->displayUntil);
}

return $this->displayUntil;
}

/**
* Set the id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ public function testHandleQuery()
->getMock();

$this->repoMap['IrfoGvPermitType']
->shouldReceive('fetchList')
->with($query, \Doctrine\ORM\Query::HYDRATE_OBJECT)
->shouldReceive('fetchActiveRecords')
->andReturn([$entity])
//
->shouldReceive('fetchCount')
->with($query)
->andReturn(2);
->andReturn(1);

$actual = $this->sut->handleQuery($query);

static::assertEquals(2, $actual['count']);
static::assertEquals(1, $actual['count']);
static::assertEquals(['SERIALIZED'], $actual['result']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ public function testApplyListFilters()

$this->sut->applyListFilters($mockQb, $mockQ);
}

public function testFetchActiveRecords()
{
$qb = $this->createMockQb('QRYSTART');

$this->mockCreateQueryBuilder($qb);

$qb->shouldReceive('getQuery')
->once()
->andReturn(m::mock(\Doctrine\ORM\AbstractQuery::class)->shouldReceive('getResult')
->once()
->andReturn(['Mocked Result'])
->getMock());

$this->assertEquals(['Mocked Result'], $this->sut->fetchActiveRecords('ORG1'));

$actualQuery = $this->query;
$expectedPattern = '/QRYSTART AND \(m\.displayUntil IS NULL OR m\.displayUntil >= \[\[.*\]\]\) ORDER BY m\.description ASC/';
$this->assertMatchesRegularExpression($expectedPattern, $actualQuery);
}
}

0 comments on commit c09ac36

Please sign in to comment.