Browse Source

fix(phonenumber): Fix migration and add missing test

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/14992/head
Joas Schilling 6 months ago
parent
commit
143ccde40a
No known key found for this signature in database GPG Key ID: F72FA5B49FFA96B0
  1. 2
      appinfo/info.xml
  2. 3
      lib/Command/PhoneNumber/FindPhoneNumber.php
  3. 15
      lib/Migration/Version21001Date20250417141337.php
  4. 1
      lib/Model/PhoneNumber.php
  5. 3
      tests/integration/features/bootstrap/CommandLineTrait.php
  6. 70
      tests/integration/features/command/phone-number.feature
  7. 3
      tests/integration/spreedcheats/lib/Controller/ApiController.php

2
appinfo/info.xml

@ -18,7 +18,7 @@
* 🌉 **Sync with other chat solutions** With [Matterbridge](https://github.com/42wim/matterbridge/) being integrated in Talk, you can easily sync a lot of other chat solutions to Nextcloud Talk and vice-versa.
]]></description>
<version>21.1.0-dev.2</version>
<version>21.1.0-dev.3</version>
<licence>agpl</licence>
<author>Anna Larch</author>

3
lib/Command/PhoneNumber/FindPhoneNumber.php

@ -73,8 +73,7 @@ class FindPhoneNumber extends Base {
$entry = array_pop($entries);
$output->writeln($entry->getActorId() . ' has phone number ' . $entry->getPhoneNumber() . ' assigned');
} else {
$entry = array_pop($entries);
$output->writeln($entry->getActorId() . ' has the following phone numbers assigned:');
$output->writeln($userId . ' has the following phone numbers assigned:');
foreach ($entries as $entry) {
$output->writeln(' - ' . $entry->getPhoneNumber());
}

15
lib/Migration/Version21001Date20250327161337.php → lib/Migration/Version21001Date20250417141337.php

@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@ -14,7 +15,7 @@ use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version21001Date20250327161337 extends SimpleMigrationStep {
class Version21001Date20250417141337 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
@ -26,11 +27,16 @@ class Version21001Date20250327161337 extends SimpleMigrationStep {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('talk_phone_numbers')) {
if ($schema->hasTable('talk_phone_numbers')) {
return null;
}
$table = $schema->createTable('talk_phone_numbers');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
$table->addColumn('phone_number', Types::STRING, [
'notnull' => true,
'length' => 255,
@ -40,7 +46,8 @@ class Version21001Date20250327161337 extends SimpleMigrationStep {
'length' => 255,
]);
$table->setPrimaryKey(['phone_number']);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['phone_number']);
$table->addIndex(['actor_id']);
return $schema;
}

1
lib/Model/PhoneNumber.php

@ -12,6 +12,7 @@ use OCP\AppFramework\Db\Entity;
use OCP\DB\Types;
/**
* @psalm-method int<1, max> getId()
* @method void setPhoneNumber(string $phoneNumber)
* @method string getPhoneNumber()
* @method void setActorId(string $actorId)

3
tests/integration/features/bootstrap/CommandLineTrait.php

@ -156,7 +156,7 @@ trait CommandLineTrait {
#[Then('/^the command failed with exit code ([0-9]+)$/')]
public function theCommandFailedWithExitCode(int $exitCode): void {
Assert::assertEquals($exitCode, $this->lastCode, 'The commands exit code did not match');
Assert::assertEquals($exitCode, $this->lastCode, 'The commands exit code did not match: ' . $this->lastStdOut . "\n\n" . $this->lastStdErr);
}
#[Then('/^the command failed with exception text "([^"]*)"$/')]
@ -173,6 +173,7 @@ trait CommandLineTrait {
#[Then('/^the command output contains the text:$/')]
#[Then('/^the command output contains the text "([^"]*)"$/')]
#[Then("/^the command output contains the text '([^']*)'\$/")]
public function theCommandOutputContainsTheText(string $text): void {
if ($this->lastStdOut === '' && $this->lastStdErr !== '') {
Assert::assertStringContainsString($text, $this->lastStdErr, 'The command did not output the expected text on stdout');

70
tests/integration/features/command/phone-number.feature

@ -0,0 +1,70 @@
Feature: command/phone-number
Background:
Given user "participant1" exists
Given user "participant2" exists
Scenario: Configuring a phone number
Given invoking occ with "talk:phone-number:add abc participant1"
Then the command failed with exit code 1
And the command output contains the text "Not a valid phone number abc. The format is invalid."
Given invoking occ with "talk:phone-number:add +49-160-123-12-12 participant3"
Then the command failed with exit code 1
And the command output contains the text 'Invalid user "participant3" provided'
Given invoking occ with "talk:phone-number:add +49-160-123-12-12 participant1"
Then the command failed with exit code 0
And the command output contains the text "Phone number +491601231212 is now assigned to participant1"
Given invoking occ with "talk:phone-number:find --phone +491601231212"
Then the command failed with exit code 0
And the command output contains the text "Phone number +491601231212 is assigned to participant1"
Given invoking occ with "talk:phone-number:find --phone +49160123121234"
Then the command failed with exit code 1
And the command output contains the text "Phone number +49160123121234 could not be found"
Given invoking occ with "talk:phone-number:find --user participant1"
Then the command failed with exit code 0
And the command output contains the text "participant1 has phone number +491601231212 assigned"
Given invoking occ with "talk:phone-number:find --user participant2"
Then the command failed with exit code 1
And the command output contains the text "No phone number found for participant2"
Given invoking occ with "talk:phone-number:add +49-160-123-1213 participant1"
Then the command failed with exit code 0
And the command output contains the text "Phone number +491601231213 is now assigned to participant1"
Given invoking occ with "talk:phone-number:find --user participant1"
Then the command failed with exit code 0
And the command output contains the text "participant1 has the following phone numbers assigned:"
And the command output contains the text "- +491601231212"
And the command output contains the text "- +491601231213"
Given invoking occ with "talk:phone-number:add +49-160-123-1212 participant2"
Then the command failed with exit code 1
And the command output contains the text "Phone number is already assigned to participant1"
Given invoking occ with "talk:phone-number:add --force '+49-160-123-12-12' participant2"
Then the command failed with exit code 0
And the command output contains the text "Phone number +491601231212 is now assigned to participant2"
And the command output contains the text "Was assigned to participant1"
Given invoking occ with "talk:phone-number:find --user participant1"
Then the command failed with exit code 0
And the command output contains the text "participant1 has phone number +491601231213 assigned"
Given invoking occ with "talk:phone-number:remove +491601231213"
Then the command failed with exit code 0
Given invoking occ with "talk:phone-number:find --user participant1"
Then the command failed with exit code 1
And the command output contains the text "No phone number found for participant1"
Given invoking occ with "talk:phone-number:remove-user participant2"
Then the command failed with exit code 0
Given invoking occ with "talk:phone-number:find --user participant2"
Then the command failed with exit code 1
And the command output contains the text "No phone number found for participant2"

3
tests/integration/spreedcheats/lib/Controller/ApiController.php

@ -56,6 +56,9 @@ class ApiController extends OCSController {
$delete = $this->db->getQueryBuilder();
$delete->delete('talk_invitations')->executeStatement();
$delete = $this->db->getQueryBuilder();
$delete->delete('talk_phone_numbers')->executeStatement();
$delete = $this->db->getQueryBuilder();
$delete->delete('talk_polls')->executeStatement();

Loading…
Cancel
Save