Skip to content

Commit

Permalink
add edge case for check file info
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Sep 18, 2024
1 parent b29538b commit 898b91c
Show file tree
Hide file tree
Showing 3 changed files with 673 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
Expand All @@ -33,6 +34,7 @@
class CollaborationContext implements Context {
private FeatureContext $featureContext;
private SpacesContext $spacesContext;
private string $storeLastAppEndpointResponse;

/**
* This will run before EVERY scenario.
Expand All @@ -52,6 +54,21 @@ public function before(BeforeScenarioScope $scope): void {
$this->spacesContext = $environment->getContext('SpacesContext');
}

/**
* @param string $appData
* @return void
*/
public function storeLastAppEndpointResponse(string $appData): void {
$this->storeLastAppEndpointResponse = $appData;
}

/**
* @return string
*/
public function getLastAppEndpointResponse(): string {
return $this->storeLastAppEndpointResponse;
}

/**
* @When user :user checks the information of file :file of space :space using office :app
* @When user :user checks the information of file :file of space :space using office :app with view mode :view
Expand Down Expand Up @@ -205,4 +222,42 @@ public function userTriesToCheckTheInformationOfFileOfSpaceUsingOfficeWithInvali
)
);
}

/**
* @Given user :user has sent POST request on app endpoint:
*/
public function userHasSentPostRequestOnAppEndpoint($user, TableNode $items) {
$rows = $items->getRowsHash();
$appResponse = CollaborationHelper::sendPOSTRequestToAppOpen(
$this->spacesContext->getFileId($user, $rows['space'], $rows['resource']),
$rows['suites'],
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef()
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $appResponse);
$this->storeLastAppEndpointResponse($appResponse->getBody()->getContents());
}

/**
* @When user :user tries to get the file information of file using wopi endpoint
* @When user :user gets the file information of file using wopi endpoint
*/
public function userTriesToCheckTheInformationOfDeletedFileUsingWopiEndpoint(string $user) {
$response = json_decode($this->getLastAppEndpointResponse());
$accessToken = $response->form_parameters->access_token;

// Extract the WOPISrc from the app_url
$parsedUrl = parse_url($response->app_url);
parse_str($parsedUrl['query'], $queryParams);
$wopiSrc = $queryParams['WOPISrc'];

$this->featureContext->setResponse(
HttpRequestHelper::get(
$wopiSrc . "?access_token=$accessToken",
$this->featureContext->getStepLineRef()
)
);
}
}
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ default:
- FeatureContext: *common_feature_context_params
- SharingNgContext:
- CollaborationContext:
- TrashbinContext:


cliCommands:
Expand Down
Loading

0 comments on commit 898b91c

Please sign in to comment.