Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevazhnovu committed Oct 9, 2024
1 parent d0d998d commit c3aebec
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.sourcepoint.cmplibrary.util.extensions.toMapOfAny
import com.sourcepoint.mobile_core.network.requests.MetaDataRequest
import com.sourcepoint.mobile_core.network.responses.MetaDataResponse
import kotlinx.serialization.json.jsonObject
import org.json.JSONArray

/**
* Factory method to create an instance of a [Service] using its implementation
Expand Down Expand Up @@ -66,14 +65,6 @@ internal class ServiceImpl(
private val connectionManager: ConnectionManager,
) : Service, NetworkClient by networkClient, CampaignManager by campaignManager {

private fun JSONArray.toArrayList(): ArrayList<String> {
val list = arrayListOf<String>()
for (i in 0 until this.length()) {
list.add(this.getString(i))
}
return list
}

override fun sendCustomConsentServ(
consentUUID: String,
propertyId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import com.sourcepoint.cmplibrary.core.Either
import com.sourcepoint.cmplibrary.core.layout.model.NativeMessageDto
import com.sourcepoint.cmplibrary.data.network.model.optimized.* // ktlint-disable
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceResp
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.* // ktlint-disable
import com.sourcepoint.cmplibrary.model.ConsentResp

/**
* Component used to convert the response body of the message call to its DTO
Expand All @@ -17,12 +15,8 @@ internal interface JsonConverter {
* @return [Either] object contain either a DTO or an [Throwable]
*/

fun toConsentResp(body: String, campaignType: CampaignType): Either<ConsentResp>

fun toConsentAction(body: String): Either<ConsentActionImpl>

fun toCustomConsentResp(body: String): Either<CustomConsentResp>

fun toNativeMessageDto(body: String): Either<NativeMessageDto>

fun toNativeMessageRespK(body: String): Either<NativeMessageRespK>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import com.sourcepoint.cmplibrary.data.network.model.optimized.* // ktlint-disab
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceResp
import com.sourcepoint.cmplibrary.data.network.model.toConsentAction
import com.sourcepoint.cmplibrary.exception.ApiRequestPostfix
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.* // ktlint-disable
import com.sourcepoint.cmplibrary.model.ConsentActionImpl
import com.sourcepoint.cmplibrary.model.ConsentResp
import com.sourcepoint.cmplibrary.model.getMap
import com.sourcepoint.cmplibrary.model.toTreeMap
import com.sourcepoint.cmplibrary.util.check
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.json.JSONObject

Expand Down Expand Up @@ -53,26 +50,6 @@ private class JsonConverterImpl : JsonConverter {
NativeMessageRespK(msg = bean)
}

override fun toConsentResp(body: String, campaignType: CampaignType): Either<ConsentResp> = check {
val obj = JSONObject(body)
val map: Map<String, Any?> = JSONObject(body).toTreeMap()
val localState = map.getMap("localState")?.toJSONObj() ?: JSONObject()
val uuid = map.getFieldValue<String>("uuid") ?: "invalid"
obj.get("userConsent")
ConsentResp(
content = JSONObject(body),
localState = localState.toString(),
uuid = uuid,
userConsent = obj["userConsent"].toString(),
campaignType = campaignType
)
}

override fun toCustomConsentResp(body: String): Either<CustomConsentResp> = check {
val obj = JSONObject(body)
CustomConsentResp(obj)
}

