This commit is contained in:
@@ -29,6 +29,16 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function designated(string $role): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user->forceFill(['two_factor_secret' => Crypt::encryptString('SYNTHETIC'), 'two_factor_confirmed_at' => now()])->save();
|
||||
config(['portal.managers' => [...config('portal.managers', []), $user->email],
|
||||
'existing-business.'.$role => [...config('existing-business.'.$role, []), strtolower($user->email)]]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function draft(): array
|
||||
{
|
||||
@@ -41,6 +51,7 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
$reviewer = $this->reviewer();
|
||||
$triager = $this->designated('triagers');
|
||||
$this->actingAs($owner);
|
||||
$id = $this->postJson($this->base, $this->draft())->assertCreated()->json('id');
|
||||
$url = $this->base.'/'.$id;
|
||||
@@ -50,17 +61,23 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$this->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic review requested', 'review_consent' => true])->assertOk()->assertJsonPath('version_no', 2);
|
||||
$this->putJson($url, [...$this->draft(), 'version_no' => 2])->assertForbidden();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Attempted self review'])->assertForbidden();
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk()->assertJsonPath('version_no', 3);
|
||||
$this->actingAs($reviewer)->getJson('/api/v1/existing-business/reviews')->assertOk()->assertJsonPath('records.total', 1);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertConflict();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk()->assertJsonPath('version_no', 3);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'needs_information', 'note' => 'Please clarify synthetic source'])->assertOk();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertConflict();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk()->assertJsonPath('version_no', 4);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'needs_information', 'note' => 'Please clarify synthetic source'])->assertOk();
|
||||
$this->actingAs($owner)->getJson($url)->assertOk()->assertJsonPath('history.0.note', 'Please clarify synthetic source');
|
||||
$this->postJson($url, [...$this->draft(), '_method' => 'PUT', 'version_no' => 4])->assertOk()->assertJsonPath('version_no', 5);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 5, 'action' => 'withdrawn', 'note' => 'Synthetic withdrawal requested'])->assertOk();
|
||||
$this->postJson($url, [...$this->draft(), '_method' => 'PUT', 'version_no' => 5])->assertOk()->assertJsonPath('version_no', 6);
|
||||
$this->postJson($url.'/transitions', ['version_no' => 6, 'action' => 'withdrawn', 'note' => 'Synthetic withdrawal requested'])->assertOk();
|
||||
$this->actingAs($reviewer)->getJson($url)->assertForbidden();
|
||||
$this->getJson('/api/v1/existing-business/reviews')->assertJsonPath('records.total', 0);
|
||||
$this->assertDatabaseCount('existing_business_reviews', 4);
|
||||
$this->assertDatabaseCount('existing_business_revisions', 6);
|
||||
$this->assertDatabaseCount('existing_business_reviews', 5);
|
||||
$this->assertDatabaseCount('existing_business_revisions', 7);
|
||||
$this->assertDatabaseCount('business_workflow_transitions', 5);
|
||||
$this->assertDatabaseCount('outbox_events', 1);
|
||||
$transition = DB::table('business_workflow_transitions')->where('to_status', 'needs_information')->first();
|
||||
$this->assertSame('in_review', $transition->from_status);
|
||||
$this->assertStringNotContainsString('Please clarify', $transition->reason);
|
||||
$this->assertStringNotContainsString('Please clarify', DB::table('existing_business_reviews')->where('action', 'needs_information')->value('note'));
|
||||
}
|
||||
|
||||
@@ -76,11 +93,14 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
'valid_until' => today()->addDay()->toDateString()];
|
||||
$this->postJson($url.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic review requested', 'review_consent' => true])->assertOk();
|
||||
$this->postJson($url.'/verifications', $finding)->assertForbidden();
|
||||
$this->actingAs($reviewer)->postJson($url.'/verifications', [...$finding, 'version_no' => 2])->assertConflict();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk();
|
||||
$triager = $this->designated('triagers');
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'triage', 'note' => 'Synthetic triage completed'])->assertOk();
|
||||
$this->actingAs($reviewer)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'in_review', 'note' => 'Synthetic review started'])->assertOk();
|
||||
$this->postJson($url.'/verifications', [...$finding, 'version_no' => 3])->assertConflict();
|
||||
$finding['version_no'] = 4;
|
||||
$this->postJson($url.'/verifications', [...$finding, 'valid_until' => null])->assertUnprocessable();
|
||||
$this->postJson($url.'/verifications', [...$finding, 'object_id' => '00000000-0000-4000-8000-000000000001'])->assertNotFound();
|
||||
$this->postJson($url.'/verifications', $finding)->assertOk()->assertJsonPath('version_no', 4);
|
||||
$this->postJson($url.'/verifications', $finding)->assertOk()->assertJsonPath('version_no', 5);
|
||||
$this->postJson($url.'/verifications', $finding)->assertConflict();
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('verifications.0.effective_outcome', 'confirmed');
|
||||
$raw = DB::table('existing_business_revisions')->where('business_id', $id)->where('action', 'verification')->value('snapshot');
|
||||
@@ -88,8 +108,8 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$this->travel(2)->days();
|
||||
$this->getJson($url)->assertOk()->assertJsonPath('verifications.0.effective_outcome', 'expired');
|
||||
$this->travelBack();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'needs_information', 'note' => 'Synthetic clarification requested'])->assertOk();
|
||||
$this->actingAs($owner)->putJson($url, [...$this->draft(), 'version_no' => 5])->assertOk();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 5, 'action' => 'needs_information', 'note' => 'Synthetic clarification requested'])->assertOk();
|
||||
$this->actingAs($owner)->putJson($url, [...$this->draft(), 'version_no' => 6])->assertOk();
|
||||
$this->getJson($url)->assertJsonPath('verifications.0.effective_outcome', 'stale');
|
||||
$this->actingAs(User::factory()->create())->getJson($url)->assertForbidden();
|
||||
}
|
||||
@@ -114,12 +134,46 @@ class ExistingBusinessIntakeTest extends TestCase
|
||||
$draft = $this->draft();
|
||||
$draft['payload']['valid_until'] = today()->subDay()->toDateString();
|
||||
$id = $this->postJson($this->base, $draft)->assertCreated()->json('id');
|
||||
foreach (['published', 'approved', 'submitted'] as $action) {
|
||||
$this->postJson($this->base.'/'.$id.'/transitions', ['version_no' => 1, 'action' => $action, 'note' => 'Synthetic invalid transition', 'review_consent' => true])->assertUnprocessable();
|
||||
foreach (['published', 'approved'] as $action) {
|
||||
$this->postJson($this->base.'/'.$id.'/transitions', ['version_no' => 1, 'action' => $action, 'note' => 'Synthetic invalid transition', 'review_consent' => true])->assertForbidden();
|
||||
}
|
||||
$this->postJson($this->base.'/'.$id.'/transitions', ['version_no' => 1, 'action' => 'submitted', 'note' => 'Synthetic invalid transition', 'review_consent' => true])->assertUnprocessable();
|
||||
$this->assertDatabaseCount('existing_business_reviews', 0);
|
||||
}
|
||||
|
||||
public function test_submission_triage_two_level_approval_and_publication_require_distinct_designations(): void
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
$triager = $this->designated('triagers');
|
||||
$reviewer = $this->designated('reviewers');
|
||||
$levelOne = $this->designated('approvers_l1');
|
||||
$levelTwo = $this->designated('approvers_l2');
|
||||
$publisher = $this->designated('publishers');
|
||||
$sectorId = DB::table('sectors')->insertGetId(['name' => 'Synthetic approval sector', 'slug' => 'synthetic-approval-sector', 'is_active' => true]);
|
||||
|
||||
$this->actingAs($owner);
|
||||
$id = $this->postJson($this->base, $this->draft())->assertCreated()->json('id');
|
||||
$this->putJson($this->base.'/'.$id, [...$this->draft(), 'version_no' => 1, 'sector_id' => $sectorId,
|
||||
'public_title' => 'Synthetic public listing'])->assertOk();
|
||||
$url = $this->base.'/'.$id;
|
||||
$this->postJson($url.'/transitions', ['version_no' => 2, 'action' => 'submitted', 'note' => 'Synthetic submission for staged approval', 'review_consent' => true])->assertOk();
|
||||
$this->assertDatabaseHas('tasks', ['existing_business_id' => $id, 'task_type' => 'triage', 'status' => 'open']);
|
||||
|
||||
$this->actingAs($triager)->postJson($url.'/transitions', ['version_no' => 3, 'action' => 'triage', 'note' => 'Synthetic initial triage completed'])->assertOk();
|
||||
$this->actingAs($reviewer)->postJson($url.'/transitions', ['version_no' => 4, 'action' => 'in_review', 'note' => 'Synthetic independent review started'])->assertOk();
|
||||
$this->postJson($url.'/transitions', ['version_no' => 5, 'action' => 'approval_l1', 'note' => 'Synthetic review checks completed'])->assertOk();
|
||||
$this->actingAs($levelOne)->postJson($url.'/transitions', ['version_no' => 6, 'action' => 'approval_l2', 'note' => 'Synthetic first level approval'])->assertOk();
|
||||
|
||||
config(['existing-business.approvers_l2' => [...config('existing-business.approvers_l2'), strtolower($levelOne->email)]]);
|
||||
$this->actingAs($levelOne)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic second level approval attempt'])->assertForbidden();
|
||||
$this->actingAs($levelTwo)->postJson($url.'/transitions', ['version_no' => 7, 'action' => 'approved', 'note' => 'Synthetic independent second level approval'])->assertOk();
|
||||
$this->actingAs($publisher)->postJson($url.'/transitions', ['version_no' => 8, 'action' => 'published', 'note' => 'Synthetic independent publication decision'])->assertOk()->assertJsonPath('published_at', fn ($value) => is_string($value));
|
||||
|
||||
$this->assertDatabaseHas('business_workflow_transitions', ['existing_business_id' => $id, 'from_status' => 'approval_l2', 'to_status' => 'approved']);
|
||||
$this->assertDatabaseHas('existing_businesses', ['id' => $id, 'status' => 'published']);
|
||||
$this->assertDatabaseCount('outbox_events', 1);
|
||||
}
|
||||
|
||||
public function test_reserved_objects_are_scoped_versioned_and_never_verified_by_declaration(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
Reference in New Issue
Block a user