Skip to content

Commit

Permalink
fix: Extract linkUUID from an url + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Oct 22, 2024
1 parent a0d2881 commit cae4cf3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.infomaniak.multiplatform_swisstransfer.network.exceptions.UnexpectedA
import com.infomaniak.multiplatform_swisstransfer.network.models.ApiResponse
import com.infomaniak.multiplatform_swisstransfer.network.models.transfer.TransferApi
import com.infomaniak.multiplatform_swisstransfer.network.requests.TransferRequest
import com.infomaniak.multiplatform_swisstransfer.network.utils.ApiRoutes
import io.ktor.client.HttpClient
import kotlinx.serialization.json.Json
import kotlin.coroutines.cancellation.CancellationException
Expand Down Expand Up @@ -61,5 +60,5 @@ class TransferRepository internal constructor(private val transferRequest: Trans
return transferRequest.getTransfer(extractUuid(url))
}

private fun extractUuid(url: String) = url.substringAfter(ApiRoutes.baseUrl)
internal fun extractUuid(url: String) = url.substringAfterLast("/")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.network

import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository
import kotlin.test.Test
import kotlin.test.assertEquals

class TransferRepositoryTest {

private val transferRepository = TransferRepository(ApiClientProvider()) // TODO: Use mock client

@Test
fun canExtractLinkUuidFromUrl() {
val url = "https://www.swisstransfer.com/d/fa7d299d-1001-4668-83a4-2a9b61aa59e8"
val result = transferRepository.extractUuid(url)
assertEquals("fa7d299d-1001-4668-83a4-2a9b61aa59e8", result)
}
}

0 comments on commit cae4cf3

Please sign in to comment.