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.
This commit is contained in:
mahdahar 2026-04-23 13:26:18 +07:00
parent 6b4ffe017c
commit 66e9be2a04
4 changed files with 33 additions and 27 deletions

View File

@ -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');
}

View File

@ -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) {

View File

@ -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:

View File

@ -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.');
}