Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinstardust committed Mar 27, 2024
1 parent 39dffe3 commit b9dc3e5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion library/src/main/java/com/paypal/messages/ModalFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ internal class ModalFragment(
*/
@JavascriptInterface
fun paypalMessageModalCallbackHandler(passedParams: String) {
val params = if (passedParams != "") passedParams else "{\"name\": \"\", \"args\": [{}]"
val params = if (passedParams != "") passedParams else """{"name": "", "args": [{}]} """
val nameAndArgs = JsonParser.parseString(params).asJsonObject
val name = nameAndArgs.get("name").asString
val args = nameAndArgs.get("args").asJsonArray[0].asJsonObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ModalCloseButtonTest {
availableHeight = 200,
color = "#FFFFFF",
colorType = "solid",
alternativeText = "test_alternative_text",
)

@Test
Expand All @@ -22,6 +23,7 @@ class ModalCloseButtonTest {
assertEquals(modalCloseButton.availableHeight, 200)
assertEquals(modalCloseButton.color, "#FFFFFF")
assertEquals(modalCloseButton.colorType, "solid")
assertEquals(modalCloseButton.alternativeText, "test_alternative_text")
}

@Test
Expand All @@ -31,7 +33,8 @@ class ModalCloseButtonTest {

assertEquals(
json,
"{\"width\":100,\"height\":100,\"available_width\":200,\"available_height\":200,\"color\":\"#FFFFFF\",\"color_type\":\"solid\"}",
@Suppress("ktlint:standard:max-line-length")
"""{"width":100,"height":100,"available_width":200,"available_height":200,"color":"#FFFFFF","color_type":"solid","alternative_text":"test_alternative_text"}""",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ApiHashDataTest {
val json = gson.toJson(response)
assertEquals(
json,
"{\"cache_flow_disabled\":true,\"ttl_soft\":1000,\"ttl_hard\":2000,\"merchant_profile\":{\"hash\":\"test_merchant_profile_hash\"}}",
@Suppress("ktlint:standard:max-line-length")
"""{"cache_flow_disabled":true,"ttl_soft":1000,"ttl_hard":2000,"merchant_profile":{"hash":"test_merchant_profile_hash"}}""",
)
}

Expand All @@ -44,6 +45,6 @@ class ApiHashDataTest {
@Test
fun testMerchantProfileSerialization() {
val json = gson.toJson(merchantProfile)
assertEquals(json, "{\"hash\":\"test_merchant_profile_hash\"}")
assertEquals(json, """{"hash":"test_merchant_profile_hash"}""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class ApiMessageDataTest {
)

private val main = "test_main"
private val mainAlternative = "test_alternative"
private val disclaimer = "test_disclaimer"
private val contentDetails = ApiMessageData.ContentDetails(main, disclaimer)
private val contentDetails = ApiMessageData.ContentDetails(main, mainAlternative, disclaimer)
private val contentOptions = ApiMessageData.ContentOptions(contentDetails, contentDetails)
private val response = ApiMessageData.Response(metadata, contentOptions)

Expand All @@ -65,7 +66,7 @@ class ApiMessageDataTest {
val json = gson.toJson(response)

@Suppress("ktlint:standard:max-line-length")
val expectedJson = """{"meta":{"credit_product_group":"PAYPAL_CREDIT","offer_country_code":"US","offer_type":"PAY_LATER_SHORT_TERM","message_type":"OFFER","modal_close_button":{"width":100,"height":100,"available_width":200,"available_height":200,"color":"#FFFFFF","color_type":"solid"},"variables":{"inline_logo_placeholder":"test_logo_placeholder"},"merchant_country_code":"US","credit_product_identifiers":["test_credit_product_identifier"],"debug_id":"test_debug_id","fdata":"test_fdata","tracking_keys":["test_tracking_key"],"originating_instance_id":"350e8400-e29b-41d4-a716-446655440000"},"content":{"default":{"main":"test_main","disclaimer":"test_disclaimer"},"generic":{"main":"test_main","disclaimer":"test_disclaimer"}}}"""
val expectedJson = """{"meta":{"credit_product_group":"PAYPAL_CREDIT","offer_country_code":"US","offer_type":"PAY_LATER_SHORT_TERM","message_type":"OFFER","modal_close_button":{"width":100,"height":100,"available_width":200,"available_height":200,"color":"#FFFFFF","color_type":"solid","alternative_text":"PayPal learn more modal close"},"variables":{"inline_logo_placeholder":"test_logo_placeholder"},"merchant_country_code":"US","credit_product_identifiers":["test_credit_product_identifier"],"debug_id":"test_debug_id","fdata":"test_fdata","tracking_keys":["test_tracking_key"],"originating_instance_id":"350e8400-e29b-41d4-a716-446655440000"},"content":{"default":{"main":"test_main","main_alternative":"test_alternative","disclaimer":"test_disclaimer"},"generic":{"main":"test_main","main_alternative":"test_alternative","disclaimer":"test_disclaimer"}}}"""
assertEquals(expectedJson, json)
}

Expand All @@ -80,20 +81,21 @@ class ApiMessageDataTest {
val json = gson.toJson(contentOptions)

@Suppress("ktlint:standard:max-line-length")
val expectedJson = """{"default":{"main":"test_main","disclaimer":"test_disclaimer"},"generic":{"main":"test_main","disclaimer":"test_disclaimer"}}"""
val expectedJson = """{"default":{"main":"test_main","main_alternative":"test_alternative","disclaimer":"test_disclaimer"},"generic":{"main":"test_main","main_alternative":"test_alternative","disclaimer":"test_disclaimer"}}"""
assertEquals(expectedJson, json)
}

@Test
fun testContentDetailsConstructor() {
assertEquals(main, contentDetails.main)
assertEquals(mainAlternative, contentDetails.mainAlternative)
assertEquals(disclaimer, contentDetails.disclaimer)
}

@Test
fun testContentDetailsSerialization() {
val json = gson.toJson(contentDetails)
assertEquals(json, """{"main":"test_main","disclaimer":"test_disclaimer"}""")
assertEquals(json, """{"main":"test_main","main_alternative":"test_alternative","disclaimer":"test_disclaimer"}""")
}

@Test
Expand All @@ -117,7 +119,7 @@ class ApiMessageDataTest {
val json = gson.toJson(metadata)

@Suppress("ktlint:standard:max-line-length")
val expectedJson = """{"credit_product_group":"PAYPAL_CREDIT","offer_country_code":"US","offer_type":"PAY_LATER_SHORT_TERM","message_type":"OFFER","modal_close_button":{"width":100,"height":100,"available_width":200,"available_height":200,"color":"#FFFFFF","color_type":"solid"},"variables":{"inline_logo_placeholder":"test_logo_placeholder"},"merchant_country_code":"US","credit_product_identifiers":["test_credit_product_identifier"],"debug_id":"test_debug_id","fdata":"test_fdata","tracking_keys":["test_tracking_key"],"originating_instance_id":"350e8400-e29b-41d4-a716-446655440000"}"""
val expectedJson = """{"credit_product_group":"PAYPAL_CREDIT","offer_country_code":"US","offer_type":"PAY_LATER_SHORT_TERM","message_type":"OFFER","modal_close_button":{"width":100,"height":100,"available_width":200,"available_height":200,"color":"#FFFFFF","color_type":"solid","alternative_text":"PayPal learn more modal close"},"variables":{"inline_logo_placeholder":"test_logo_placeholder"},"merchant_country_code":"US","credit_product_identifiers":["test_credit_product_identifier"],"debug_id":"test_debug_id","fdata":"test_fdata","tracking_keys":["test_tracking_key"],"originating_instance_id":"350e8400-e29b-41d4-a716-446655440000"}"""
assertEquals(expectedJson, json)
}

Expand Down

0 comments on commit b9dc3e5

Please sign in to comment.