Add an integration test for the phone search API

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-12-02 16:03:54 +01:00
parent 9e04e6f99a
commit 689e3a502d
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 65 additions and 4 deletions

View File

@ -173,6 +173,37 @@ trait Provisioning {
}
}
/**
* @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";
@ -560,6 +591,19 @@ trait Provisioning {
}
}
/**
* @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

View File

@ -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
@ -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