Skip to content

Commit a5a5c77

Browse files
committed
test: get single share form share store
Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
1 parent 99f1c3a commit a5a5c77

File tree

8 files changed

+139
-67
lines changed

8 files changed

+139
-67
lines changed

tests/acceptance/bootstrap/FeatureContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ private function validateSchemaArray(JsonSchema $schemaObj): void {
11161116
$value = $schemaObj->$validator;
11171117
switch ($validator) {
11181118
case "items":
1119-
if ($schemaObj->maxItems === 0) {
1119+
if ($schemaObj->maxItems === 0 || empty($schemaObj->items)) {
11201120
break;
11211121
}
11221122
Assert::assertNotNull($schemaObj->$validator, \sprintf($errMsg, $validator));

tests/acceptance/bootstrap/GraphContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,11 @@ public function theJsonDataResponseShouldOrNotContainSharedByMeDetails(
27322732
if (!$shouldContain && !$fileOrFolderFound) {
27332733
return;
27342734
}
2735+
if ($shouldContain && !$fileOrFolderFound) {
2736+
Assert::fail(
2737+
'Response does not contain file or folder "' . $fileName . '" but should.',
2738+
);
2739+
}
27352740
Assert::assertFalse(
27362741
!$shouldContain && $fileOrFolderFound,
27372742
'Response contains file "' . $fileName . '" but should.',

tests/acceptance/bootstrap/OcisConfigContext.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ public function theAdministratorHasEnabledTheRole(string $role): void {
127127
*
128128
* @return void
129129
*/
130-
public function theAdministratorHasEnabledTheFollowingShareRoles(TableNode $table): void {
130+
public function theAdministratorHasEnabledTheFollowingSharePermissionsRoles(TableNode $table): void {
131131
$defaultRoles = array_values(GraphHelper::DEFAULT_PERMISSIONS_ROLES);
132132
$roles = [];
133133
foreach ($table->getHash() as $row) {
134-
$roles[] = $row['role'];
135-
$roleId = GraphHelper::getPermissionsRoleIdByName($row['role']);
134+
$roles[] = $row['permissions-role'];
135+
$roleId = GraphHelper::getPermissionsRoleIdByName($row['permissions-role']);
136136
if (!\in_array($roleId, $defaultRoles)) {
137137
$defaultRoles[] = $roleId;
138138
}
@@ -141,12 +141,12 @@ public function theAdministratorHasEnabledTheFollowingShareRoles(TableNode $tabl
141141
$envs = [
142142
"GRAPH_AVAILABLE_ROLES" => implode(',', $defaultRoles),
143143
];
144-
$response = OcisConfigHelper::reConfigureOcis($envs);
144+
$response = OcisConfigHelper::reConfigureOcis($envs);
145145

146146
Assert::assertEquals(
147147
200,
148148
$response->getStatusCode(),
149-
"Failed to enable roles: " . implode(', ', $roles)
149+
"Failed to enable roles: " . implode(', ', $roles),
150150
);
151151
$this->setEnabledPermissionsRoles($defaultRoles);
152152
}

tests/acceptance/bootstrap/Sharing.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,23 @@ public function shareNgGetLastCreatedLinkShare(): ?array {
135135

136136
/**
137137
* @param ResponseInterface $response
138+
* @param string $resource
139+
* @param string $space
138140
*
139141
* @return void
140142
*/
141-
public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void {
142-
$this->shareNgCreatedUserGroupShares[] = $this->getJsonDecodedResponse($response);
143+
public function shareNgAddToCreatedUserGroupShares(
144+
ResponseInterface $response,
145+
string $resource,
146+
string $space,
147+
): void {
148+
$share = $this->getJsonDecodedResponse($response);
149+
if (\array_key_exists("value", $share)) {
150+
$share = $share["value"][0];
151+
}
152+
$share["resource"] = $resource;
153+
$share["space"] = $space;
154+
$this->shareNgCreatedUserGroupShares[] = $share;
143155
}
144156

145157
/**
@@ -149,6 +161,40 @@ public function shareNgGetLastCreatedUserGroupShare(): ?array {
149161
return \end($this->shareNgCreatedUserGroupShares);
150162
}
151163

164+
/**
165+
* @param string $sharer
166+
* @param string $sharee
167+
* @param string $space
168+
* @param string $resource
169+
*
170+
* @return array
171+
*/
172+
public function shareNgGetCreatedUserGroupShare(
173+
string $sharer,
174+
string $sharee,
175+
string $space,
176+
string $resource = '',
177+
): array {
178+
foreach ($this->shareNgCreatedUserGroupShares as $share) {
179+
$shareOwner = $share["invitation"]["invitedBy"]["user"]["displayName"];
180+
$shareReceiver = $share["grantedToV2"]["user"]["displayName"];
181+
if ($shareOwner === $this->getUserDisplayName($sharer)
182+
&& $shareReceiver === $this->getUserDisplayName($sharee)
183+
&& $share["resource"] === $resource
184+
&& $share["space"] === $space
185+
) {
186+
return $share;
187+
}
188+
}
189+
Assert::fail(
190+
"Share not found:\n" .
191+
"\tsharer: $sharer\n" .
192+
"\tsharee: $sharee\n" .
193+
"\tresource: $resource\n" .
194+
"\tspace: $space",
195+
);
196+
}
197+
152198
/**
153199
* @param string $sharer
154200
* @param SimpleXMLElement $shareData
@@ -250,10 +296,10 @@ public function shareNgUpdatedCreatedLinkShare(string $permissionId, ResponseInt
250296
*/
251297
public function shareNgGetLastCreatedUserGroupShareID(): string {
252298
$lastResponse = $this->shareNgGetLastCreatedUserGroupShare();
253-
if (!isset($lastResponse['value'][0]['id'])) {
299+
if (!isset($lastResponse['id'])) {
254300
throw new Error('Response did not contain share id for the last created share.');
255301
}
256-
return $lastResponse['value'][0]['id'];
302+
return $lastResponse['id'];
257303
}
258304

259305
/**
@@ -264,7 +310,7 @@ public function shareNgGetLastCreatedUserGroupShareID(): string {
264310
*/
265311
public function shareNgUpdateCreatedUserGroupShare(string $permissionId, ResponseInterface $response): void {
266312
foreach ($this->shareNgCreatedUserGroupShares as $key => $share) {
267-
if ($share['value'][0]['id'] === $permissionId) {
313+
if ($share['id'] === $permissionId) {
268314
$decodedResponse = $this->getJsonDecodedResponse($response);
269315
$this->shareNgCreatedUserGroupShares[$key]['value'] = $decodedResponse;
270316
return;

tests/acceptance/bootstrap/SharingNgContext.php

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ public function sendShareInvitation(
377377
$expirationDateTime,
378378
);
379379
if ($response->getStatusCode() === 200) {
380-
$this->featureContext->shareNgAddToCreatedUserGroupShares($response);
380+
$this->featureContext->shareNgAddToCreatedUserGroupShares(
381+
$response,
382+
$shareInfo['resource'] ?? '',
383+
$shareInfo['space'],
384+
);
381385
}
382386
return $response;
383387
}
@@ -696,12 +700,36 @@ public function userHasUpdatedTheLastResourceShareWithTheFollowingProperties(str
696700
$permissionID = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
697701
$response = $this->updateResourceShare(
698702
$user,
699-
$table,
703+
$table->getRowsHash(),
700704
$permissionID,
701705
);
702706
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 200", $response);
703707
}
704708

709+
/**
710+
* @Given user :user has updated the following resource share:
711+
*
712+
* @param string $user
713+
* @param TableNode $table
714+
*
715+
* @return void
716+
*/
717+
public function userHasUpdatedTheFollowingResourceShare(string $user, TableNode $table): void {
718+
$updateInfo = $table->getRowsHash();
719+
$share = $this->featureContext->shareNgGetCreatedUserGroupShare(
720+
$user,
721+
$updateInfo["sharee"],
722+
$updateInfo["space"],
723+
$updateInfo["resource"],
724+
);
725+
$response = $this->updateResourceShare(
726+
$user,
727+
$updateInfo,
728+
$share["id"],
729+
);
730+
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed to update share", $response);
731+
}
732+
705733
/**
706734
* @When user :user updates the last resource share with the following properties using the Graph API:
707735
*
@@ -715,7 +743,7 @@ public function userUpdatesTheLastShareWithFollowingPropertiesUsingGraphApi($use
715743
$this->featureContext->setResponse(
716744
$this->updateResourceShare(
717745
$user,
718-
$table,
746+
$table->getRowsHash(),
719747
$permissionID,
720748
),
721749
);
@@ -747,38 +775,37 @@ public function userUpdatesTheSpaceShareForUserOrGroupWithFollowingUsingGraphApi
747775
$this->featureContext->setResponse(
748776
$this->updateResourceShare(
749777
$user,
750-
$table,
778+
$table->getRowsHash(),
751779
$permissionID,
752780
),
753781
);
754782
}
755783

756784
/**
757785
* @param string $user
758-
* @param TableNode $body
786+
* @param array $updateInfo
759787
* @param string $permissionID
760788
*
761789
* @return ResponseInterface
762790
*/
763-
public function updateResourceShare(string $user, TableNode $body, string $permissionID): ResponseInterface {
764-
$bodyRows = $body->getRowsHash();
765-
$space = $this->spacesContext->getSpaceByName($user, $bodyRows['space']);
791+
public function updateResourceShare(string $user, array $updateInfo, string $permissionID): ResponseInterface {
792+
$space = $this->spacesContext->getSpaceByName($user, $updateInfo['space']);
766793
$spaceId = $space["id"];
767794
// for updating role of project space shared, we do not need to provide resource
768-
$resource = $bodyRows['resource'] ?? '';
769-
if ($resource === '' && !\in_array($bodyRows['space'], ['Personal', 'Shares'])) {
795+
$resource = $updateInfo['resource'] ?? '';
796+
if ($resource === '' && !\in_array($updateInfo['space'], ['Personal', 'Shares'])) {
770797
$itemId = $space['fileId'];
771798
} else {
772-
$itemId = $this->spacesContext->getResourceId($user, $bodyRows['space'], $resource);
799+
$itemId = $this->spacesContext->getResourceId($user, $updateInfo['space'], $resource);
773800
}
774801
$body = [];
775-
if (\array_key_exists('permissionsRole', $bodyRows)) {
776-
$body['roles'] = [GraphHelper::getPermissionsRoleIdByName($bodyRows['permissionsRole'])];
802+
if (\array_key_exists('permissionsRole', $updateInfo)) {
803+
$body['roles'] = [GraphHelper::getPermissionsRoleIdByName($updateInfo['permissionsRole'])];
777804
}
778805

779-
if (\array_key_exists('expirationDateTime', $bodyRows)) {
780-
$body['expirationDateTime'] = empty($bodyRows['expirationDateTime'])
781-
? null : $bodyRows['expirationDateTime'];
806+
if (\array_key_exists('expirationDateTime', $updateInfo)) {
807+
$body['expirationDateTime'] = empty($updateInfo['expirationDateTime'])
808+
? null : $updateInfo['expirationDateTime'];
782809
}
783810

784811
$response = GraphHelper::updateShare(

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,7 @@ public function userExpiresTheLastShareOfResourceInsideOfTheSpace(
27372737
);
27382738

27392739
if ($response->getStatusCode() === 200) {
2740-
$this->featureContext->shareNgAddToCreatedUserGroupShares($response);
2740+
$this->featureContext->shareNgAddToCreatedUserGroupShares($response, $resource, $spaceName);
27412741
}
27422742
$this->featureContext->setResponse($response);
27432743
} else {

0 commit comments

Comments
 (0)