override fun toNativeMessageDto(body: String): Either<NativeMessageDto> = check {
JSONObject(body).toTreeMap().toNativeMessageDto()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.sourcepoint.cmplibrary.data.network.model.optimized.ConsentStatusPara
import com.sourcepoint.cmplibrary.data.network.model.optimized.MessagesParamReq
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.GetChoiceParamReq
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.CustomConsentReq
import com.sourcepoint.cmplibrary.model.PmUrlConfig
import com.sourcepoint.cmplibrary.model.exposed.MessageType
import com.sourcepoint.cmplibrary.model.exposed.MessageType.* // ktlint-disable
Expand All @@ -20,8 +19,6 @@ import okhttp3.HttpUrl
*/
internal interface HttpUrlManager {
fun inAppMessageUrl(env: Env): HttpUrl
fun sendCustomConsentUrl(env: Env): HttpUrl
fun deleteCustomConsentToUrl(host: String, params: CustomConsentReq): HttpUrl
fun pmUrl(
env: Env,
campaignType: CampaignType,
Expand Down Expand Up @@ -67,31 +64,6 @@ internal object HttpUrlManagerSingleton : HttpUrlManager {
}
}

override fun sendCustomConsentUrl(env: Env): HttpUrl {
// https://cdn.sp-stage.net/wrapper/tcfv2/v1/gdpr/custom-consent?inApp=true&env=stage
return HttpUrl.Builder()
.scheme("https")
.host(env.host)
.addPathSegments("wrapper/tcfv2/v1/gdpr/custom-consent")
.addQueryParameter("env", env.queryParam)
.addQueryParameter("inApp", "true")
.addQueryParameter("scriptType", scriptType)
.addQueryParameter("scriptVersion", scriptVersion)
.build()
}

override fun deleteCustomConsentToUrl(host: String, params: CustomConsentReq): HttpUrl {
// https://cdn.privacy-mgmt.com/consent/tcfv2/consent/v3/custom/:propertyId?consentUUID={GDPR_UUID}
return HttpUrl.Builder()
.scheme("https")
.host(host)
.addPathSegments("consent/tcfv2/consent/v3/custom/${params.propertyId}")
.addQueryParameter("consentUUID", params.consentUUID)
.addQueryParameter("scriptType", scriptType)
.addQueryParameter("scriptVersion", scriptVersion)
.build()
}

private fun urlPmGdpr(pmConf: PmUrlConfig, env: Env, messageType: MessageType): HttpUrl {

val pathSegment = when (messageType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package com.sourcepoint.cmplibrary.data.network.util
import com.sourcepoint.cmplibrary.data.network.model.optimized.* // ktlint-disable
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceResp
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceTypeParam
import com.sourcepoint.cmplibrary.model.CustomConsentResp
import okhttp3.Response

internal interface ResponseManager {
fun parseCustomConsentRes(r: Response): CustomConsentResp

fun parseConsentStatusResp(r: Response): ConsentStatusResp
fun parseGetChoiceResp(r: Response, choice: ChoiceTypeParam): ChoiceResp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceResp
import com.sourcepoint.cmplibrary.data.network.model.optimized.choice.ChoiceTypeParam
import com.sourcepoint.cmplibrary.exception.* // ktlint-disable
import com.sourcepoint.cmplibrary.exception.InvalidRequestException
import com.sourcepoint.cmplibrary.model.CustomConsentResp
import okhttp3.Response

/**
Expand All @@ -29,26 +28,6 @@ private class ResponseManagerImpl(
val logger: Logger
) : ResponseManager {

override fun parseCustomConsentRes(r: Response): CustomConsentResp {
val body = r.body?.byteStream()?.reader()?.readText() ?: ""
val status = r.code
val mess = r.message
logger.res(
tag = "CustomConsentResp",
msg = mess,
body = body,
status = status.toString()
)
return if (r.isSuccessful) {
when (val either: Either<CustomConsentResp> = jsonConverter.toCustomConsentResp(body)) {
is Either.Right -> either.r
is Either.Left -> throw either.t
}
} else {
throw InvalidRequestException(description = body)
}
}

override fun parseConsentStatusResp(r: Response): ConsentStatusResp {
val body = r.body?.byteStream()?.reader()?.readText() ?: ""
val status = r.code
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.sourcepoint.cmplibrary.data.network.util.Env
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.exception.Logger
import com.sourcepoint.cmplibrary.model.ConsentActionImpl
import com.sourcepoint.cmplibrary.model.ConsentResp
import com.sourcepoint.cmplibrary.model.exposed.ActionType
import com.sourcepoint.cmplibrary.model.exposed.SPConsents
import com.sourcepoint.cmplibrary.stub.MockExecutorManager
Expand All @@ -20,12 +19,6 @@ import org.junit.Test

class ConsentManagerImplTest {

@MockK
private lateinit var sPSuccessMock: ((SPConsents) -> Unit)

@MockK
private lateinit var sPErrorMock: ((Throwable) -> Unit)

@MockK
private lateinit var clientEventManager: ClientEventManager

Expand All @@ -41,23 +34,6 @@ class ConsentManagerImplTest {
@MockK
private lateinit var dataStorage: DataStorage

private val consentResp = ConsentResp(
uuid = "uuid_test",
localState = "localState_test",
campaignType = CampaignType.GDPR,
userConsent = "{}",
content = JSONObject()
)

private val consentAction = ConsentActionImpl(
requestFromPm = false,
campaignType = CampaignType.GDPR,
actionType = ActionType.ACCEPT_ALL,
choiceId = "123",
privacyManagerId = "100",
pmTab = "default"
)

private val consentManager by lazy {
ConsentManager.create(
service = service,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sourcepoint.cmplibrary.data.network

import com.sourcepoint.cmplibrary.assertEquals
import com.sourcepoint.cmplibrary.assertNotNull
import com.sourcepoint.cmplibrary.core.Either
import com.sourcepoint.cmplibrary.data.network.model.optimized.* // ktlint-disable
import com.sourcepoint.cmplibrary.data.network.model.optimized.includeData.buildIncludeData
Expand All @@ -12,12 +11,9 @@ import com.sourcepoint.cmplibrary.exception.ApiRequestPostfix
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.exception.CodeList
import com.sourcepoint.cmplibrary.exception.ConnectionTimeoutException
import com.sourcepoint.cmplibrary.model.CustomConsentReq
import com.sourcepoint.cmplibrary.model.CustomConsentResp
import com.sourcepoint.cmplibrary.model.exposed.ActionType
import com.sourcepoint.cmplibrary.readText
import com.sourcepoint.cmplibrary.stub.MockLogger
import com.sourcepoint.cmplibrary.util.file2String
import com.sourcepoint.mobile_core.models.SPNetworkError
import io.mockk.* // ktlint-disable
import io.mockk.impl.annotations.MockK
Expand Down Expand Up @@ -62,44 +58,30 @@ class NetworkClientImplTest {

@Test
fun `EXECUTE deleteCustomConsentTo THROWS an exception with okHttp`() {
val req = CustomConsentReq(
consentUUID = "uuid",
legIntCategories = listOf("a"),
categories = listOf("b"),
vendors = listOf(),
propertyId = 1
)
assertThrows(
SPNetworkError::class.java
) {
sut.deleteCustomConsentTo(
req.consentUUID,
req.propertyId,
req.vendors,
req.categories,
req.legIntCategories
"uuid",
1,
listOf("a"),
listOf("b"),
listOf()
)
}
}

@Test
fun `EXECUTE sendCustomConsent THROWS an exception with okHttp`() {
val req = CustomConsentReq(
consentUUID = "uuid",
legIntCategories = listOf("a"),
categories = listOf("b"),
vendors = listOf(),
propertyId = 1
)
assertThrows(
SPNetworkError::class.java
) {
sut.sendCustomConsent(
req.consentUUID,
req.propertyId,
req.vendors,
req.categories,
req.legIntCategories
"uuid",
1,
listOf("a"),
listOf("b"),
listOf()
)
}
}
Expand Down
Loading

0 comments on commit c3aebec

Please sign in to comment.