[tests-only]Added GDPR export. check events when user is created (#6106)

* Added GDPR export for event upload file

* Add for user created events for GDPR export

* Add for user information assertion

* Review Address
This commit is contained in:
Sagar Gurung
2023-04-27 16:04:17 +05:45
committed by GitHub
parent b7990875c1
commit 579dcd082a
4 changed files with 306 additions and 0 deletions
@@ -2317,4 +2317,81 @@ class GraphContext implements Context {
)
);
}
/**
* @When /^user "([^"]*)" exports (?:her|his) GDPR report to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $path
*
* @return void
* @throws GuzzleException
*/
public function userGeneratesGDPRReportOfOwnDataToPath(string $user, string $path): void {
$credentials = $this->getAdminOrUserCredentials($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$this->featureContext->setResponse(
GraphHelper::generateGDPRReport(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password'],
$userId,
$path
)
);
$this->featureContext->pushToLastStatusCodesArrays();
}
/**
* @Then the downloaded JSON content should contain event type :eventType in item 'events' and should match
*
* @param string $eventType
* @param PyStringNode $schemaString
*
* @return void
* @throws GuzzleException
*
*/
public function downloadedJsonContentShouldContainEventTypeInItemAndShouldMatch(string $eventType, PyStringNode $schemaString): void {
$actualResponseToAssert = null;
$events = $this->featureContext->getJsonDecodedResponseBodyContent()->events;
foreach ($events as $event) {
if ($event->type === $eventType) {
$actualResponseToAssert = $event;
break;
}
}
if ($actualResponseToAssert === null) {
throw new Error(
"Response does not contain event type '" . $eventType . "'."
);
}
JsonAssertions::assertJsonDocumentMatchesSchema(
$actualResponseToAssert,
$this->featureContext->getJSONSchema($schemaString)
);
}
/**
* @Then the downloaded JSON content should contain key 'user' and match
*
* @param PyStringNode $schemaString
*
* @return void
* @throws GuzzleException
*
*/
public function downloadedJsonContentShouldContainKeyUserAndMatch(PyStringNode $schemaString): void {
$actualResponseToAssert = $this->featureContext->getJsonDecodedResponseBodyContent();
if (!isset($actualResponseToAssert->user)) {
throw new Error(
"Response does not contain key 'user'"
);
}
JsonAssertions::assertJsonDocumentMatchesSchema(
$actualResponseToAssert->user,
$this->featureContext->getJSONSchema($schemaString)
);
}
}