diff --git a/app/src/full/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModel.kt b/app/src/full/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModel.kt index ef9e76b..53e4301 100644 --- a/app/src/full/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModel.kt +++ b/app/src/full/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModel.kt @@ -1386,10 +1386,14 @@ class AddAccountViewModel @Inject constructor( } } + // The port is part of the name: two servers on one host are two accounts (#105). private fun accountName(): String = - username.takeIf { it.isNotBlank() }?.let { "$it@${serverRoot?.host.orEmpty()}" } + username.takeIf { it.isNotBlank() }?.let { "$it@${serverRoot?.authority().orEmpty()}" } ?: typedInput + private fun HttpUrl.authority(): String = + if (port == HttpUrl.defaultPort(scheme)) host else "$host:$port" + internal companion object { const val POLL_INTERVAL_MILLIS = 2_000L diff --git a/app/src/testFull/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModelTest.kt b/app/src/testFull/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModelTest.kt index ee123ff..dd3d34c 100644 --- a/app/src/testFull/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModelTest.kt +++ b/app/src/testFull/java/de/jeanlucmakiola/agendula/ui/accounts/add/AddAccountViewModelTest.kt @@ -1307,6 +1307,15 @@ class AddAccountViewModelTest { assertThat(vm.state.value.fatal).isEqualTo(AddAccountMessage.ExternalStorage) } + @Test + fun `a server on its own port is named with it`() = runTest(dispatcher) { + val vm = signedIn("https://cloud.example.com:5233/") + vm.onSave() + advanceUntilIdle() + + assertThat(creator.created).containsExactly("me@cloud.example.com:5233") + } + @Test fun `a completed add reports the account it created`() = runTest(dispatcher) { val vm = signedIn() @@ -1406,12 +1415,14 @@ class AddAccountViewModelTest { * submit, so going straight from the address to a `Found` leaves the * username and password empty. */ - private fun kotlinx.coroutines.test.TestScope.signedIn(): AddAccountViewModel { + private fun kotlinx.coroutines.test.TestScope.signedIn( + address: String = "https://cloud.example.com/", + ): AddAccountViewModel { gateway.discoveryOutcomes += CalDavDiscovery.Outcome.NeedsAuthentication(emptyList()) gateway.loginFlow = null val vm = viewModel() - vm.enterAddress("https://cloud.example.com/") + vm.enterAddress(address) vm.onAddressSubmitted() advanceUntilIdle()