From 66e9be2a04e5aad473b2e443c866e02486ab87dc Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Thu, 23 Apr 2026 13:26:18 +0700 Subject: [PATCH] Rename order test delta created to added Update order test patch flow to use Tests.added instead of Tests.created across controller, model, bundled OpenAPI, and feature test coverage. Reject legacy created payloads, align validation/error text, and adjust test payloads and assertions for new added lifecycle. --- app/Controllers/OrderTestController.php | 8 +++- app/Models/OrderTest/OrderTestModel.php | 8 ++-- public/api-docs.bundled.yaml | 4 +- .../feature/OrderTest/OrderTestPatchTest.php | 40 ++++++++++--------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/app/Controllers/OrderTestController.php b/app/Controllers/OrderTestController.php index 47d1d60..76619bd 100755 --- a/app/Controllers/OrderTestController.php +++ b/app/Controllers/OrderTestController.php @@ -308,8 +308,12 @@ class OrderTestController extends Controller { throw new \InvalidArgumentException('Tests must be an object'); } + if (array_key_exists('created', $tests)) { + throw new \InvalidArgumentException('created tests are not supported'); + } + $delta = [ - 'created' => [], + 'added' => [], 'edited' => [], 'deleted' => [], ]; @@ -326,7 +330,7 @@ class OrderTestController extends Controller { $delta[$key] = $tests[$key]; } - if (empty($delta['created']) && empty($delta['edited']) && empty($delta['deleted'])) { + if (empty($delta['added']) && empty($delta['edited']) && empty($delta['deleted'])) { throw new \InvalidArgumentException('Tests delta is required'); } diff --git a/app/Models/OrderTest/OrderTestModel.php b/app/Models/OrderTest/OrderTestModel.php index 6ec2825..a18808d 100755 --- a/app/Models/OrderTest/OrderTestModel.php +++ b/app/Models/OrderTest/OrderTestModel.php @@ -238,17 +238,17 @@ class OrderTestModel extends BaseModel { } $summary = [ - 'created' => [], + 'added' => [], 'edited' => [], 'deleted' => [], ]; - foreach (($testsDelta['created'] ?? []) as $item) { + foreach (($testsDelta['added'] ?? []) as $item) { if (!is_array($item)) { - throw new \InvalidArgumentException('Invalid created test payload'); + throw new \InvalidArgumentException('Invalid added test payload'); } - $summary['created'][] = $this->createTestRow($order, $item); + $summary['added'][] = $this->createTestRow($order, $item); } foreach (($testsDelta['edited'] ?? []) as $item) { diff --git a/public/api-docs.bundled.yaml b/public/api-docs.bundled.yaml index 0de7cf4..73ecf5c 100755 --- a/public/api-docs.bundled.yaml +++ b/public/api-docs.bundled.yaml @@ -1505,9 +1505,9 @@ paths: Tests: type: object properties: - created: + added: type: array - description: New tests to create for this order + description: New tests to add to this order items: type: object properties: diff --git a/tests/feature/OrderTest/OrderTestPatchTest.php b/tests/feature/OrderTest/OrderTestPatchTest.php index f03d39e..db2bf5a 100755 --- a/tests/feature/OrderTest/OrderTestPatchTest.php +++ b/tests/feature/OrderTest/OrderTestPatchTest.php @@ -103,7 +103,7 @@ class OrderTestPatchTest extends CIUnitTestCase ]; } - public function testPatchTestsLifecycleCreatedEditedDeleted(): void + public function testPatchTestsLifecycleAddedEditedDeleted(): void { $fixture = $this->createOrderWithTest(); $order = $fixture['order']; @@ -114,32 +114,32 @@ class OrderTestPatchTest extends CIUnitTestCase $baseSiteID = (int) $baseTest['TestSiteID']; $extraSiteID = (int) $extraTest['TestSiteID']; - $createResponse = $this->withHeaders($this->authHeaders()) + $addResponse = $this->withHeaders($this->authHeaders()) ->withBodyFormat('json') ->call('patch', "{$this->endpoint}/{$orderID}", [ 'Tests' => [ - 'created' => [ + 'added' => [ [ - 'TestSiteID' => $extraSiteID, - 'Result' => 'CREATED', + 'TestSiteID' => (string) $extraSiteID, + 'Result' => 'ADDED', ], ], ], ]); - $createResponse->assertStatus(200); - $createJson = json_decode($createResponse->getJSON(), true); - $this->assertSame('success', $createJson['status'] ?? null); + $addResponse->assertStatus(200); + $addJson = json_decode($addResponse->getJSON(), true); + $this->assertSame('success', $addJson['status'] ?? null); - $createdRow = $this->findRowBySite($createJson['data']['Tests'] ?? [], $extraSiteID); - $this->assertNotNull($createdRow, 'Created test not returned by patch response.'); - $this->assertSame('CREATED', $createdRow['Result'] ?? null); - $createdResultID = (int) ($createdRow['ResultID'] ?? 0); - $this->assertGreaterThan(0, $createdResultID, 'Created test missing ResultID.'); + $addedRow = $this->findRowBySite($addJson['data']['Tests'] ?? [], $extraSiteID); + $this->assertNotNull($addedRow, 'Added test not returned by patch response.'); + $this->assertSame('ADDED', $addedRow['Result'] ?? null); + $addedResultID = (int) ($addedRow['ResultID'] ?? 0); + $this->assertGreaterThan(0, $addedResultID, 'Added test missing ResultID.'); - $createdDbRow = $this->findResultByOrderAndSite($internalOID, $extraSiteID); - $this->assertNotNull($createdDbRow, 'Created test not found in DB.'); - $this->assertSame('CREATED', $createdDbRow['Result'] ?? null); + $addedDbRow = $this->findResultByOrderAndSite($internalOID, $extraSiteID); + $this->assertNotNull($addedDbRow, 'Added test not found in DB.'); + $this->assertSame('ADDED', $addedDbRow['Result'] ?? null); $editResponse = $this->withHeaders($this->authHeaders()) ->withBodyFormat('json') @@ -147,7 +147,7 @@ class OrderTestPatchTest extends CIUnitTestCase 'Tests' => [ 'edited' => [ [ - 'TestSiteID' => $baseSiteID, + 'TestSiteID' => (string) $baseSiteID, 'Result' => 'EDITED', ], ], @@ -167,7 +167,9 @@ class OrderTestPatchTest extends CIUnitTestCase ->call('patch', "{$this->endpoint}/{$orderID}", [ 'Tests' => [ 'deleted' => [ - $extraSiteID, + [ + 'TestSiteID' => (string) $extraSiteID, + ], ], ], ]); @@ -177,7 +179,7 @@ class OrderTestPatchTest extends CIUnitTestCase $this->assertSame('success', $deleteJson['status'] ?? null); $this->assertNull($this->findRowBySite($deleteJson['data']['Tests'] ?? [], $extraSiteID), 'Deleted test still returned by patch response.'); - $deletedDbRow = (new PatResultModel())->find($createdResultID); + $deletedDbRow = (new PatResultModel())->find($addedResultID); $this->assertNotNull($deletedDbRow, 'Deleted test row missing from DB.'); $this->assertNotNull($deletedDbRow['DelDate'] ?? null, 'Deleted test row not soft deleted.'); }