Skip to content

Commit

Permalink
Changes after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Nov 8, 2023
1 parent 6a1dd33 commit 994330a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
entry = JsonPrimitive(expectedMessage),
timetoken = result.timetoken,
meta = expectedMeta,
error = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED.message
error = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED
)
)

Expand Down Expand Up @@ -248,7 +248,7 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
meta = expectedMeta,
messageType = HistoryMessageType.Message,
actions = emptyMap<String, Map<String, List<Action>>>(),
error = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED.message
error = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED
)

val expectedChannelsResponse: Map<String, List<PNFetchMessageItem>> =
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/pubnub/api/endpoints/History.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class History internal constructor(

var timetoken: Long? = null
var meta: JsonElement? = null
val historyMessageWithError: Pair<JsonElement, String?>
val historyMessageWithError: Pair<JsonElement, PubNubError?>

if (includeTimetoken || includeMeta) {
historyMessageWithError = pubnub.mapper.getField(historyEntry, "message")!!.processHistoryMessage(pubnub.cryptoModule, pubnub.mapper)
Expand All @@ -88,7 +88,7 @@ class History internal constructor(
}

val message: JsonElement = historyMessageWithError.first
val error: String? = historyMessageWithError.second
val error: PubNubError? = historyMessageWithError.second

val historyItem = PNHistoryItemResult(
entry = message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.pubnub.api.models.consumer.history

import com.google.gson.JsonElement
import com.pubnub.api.PubNub
import com.pubnub.api.PubNubError
import com.pubnub.api.endpoints.FetchMessages
import com.pubnub.api.models.consumer.PNBoundedPage

Expand Down Expand Up @@ -39,7 +40,7 @@ data class PNFetchMessageItem(
val timetoken: Long,
val actions: Map<String, Map<String, List<Action>>>? = null,
val messageType: HistoryMessageType?,
val error: String? = null
val error: PubNubError? = null
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.pubnub.api.models.consumer.history

import com.google.gson.JsonElement
import com.pubnub.api.PubNub
import com.pubnub.api.PubNubError
import com.pubnub.api.endpoints.History

/**
Expand Down Expand Up @@ -29,5 +30,5 @@ data class PNHistoryItemResult(
val entry: JsonElement,
val timetoken: Long? = null,
val meta: JsonElement? = null,
val error: String? = null
val error: PubNubError? = null
)
10 changes: 5 additions & 5 deletions src/main/kotlin/com/pubnub/extension/JsonElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private const val PN_OTHER = "pn_other"
internal fun JsonElement.processHistoryMessage(
cryptoModule: CryptoModule?,
mapper: MapperManager
): Pair<JsonElement, String?> {
): Pair<JsonElement, PubNubError?> {

cryptoModule ?: return Pair(this, null)

Expand Down Expand Up @@ -51,8 +51,8 @@ internal fun JsonElement.processHistoryMessage(
return Pair(outputObject, null)
}

private fun logAndReturnDecryptionError(): String {
val errorMessage = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED.message
log.warn(errorMessage)
return errorMessage
private fun logAndReturnDecryptionError(): PubNubError {
val pnError = PubNubError.CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED
log.warn(pnError.message)
return pnError
}
4 changes: 2 additions & 2 deletions src/test/kotlin/com/pubnub/extension/JsonElementTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class JsonElementTest {

// then
assertEquals(objectUnderTest, jsonElement)
assertEquals("Crypto is configured but message is not encrypted.", errorMessage)
assertEquals("Crypto is configured but message is not encrypted.", errorMessage?.message)
}

@ParameterizedTest
Expand Down Expand Up @@ -134,7 +134,7 @@ class JsonElementTest {

// then
assertEquals(objectUnderTest, jsonElement)
assertEquals("Crypto is configured but message is not encrypted.", errorMessage)
assertEquals("Crypto is configured but message is not encrypted.", errorMessage?.message)
}

@ParameterizedTest
Expand Down

0 comments on commit 994330a

Please sign in to comment.