Skip to content

Commit

Permalink
fix: remove unecessary steps
Browse files Browse the repository at this point in the history
After implementation of integration with jq and the step to fetch a
field from previous response was possible to remove some steps.

Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Apr 19, 2024
1 parent fba9933 commit 524910d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 88 deletions.
65 changes: 0 additions & 65 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,6 @@ public function setTheCustomHttpHeaderAsValueToNextRequest(string $header, strin
$this->customHeaders[$header] = $this->parseText($value);
}


/**
* @Then /^the signer "([^"]*)" have a file to sign$/
*/
public function theSignerHaveAFileToSign(string $signer): void {
$this->setCurrentUser($signer);
$this->sendOCSRequest('get', '/apps/libresign/api/v1/file/list');
$response = json_decode($this->response->getBody()->getContents(), true);
Assert::assertGreaterThan(0, $response['data'], 'Haven\'t files to sign');
$this->signer = [];
$this->file = [];
foreach (array_reverse($response['data']) as $file) {
$currentSigner = array_filter($file['signers'], function ($signer): bool {
return $signer['me'];
});
if (count($currentSigner) === 1) {
$this->signer = end($currentSigner);
$this->file = $file;
break;
}
}
Assert::assertGreaterThan(1, $this->signer, $signer . ' don\'t will sign a file');
Assert::assertGreaterThan(1, $this->file, 'The /file/list didn\'t returned a file assigned to ' . $signer);
}

/**
* @Then /^the file to sign contains$/
*
* @param string $name
*/
public function theFileToSignContains(TableNode $table): void {
if (!$this->file) {
$this->theSignerHaveAFileToSign($this->currentUser);
}
$expectedValues = $table->getColumnsHash();
foreach ($expectedValues as $value) {
Assert::assertArrayHasKey($value['key'], $this->file);
if ($value['value'] === '<IGNORE>') {
continue;
}
Assert::assertEquals($value['value'], $this->file[$value['key']]);
}
}

protected function beforeRequest(string $fullUrl, array $options): array {
list($fullUrl, $options) = parent::beforeRequest($fullUrl, $options);
$options = $this->parseFormParams($options);
Expand All @@ -178,27 +134,6 @@ protected function parseText(string $text): string {
return $text;
}

/**
* @Given the signer contains
*/
public function theSignerContains(TableNode $table): void {
if (!$this->signer) {
$this->theSignerHaveAFileToSign($this->currentUser);
}
$expectedValues = $table->getColumnsHash();
foreach ($expectedValues as $value) {
Assert::assertArrayHasKey($value['key'], $this->signer);
if ($value['value'] === '<IGNORE>') {
continue;
}
$actual = $this->signer[$value['key']];
if (is_array($this->signer[$value['key']]) || is_object($this->signer[$value['key']])) {
$actual = json_encode($actual);
}
Assert::assertEquals($value['value'], $actual, sprintf('The actual value of key "%s" is different of expected', $value['key']));
}
}

/**
* @When I fetch the signer UUID from opened email
*/
Expand Down
38 changes: 15 additions & 23 deletions tests/integration/features/page/sign_identify_account.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: page/sign_identify_account
Background: Make setup ok
Given run the command "config:app:set libresign authkey --value dummy" with result code 0
Given run the command "libresign:configure:openssl --cn test" with result code 0

Scenario: Open sign file with invalid account data
Given user "signer1" exists
Expand All @@ -21,17 +21,13 @@ Feature: page/sign_identify_account
| ocs | (jq).data\|.[].subject == "admin requested your signature on document"|
When sending "get" to ocs "/apps/libresign/api/v1/file/list"
And the response should have a status code 200
And the file to sign contains
| key | value |
| uuid | <IGNORE> |
| name | document |
| status | 1 |
| statusText | available for signature |
And the signer contains
| key | value |
| email | |
| me | true |
| identifyMethods | [{"method":"account","value":"signer1","mandatory":1}] |
And the response should be a JSON array with the following mandatory values
| key | value |
| (jq).data\|.[].statusText | available for signature |
| (jq).data\|.[].signers | (jq).[].me == true |
| (jq).data\|.[].signers\|.[].identifyMethods\|.[].method | account |
| (jq).data\|.[].signers\|.[].identifyMethods\|.[].value | signer1 |
And fetch field "(SIGN_UUID)data.0.signers.0.sign_uuid" from prevous JSON response
# invalid UUID, need to be the signer UUID
When as user "signer1"
And sending "get" to "/apps/libresign/p/sign/<FILE_UUID>"
Expand Down Expand Up @@ -75,17 +71,13 @@ Feature: page/sign_identify_account
| ocs | (jq).data\|.[].subject == "admin requested your signature on document"|
When sending "get" to ocs "/apps/libresign/api/v1/file/list"
And the response should have a status code 200
And the file to sign contains
| key | value |
| uuid | <IGNORE> |
| name | document |
| status | 1 |
| statusText | available for signature |
And the signer contains
| key | value |
| email | |
| me | true |
| identifyMethods | [{"method":"account","value":"signer1","mandatory":1}] |
And the response should be a JSON array with the following mandatory values
| key | value |
| (jq).data\|.[].statusText | available for signature |
| (jq).data\|.[].signers | (jq).[].me == true |
| (jq).data\|.[].signers\|.[].identifyMethods\|.[].method | account |
| (jq).data\|.[].signers\|.[].identifyMethods\|.[].value | signer1 |
And fetch field "(SIGN_UUID)data.0.signers.0.sign_uuid" from prevous JSON response
When as user "signer1"
And sending "get" to "/apps/libresign/p/sign/<SIGN_UUID>"
And the response should contain the initial state "libresign-action" with the following values:
Expand Down

0 comments on commit 524910d

Please sign in to comment.