Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinpaypal committed Jun 24, 2024
1 parent ee7813f commit d4048a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
12 changes: 6 additions & 6 deletions library/src/androidTest/java/com/paypal/messages/io/ApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ApiTest {
@Test
fun testCallMessageDataEndpointWith404() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockMessageDataResponse = MockResponse()
.setResponseCode(404)
Expand Down Expand Up @@ -156,7 +156,7 @@ class ApiTest {
@Test
fun testCallMessageDataEndpointWithBadData() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockMessageDataResponse = MockResponse()
.setResponseCode(200)
Expand Down Expand Up @@ -191,7 +191,7 @@ class ApiTest {
@Test
fun testCallMessageDataEndpointWithGoodData() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockMessageDataResponse = MockResponse()
.setResponseCode(200)
Expand Down Expand Up @@ -222,7 +222,7 @@ class ApiTest {
fun testGetMessageWithHash() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.ioDispatcher = standardTestDispatcher
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockMerchantProfileResponse = MockResponse()
.setBody(merchantProfileHashData)
Expand Down Expand Up @@ -271,7 +271,7 @@ class ApiTest {
@Test
fun testCallMessageHashEndpointWithFailure() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockHashDataResponse = MockResponse()
.setResponseCode(404)
Expand Down Expand Up @@ -306,7 +306,7 @@ class ApiTest {
@Test
fun testCallMessageHashEndpointWithSuccess() = runTest(standardTestDispatcher) {
val mockServerPort = mockWebServer.url("").port
Api.env = PayPalEnvironment.local(mockServerPort)
Api.env = PayPalEnvironment.LOCAL(mockServerPort)

val mockHashDataResponse = MockResponse()
.setResponseCode(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,27 @@ import org.junit.jupiter.api.Test
import com.paypal.messages.config.PayPalEnvironment as Env

class PayPalEnvironmentTest {
@Test
fun testLive() {
assertEquals(Env.LIVE.toString(), "LIVE")
}

@Test
fun testSandbox() {
assertEquals(Env.SANDBOX.toString(), "SANDBOX")
}

@Test
fun testStage() {
assertEquals(Env.STAGE.toString(), "STAGE")
}

@Test
fun testLocal() {
assertEquals(Env.LOCAL.toString(), "LOCAL")
}

@Test
fun testIsProduction() {
assertTrue(Env.LIVE.isProduction, "LIVE is not production")
assertTrue(Env.SANDBOX.isProduction, "SANDBOX is not production")
assertFalse(Env.STAGE.isProduction, "STAGE is production")
assertFalse(Env.LOCAL.isProduction, "LOCAL is production")
assertFalse(Env.STAGE("").isProduction, "STAGE is production")
assertFalse(Env.LOCAL().isProduction, "LOCAL is production")
}

@Test
fun testPresentmentUrls() {
assertEquals(
"http://localhost:8443/credit-presentment/native/message",
Env.local().url(Env.Endpoints.MESSAGE_DATA).toString(),
Env.LOCAL().url(Env.Endpoints.MESSAGE_DATA).toString(),
)
assertEquals(
"http://localhost:1234/credit-presentment/native/message",
Env.local(1234).url(Env.Endpoints.MESSAGE_DATA).toString(),
Env.LOCAL(1234).url(Env.Endpoints.MESSAGE_DATA).toString(),
)
assertEquals(
"https://www.stage.host/credit-presentment/lander/modal",
Env.stage("stage.host").url(Env.Endpoints.MODAL_DATA).toString(),
Env.STAGE("stage.host").url(Env.Endpoints.MODAL_DATA).toString(),
)
assertEquals(
"https://www.sandbox.paypal.com/credit-presentment/merchant-profile",
Expand All @@ -63,15 +43,15 @@ class PayPalEnvironmentTest {
fun testLoggerUrls() {
assertEquals(
"http://localhost:8443/v1/credit/upstream-messaging-events",
Env.local().url(Env.Endpoints.LOGGER).toString(),
Env.LOCAL().url(Env.Endpoints.LOGGER).toString(),
)
assertEquals(
"http://localhost:1234/v1/credit/upstream-messaging-events",
Env.local(1234).url(Env.Endpoints.LOGGER).toString(),
Env.LOCAL(1234).url(Env.Endpoints.LOGGER).toString(),
)
assertEquals(
"https://api.stage.log/v1/credit/upstream-messaging-events",
Env.stage("stage.log").url(Env.Endpoints.LOGGER).toString(),
Env.STAGE("stage.log").url(Env.Endpoints.LOGGER).toString(),
)
assertEquals(
"https://api.sandbox.paypal.com/v1/credit/upstream-messaging-events",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PayPalMessageDataTest {

@Test
fun testConstructor() {
val localEnvironment = PayPalEnvironment.LOCAL()
val data = PayPalMessageData(
clientID = initialClientID,
amount = 115.0,
Expand All @@ -20,7 +21,7 @@ class PayPalMessageDataTest {
buyerCountry = "buyer_country_test",
merchantID = "merchant_id_test",
partnerAttributionID = "partner_attribution_id_test",
environment = PayPalEnvironment.LOCAL,
environment = localEnvironment,
)

assertEquals(data.clientID, initialClientID)
Expand All @@ -30,7 +31,7 @@ class PayPalMessageDataTest {
assertEquals(data.buyerCountry, "buyer_country_test")
assertEquals(data.merchantID, "merchant_id_test")
assertEquals(data.partnerAttributionID, "partner_attribution_id_test")
assertEquals(data.environment, PayPalEnvironment.LOCAL)
assertEquals(data.environment, localEnvironment)
}

@Test
Expand All @@ -43,7 +44,7 @@ class PayPalMessageDataTest {
buyerCountry = "ES",
offerType = PayPalMessageOfferType.PAY_LATER_PAY_IN_1,
pageType = PayPalMessagePageType.CART,
environment = PayPalEnvironment.LOCAL,
environment = PayPalEnvironment.LOCAL(),
)

val data = oldData.clone()
Expand Down

0 comments on commit d4048a5

Please sign in to comment.