Skip to content

Commit

Permalink
DDLS-381 - Admin fixture-created deputy has no deputy UID (#1711)
Browse files Browse the repository at this point in the history
* generate and set deputy uid on entity in dd_user and pre-reg table for court order fixtures

* generate deputy uid for pre-reg fixtures for deputy and co-deputies

* set primary flag to true for lay deputies and co-deputies

* update endpoint to successfully pull client info and render on client details page

* update generation of unique emails to prevent future pipeline failures
  • Loading branch information
MiaGordon91 authored Oct 31, 2024
1 parent 43cd768 commit 751cd89
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions api/app/src/FixtureFactory/PreRegistrationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public function __construct(private PreRegistrationDTOFactory $preRegistrationFa
public function create(array $data): PreRegistration
{
$caseNumber = str_pad((string) rand(1, 99999999), 8, '0', STR_PAD_LEFT);
$deputyNumber = str_pad((string) rand(1, 999999999999), 12, '0', STR_PAD_LEFT);
$generateDeputyUidIfNotSet = '7'.str_pad((string) rand(1, 99999999), 11, '0', STR_PAD_LEFT);
$deputyUid = array_key_exists('deputyUid', $data) && strval($data['deputyUid']) ? strval($data['deputyUid']) : $generateDeputyUidIfNotSet;
$reportType = 'ndr' == $data['reportType'] ? 'OPG102' : $data['reportType'];

$dto = (new LayDeputyshipDto())
->setCaseNumber($data['caseNumber'] ?? $caseNumber)
->setClientSurname($data['clientLastName'] ?? 'Smith')
->setDeputyUid($deputyNumber)
->setDeputyUid($deputyUid)
->setDeputyAddress1($data['deputyAddress1'] ?? 'Victoria Park')
->setDeputyAddress2($data['deputyAddress2'] ?? 'Fakeville')
->setDeputyAddress3($data['deputyAddress3'] ?? 'Pretendham')
Expand Down
9 changes: 6 additions & 3 deletions api/app/src/FixtureFactory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function create(array $data): User
->setAddressPostcode(isset($data['postCode']) ? $data['postCode'] : 'SW1')
->setAddressCountry('GB')
->setRoleName($roleName)
->setAgreeTermsUse(true);
->setAgreeTermsUse(true)
->setDeputyUid(User::TYPE_LAY === $data['deputyType'] ? $data['deputyUid'] : null);

if ('true' === $data['activated'] || true === $data['activated']) {
$user->setPassword($this->passwordHasher->hashPassword($user, 'DigidepsPass1234'));
Expand Down Expand Up @@ -135,10 +136,12 @@ public function createCoDeputy(User $originalDeputy, Client $client, array $data
->setActive($data['activated'])
->setRegistrationDate(new \DateTime())
->setCoDeputyClientConfirmed(true)
->setActive(true);
->setActive(true)
->setDeputyUid('7'.str_pad((string) rand(1, 99999999), 11, '0', STR_PAD_LEFT));

if ('true' === $data['activated'] || true === $data['activated']) {
$user2->setPassword($this->passwordHasher->hashPassword($user2, 'DigidepsPass1234'));
$user2->setPassword($this->passwordHasher->hashPassword($user2, 'DigidepsPass1234'))
->setIsPrimary(true);
} else {
$user2->setActive(false);
}
Expand Down
6 changes: 5 additions & 1 deletion api/app/src/v2/Fixture/Controller/FixtureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function createCourtOrderAction(Request $request)
'deputyLastName' => $deputy->getLastname(),
'deputyFirstName' => $deputy->getFirstName(),
'reportType' => $fromRequest['reportType'],
'deputyUid' => $fromRequest['deputyUid'],
]
);

Expand All @@ -97,6 +98,7 @@ public function createCourtOrderAction(Request $request)
}

if (User::TYPE_LAY === $fromRequest['deputyType']) {
$deputy->setIsPrimary(true);
$deputy->addClient($client);
} else {
$this->createOrgAndAttachParticipants($fromRequest, $deputy, $client);
Expand All @@ -114,6 +116,7 @@ public function createCourtOrderAction(Request $request)
'deputyLastName' => $coDeputy->getLastname(),
'deputyFirstName' => $coDeputy->getFirstName(),
'reportType' => $fromRequest['reportType'],
'deputyUid' => $coDeputy->getDeputyUid(),
]
);

Expand Down Expand Up @@ -154,6 +157,7 @@ private function createDeputy($fromRequest): User
'email' => $fromRequest['deputyEmail'],
'activated' => $fromRequest['activated'],
'coDeputyEnabled' => $fromRequest['coDeputyEnabled'],
'deputyUid' => $fromRequest['deputyUid'],
]);

$this->em->persist($deputy);
Expand Down Expand Up @@ -252,7 +256,7 @@ private function buildDeputy(User $deputy, array $fromRequest)
->setFirstname($deputy->getFirstname())
->setLastname($deputy->getLastname())
->setEmail1($deputy->getEmail())
->setDeputyUid($fromRequest['caseNumber'].mt_rand(1, 100))
->setDeputyUid('70'.str_pad($fromRequest['caseNumber'].mt_rand(1, 100), 10))
->setAddress1($deputy->getAddress1())
->setAddressPostcode($deputy->getAddressPostcode())
->setPhoneMain($deputy->getPhoneMain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ private function generateDeputyPrimaryAccount()
'data' => [
'firstname' => 'Sue',
'lastname' => 'Jones',
'email' => sprintf('firstdeputyaccount%[email protected]', rand(1, 20)),
'email' => sprintf('firstdeputy%[email protected]', $casenumber),
'postcode' => 'SW1',
'client_firstname' => 'John',
'client_lastname' => 'Smith',
Expand Down
2 changes: 2 additions & 0 deletions client/app/src/Controller/Admin/FixtureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function courtOrdersAction(Request $request)
$courtDate = $request->get('court-date') ? new \DateTime($request->get('court-date')) : new \DateTime();
$deputyEmail = $request->query->get('deputy-email', sprintf('original-%s-deputy-%[email protected]', strtolower($submitted['deputyType']), mt_rand(1000, 9999)));
$caseNumber = $request->get('case-number', ClientHelpers::createValidCaseNumber());
$deputyUid = intval('7'.str_pad((string) mt_rand(1, 99999999), 11, '0', STR_PAD_LEFT));

$response = $this->restClient->post('v2/fixture/court-order', json_encode([
'deputyType' => $submitted['deputyType'],
Expand All @@ -105,6 +106,7 @@ public function courtOrdersAction(Request $request)
'activated' => $submitted['activated'],
'orgSizeClients' => $submitted['orgSizeClients'],
'orgSizeUsers' => $submitted['orgSizeUsers'],
'deputyUid' => $deputyUid,
]));

$query = ['query' => ['filter_by_ids' => implode(',', $response['deputyIds'])]];
Expand Down
2 changes: 1 addition & 1 deletion client/app/src/Service/Client/Internal/ClientApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getWithUsersV2(int $clientId, array $includes = [])
public function getById(int $clientId, array $includes = [])
{
return $this->restClient->get(
sprintf(self::GET_CLIENT_BY_ID_V2, $clientId),
sprintf(self::GET_CLIENT_BY_ID, $clientId),
'Client',
[
'client',
Expand Down

0 comments on commit 751cd89

Please sign in to comment.