diff --git a/src/Domain/CredentialDocumentBlock.php b/src/Domain/CredentialDocumentBlock.php index b010cab..8b6e806 100644 --- a/src/Domain/CredentialDocumentBlock.php +++ b/src/Domain/CredentialDocumentBlock.php @@ -32,7 +32,8 @@ public function __construct(object $block_data, EntityStatus $entityStatus = nul $this->credential_subject = $this->checkForOptionalSubject(); } - private function checkForOptionalSubject() : null|object { + private function checkForOptionalSubject(): null|object + { return array_key_exists('document', $this->block_data) ? (object) $this->block_data['document']['credentialSubject']['0'] : null; diff --git a/src/Domain/GuardianToken.php b/src/Domain/GuardianToken.php index 116cec6..96feaea 100644 --- a/src/Domain/GuardianToken.php +++ b/src/Domain/GuardianToken.php @@ -12,11 +12,10 @@ public static function none(): self { return new self((object) [ "adminId" => null, - "tokenId" => "" + "tokenId" => "", ]); } - /** * When "adminId" from parent obj is falsely then ignore "id()" fn in client. * @@ -26,7 +25,7 @@ public static function none(): self */ public function isTokenPublished(): bool { - return !! $this->token->adminId; + return ! ! $this->token->adminId; } public function id(): string diff --git a/src/Domain/TrustchainQuery.php b/src/Domain/TrustchainQuery.php index 73a3743..3788a1a 100644 --- a/src/Domain/TrustchainQuery.php +++ b/src/Domain/TrustchainQuery.php @@ -68,6 +68,6 @@ public function withResult(?CredentialDocumentBlock $result): self public function hasTrustchainResult(): bool { - return !! $this->result; + return ! ! $this->result; } } diff --git a/src/Service/PolicyService.php b/src/Service/PolicyService.php index 46a148c..b423cd3 100644 --- a/src/Service/PolicyService.php +++ b/src/Service/PolicyService.php @@ -3,7 +3,7 @@ namespace Dovu\GuardianPhpSdk\Service; use Dovu\GuardianPhpSdk\Domain\GuardianToken; -use Exception; +use Dovu\GuardianPhpSdk\Domain\TaskInstance; class PolicyService extends AbstractService { @@ -17,6 +17,22 @@ public function get($id): object return (object) $this->httpClient->get("policies/{$id}")->data(); } + public function publish($id, $version): object + { + return (object) $this->httpClient->put("policies/push/{$id}/publish", [ + 'policyVersion' => $version, + ])->data(); + } + + public function publishSync(callable $callback, string $id, string $version): TaskInstance + { + $callback($id, $version); + + $import = TaskInstance::from($this->publish($id, $version)); + + return $this->runnerTask($import, $callback); + } + public function assign(string $username, string $policy_id, bool $assign = true): object { $payload = [ diff --git a/src/Support/PolicyMode.php b/src/Support/PolicyMode.php index 098f267..210b9e4 100644 --- a/src/Support/PolicyMode.php +++ b/src/Support/PolicyMode.php @@ -2,6 +2,8 @@ namespace Dovu\GuardianPhpSdk\Support; +use Dovu\GuardianPhpSdk\Domain\TaskInstance; + enum PolicyStatus: string { case DRAFT = 'DRAFT'; @@ -23,10 +25,9 @@ public static function context(PolicyContext $context): self return new self($context); } - // TODO: Implement later to publish - public function publish() + public function publishVersion(callable $callback, string $version): TaskInstance { - + return $this->context->policies->publishSync($callback, $this->context->policyId, $version); } public function dryRun() diff --git a/tests/ResearchElvClientGuardianTest.php b/tests/ResearchElvClientGuardianTest.php index f7d9d1c..1d16ed9 100644 --- a/tests/ResearchElvClientGuardianTest.php +++ b/tests/ResearchElvClientGuardianTest.php @@ -6,7 +6,6 @@ use Dovu\GuardianPhpSdk\Constants\GuardianApprovalOption; use Dovu\GuardianPhpSdk\Constants\GuardianRole; use Dovu\GuardianPhpSdk\Domain\PolicySchemaDocument; -use Dovu\GuardianPhpSdk\Domain\Trustchain; use Dovu\GuardianPhpSdk\Domain\TrustchainQuery; use Dovu\GuardianPhpSdk\DovuGuardianAPI; use Dovu\GuardianPhpSdk\Support\DryRunScenario; @@ -116,7 +115,7 @@ describe('Functional Guardian Test', function () { beforeEach(function () { $this->sdk = new DovuGuardianAPI(); -// $this->sdk->setGuardianBaseUrl("http://localhost:3000/api/v1/"); + // $this->sdk->setGuardianBaseUrl("http://localhost:3000/api/v1/"); $config = EnvConfig::instance(); @@ -125,11 +124,6 @@ $policy_id = $config->get(Env::POLICY_ID); - // TODO: Remove. mmcm elv -// $policy_id = "66b5e1e76efceb6b593efa73"; -// $policy_id = "66c616cc6efceb6b593f08de"; -// $policy_id = $config->testLocalPolicy(); - $context = PolicyContext::using($this->sdk)->for($policy_id); $this->helper = new GuardianSDKHelper($this->sdk, $policy_id); @@ -214,6 +208,28 @@ })->skip(); + it('A policy can be published', function () { + + $this->helper->authenticateAsRegistry(); + + expect($this->policy_mode->hasPolicyStatus(PolicyStatus::DRAFT) + || $this->policy_mode->hasPolicyStatus(PolicyStatus::DRY_RUN))->toBeTruthy(); + + + $publish_fn = function ($state) { + ray("Publish progress"); + ray($state); + + expect($state)->toBeTruthy(); + }; + + + $publish = $this->policy_mode->publishVersion($publish_fn, '1'); + + expect($publish->result['isValid'])->toBeTrue(); + + })->skip("Publish testing for local dev, currently."); + it('A policy can create users and view them in dry run', function () { $this->helper->authenticateAsRegistry(); @@ -514,7 +530,7 @@ expect($response->hasTrustchainResult())->toBeTruthy(); // TODO: WORK IN PROGRESS -// ray($trustchain->format()); + // ray($trustchain->format()); })->skip(); it('An admin can get the token for a policy', function () { @@ -527,6 +543,8 @@ $token = $this->sdk->policies->token($policy_id); + ray($token); + expect($token->hasValidToken())->toBeBool(); expect($token->id())->toBeTruthy(); @@ -537,7 +555,7 @@ expect($token->hasValidToken())->toBeTruthy(); expect($token->id())->toBeFalsy(); - }); + })->skip(); it('Fetch a specification of a schema for workflow import and validation', function () { @@ -610,9 +628,11 @@ expect($timestamp)->toBeTruthy(); // When something happens, complete - $status_update_callable = function ($state) { - ray("Status update"); - ray($state); + $status_update_callable = function ($state) use ($registry_user, $password) { + + $this->helper->authenticateAsRegistry($registry_user, $password); + + ray("Status Import Update"); if ($state->result) { ray("done"); @@ -655,7 +675,7 @@ * 3. Update the context objects with the correct uploaded "registry" user and imported policy id. */ -// $this->policy_mode->dryRun(); + // $this->policy_mode->dryRun(); /** * Create mediator object. @@ -793,7 +813,7 @@ ->setApprovalOption(ApprovalOption::APPROVE) ->setFilterValue($claim['uuid']) ->run(); - + ray('$approve_claim'); ray($result);