Skip to content

Commit

Permalink
Add an integration test for the phone search API
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Dec 2, 2020
1 parent 86fe4de commit 0d63b89
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
44 changes: 44 additions & 0 deletions build/integration/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,37 @@ public function userHasSetting($user, $settings) {
}
}

/**
* @Then /^search users by phone for region "([^"]*)" with$/
*
* @param string $user
* @param \Behat\Gherkin\Node\TableNode|null $settings
*/
public function searchUserByPhone($region, \Behat\Gherkin\Node\TableNode $searchTable) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/search/by-phone";
$client = new Client();
$options = [];
$options['auth'] = $this->adminUser;
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];

$search = [];
foreach ($searchTable->getRows() as $row) {
if (!isset($search[$row[0]])) {
$search[$row[0]] = [];
}
$search[$row[0]][] = $row[1];
}

$options['form_params'] = [
'location' => $region,
'search' => $search,
];

$this->response = $client->post($fullUrl, $options);
}

public function createUser($user) {
$previous_user = $this->currentUser;
$this->currentUser = "admin";
Expand Down Expand Up @@ -560,6 +591,19 @@ public function theUsersShouldBe($usersList) {
}
}

/**
* @Then /^phone matches returned are$/
* @param \Behat\Gherkin\Node\TableNode|null $usersList
*/
public function thePhoneUsersShouldBe($usersList) {
if ($usersList instanceof \Behat\Gherkin\Node\TableNode) {
$users = $usersList->getRowsHash();
$listCheckedElements = simplexml_load_string($this->response->getBody())->data;
$respondedArray = json_decode(json_encode($listCheckedElements), true);
Assert::assertEquals($users, $respondedArray);
}
}

/**
* @Then /^detailed users returned are$/
* @param \Behat\Gherkin\Node\TableNode|null $usersList
Expand Down
25 changes: 21 additions & 4 deletions build/integration/features/provisioning-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ Feature: provisioning
And the HTTP status code should be "200"
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | email |
| value | brand-new-user@gmail.com |
| value | no-reply@nextcloud.com |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | phone |
| value | 0123 456 789 |
| value | 0711 / 25 24 28-90 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And sending "PUT" to "/cloud/users/brand-new-user" with
Expand All @@ -97,12 +97,29 @@ Feature: provisioning
Then user "brand-new-user" has
| id | brand-new-user |
| displayname | Brand New User |
| email | brand-new-user@gmail.com |
| phone | 0123 456 789 |
| email | no-reply@nextcloud.com |
| phone | +4971125242890 |
| address | Foo Bar Town |
| website | https://nextcloud.com |
| twitter | Nextcloud |

Scenario: Search by phone number
Given As an "admin"
And user "phone-user" exists
And sending "PUT" to "/cloud/users/phone-user" with
| key | phone |
| value | 0711 / 25 24 28-90 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
Then search users by phone for region "DE" with
| random-string1 | 0711 / 123 456 78 |
| random-string1 | 0711 / 252 428-90 |
| random-string2 | 0711 / 90-824 252 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
Then phone matches returned are
| random-string1 | phone-user@http://localhost:8080/ |

Scenario: Create a group
Given As an "admin"
And group "new-group" does not exist
Expand Down

0 comments on commit 0d63b89

Please sign in to comment.