From a41d87b832381964bbe0c1b00e2af4e85ef60183 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Thu, 15 Aug 2024 10:12:53 +0100 Subject: [PATCH 1/3] LIMS-1002: Fix error when creating new laboratory --- api/src/Controllers/UserController.php | 11 +++-------- api/src/Model/Services/UserData.php | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/api/src/Controllers/UserController.php b/api/src/Controllers/UserController.php index 9951a9d6e..ad1e9739e 100644 --- a/api/src/Controllers/UserController.php +++ b/api/src/Controllers/UserController.php @@ -275,13 +275,8 @@ function _update_user() $person = $this->userData->getUser($this->user->personId, $this->proposalid, $this->arg('PERSONID')); $person = $person[0]; $this->_output((array) $person); - $laboratory = null; - if ($person['LABORATORYID']) - { - $laboratory = $this->userData->getLaboratory($person['LABORATORYID'])[0]; - } - $this->userData->updateLaboratory( + $laboratoryId = $this->userData->updateLaboratory( $this->arg('PERSONID'), $this->argOrNull('LABNAME'), $this->argOrNull('ADDRESS'), @@ -290,7 +285,7 @@ function _update_user() $this->argOrNull('COUNTRY'), $person['LABORATORYID'] ); - $laboratory = $this->userData->getLaboratory($person['LABORATORYID']); + $laboratory = $this->userData->getLaboratory($laboratoryId); $this->_output((array) $laboratory[0]); } @@ -362,4 +357,4 @@ function _update_permission() ); $this->_output(array('TYPE' => $this->arg('TYPE'), 'DESCRIPTION' => $desc)); } -} \ No newline at end of file +} diff --git a/api/src/Model/Services/UserData.php b/api/src/Model/Services/UserData.php index 2a01cdbb5..0c65542db 100644 --- a/api/src/Model/Services/UserData.php +++ b/api/src/Model/Services/UserData.php @@ -340,6 +340,7 @@ function updateLaboratory($personId, $labName, $labAddress, $city, $postcode, $c ->whereIdEquals("personid", $personId) ->update("person"); } + return $laboratoryId; } function addGroupUser($personId, $gid) From a5213390498e320c4fdd4a49d4a80e197907a6ea Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Thu, 15 Aug 2024 10:38:27 +0100 Subject: [PATCH 2/3] LIMS-1002: Fix test --- api/tests/Controllers/UserControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/tests/Controllers/UserControllerTest.php b/api/tests/Controllers/UserControllerTest.php index 8c31e82b1..ea4225833 100644 --- a/api/tests/Controllers/UserControllerTest.php +++ b/api/tests/Controllers/UserControllerTest.php @@ -373,7 +373,7 @@ public function testUpdateUserWithValidPersonIdAndLabIdReturnsData(): void $this->dataLayerStub->expects($this->exactly(2))->method('getUser')->with(231312, null, 88)->willReturn($results); $this->dataLayerStub->expects($this->exactly(1))->method('updateUser'); - $this->dataLayerStub->expects($this->exactly(2))->method('getLaboratory')->with(666)->willReturn($labResults); + $this->dataLayerStub->expects($this->exactly(1))->method('getLaboratory')->with(666)->willReturn($labResults); $this->dataLayerStub->expects($this->exactly(1))->method('updateLaboratory'); $this->userController->_update_user(); @@ -563,4 +563,4 @@ public function testGetPermissionsWithPidSpecifiedReturnsData(): void $this->userController->_get_permissions(); $this->assertEquals(61, $response->getBody()); } -} \ No newline at end of file +} From cd421e3c9673674f4faca2a15dc6f10cd51e2fdc Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Thu, 15 Aug 2024 10:43:54 +0100 Subject: [PATCH 3/3] LIMS-1002: Fix test --- api/tests/Controllers/UserControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/tests/Controllers/UserControllerTest.php b/api/tests/Controllers/UserControllerTest.php index ea4225833..03dd3c6da 100644 --- a/api/tests/Controllers/UserControllerTest.php +++ b/api/tests/Controllers/UserControllerTest.php @@ -374,7 +374,7 @@ public function testUpdateUserWithValidPersonIdAndLabIdReturnsData(): void $this->dataLayerStub->expects($this->exactly(2))->method('getUser')->with(231312, null, 88)->willReturn($results); $this->dataLayerStub->expects($this->exactly(1))->method('updateUser'); $this->dataLayerStub->expects($this->exactly(1))->method('getLaboratory')->with(666)->willReturn($labResults); - $this->dataLayerStub->expects($this->exactly(1))->method('updateLaboratory'); + $this->dataLayerStub->expects($this->exactly(1))->method('updateLaboratory')->willReturn(666); $this->userController->_update_user(); }