Skip to content

Commit

Permalink
ci: lint and test (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinpaypal committed Oct 24, 2023
1 parent 84316bb commit 8a22f0b
Show file tree
Hide file tree
Showing 81 changed files with 2,162 additions and 604 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
codebase: [library, demo]

steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -20,3 +24,9 @@ jobs:
java-version: '17'
distribution: 'temurin'
cache: gradle

# Only library assets are needed for the build step
- name: Build with Gradle
run: ./gradlew :${{ matrix.codebase }}:assemble

- run: echo "Build status report=${{ job.status }}."
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ jobs:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Run Lint
run: ./gradlew ktLint
continue-on-error: true

- name: Get Lint Reports
uses: yutailang0119/action-ktlint@v3
with:
report-path: build/reports/ktlint/*.xml
continue-on-error: false
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
distribution: 'temurin'
cache: gradle

- name: Install Dependencies
run: echo "Install Dependencies"

- name: Run Tests
run: echo "Run Tests"
run: ./gradlew testReleaseUnitTest
continue-on-error: false
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.jmailen.gradle.kotlinter.tasks.LintTask
import org.jmailen.gradle.kotlinter.tasks.FormatTask

plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.22' apply false
id 'org.jmailen.kotlinter' version '3.16.0'
}

tasks.register('ktLint', LintTask) {
group 'formatting'
source files('demo/src', 'library/src')
reports = [
'checkstyle': file('build/reports/ktlint/main-lint.xml')
]
}

tasks.register('ktFormat', FormatTask) {
group 'formatting'
source files('demo/src', 'library/src')
report = file('build/reports/ktlint/format-report.txt')
}
73 changes: 35 additions & 38 deletions demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.graphics.Color
import com.google.android.material.switchmaterial.SwitchMaterial
import com.paypal.messages.config.PayPalMessageOfferType
import com.paypal.messages.config.message.PayPalMessageConfig
import com.paypal.messages.config.message.PayPalMessageData
import com.paypal.messages.config.message.PayPalMessageEventsCallbacks
import com.paypal.messages.config.message.PayPalMessageStyle
import com.paypal.messages.config.message.PayPalMessageViewStateCallbacks
Expand All @@ -38,7 +39,7 @@ class XmlActivity : AppCompatActivity() {
val payPalMessage = binding.payPalMessage
val progressBar = binding.progressBar

val editedClientId: EditText? = findViewById(R.id.clientId)
val clientIdEdit: EditText? = findViewById(R.id.clientId)

val logoTypeRadioGroup = findViewById<RadioGroup>(R.id.logoTypeRadioGroup)
logoTypeRadioGroup.setOnCheckedChangeListener { _, checkedId ->
Expand Down Expand Up @@ -77,23 +78,26 @@ class XmlActivity : AppCompatActivity() {
val payIn1 = findViewById<ToggleButton>(R.id.payIn1)
val credit = findViewById<ToggleButton>(R.id.credit)

fun updateOfferUi (offerName: PayPalMessageOfferType?, isChecked: Boolean) {
fun updateOfferUi(offerName: PayPalMessageOfferType?, isChecked: Boolean) {
shortTerm.isChecked = false
longTerm.isChecked = false
payIn1.isChecked = false
credit.isChecked = false
offerType = null

if ( offerName == PayPalMessageOfferType.PAY_LATER_SHORT_TERM && isChecked) {
if (offerName == PayPalMessageOfferType.PAY_LATER_SHORT_TERM && isChecked) {
shortTerm.isChecked = true
offerType = PayPalMessageOfferType.PAY_LATER_SHORT_TERM
} else if ( offerName == PayPalMessageOfferType.PAY_LATER_LONG_TERM && isChecked) {
}
else if (offerName == PayPalMessageOfferType.PAY_LATER_LONG_TERM && isChecked) {
longTerm.isChecked = true
offerType = PayPalMessageOfferType.PAY_LATER_LONG_TERM
} else if ( offerName == PayPalMessageOfferType.PAY_LATER_PAY_IN_1 && isChecked) {
}
else if (offerName == PayPalMessageOfferType.PAY_LATER_PAY_IN_1 && isChecked) {
payIn1.isChecked = true
offerType = PayPalMessageOfferType.PAY_LATER_PAY_IN_1
} else if ( offerName == PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST && isChecked) {
}
else if (offerName == PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST && isChecked) {
credit.isChecked = true
offerType = PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST
}
Expand All @@ -114,9 +118,9 @@ class XmlActivity : AppCompatActivity() {
updateOfferUi(PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST, isChecked)
}

val amount = findViewById<EditText>(R.id.amount)
val buyerCountry = findViewById<EditText>(R.id.buyerCountry)
val stageTag = findViewById<EditText>(R.id.stageTag)
val amountEdit = findViewById<EditText>(R.id.amount)
val buyerCountryEdit = findViewById<EditText>(R.id.buyerCountry)
val stageTagEdit = findViewById<EditText>(R.id.stageTag)
val ignoreCache = findViewById<SwitchMaterial>(R.id.ignoreCache)
val devTouchpoint = findViewById<SwitchMaterial>(R.id.devTouchpoint)

Expand All @@ -125,37 +129,29 @@ class XmlActivity : AppCompatActivity() {
Api.devTouchpoint = devTouchpoint.isChecked
Api.ignoreCache = ignoreCache.isChecked

if ( editedClientId?.text.toString().isNotBlank() ) {
payPalMessage.clientId = editedClientId?.text.toString()
} else {
val clientId = clientIdEdit?.text.toString()
payPalMessage.clientId = clientId.ifBlank { "" }
if (clientIdEdit?.text.toString().isNotBlank()) {
payPalMessage.clientId = clientIdEdit?.text.toString()
}
else {
payPalMessage.clientId = ""
}

if ( amount?.text.toString().isNotBlank() ) {
payPalMessage.amount = amount?.text.toString().toDouble()
} else {
payPalMessage.amount = null
}
val amount = amountEdit?.text.toString()
payPalMessage.amount = if (amount.isNotBlank()) amount.toDouble() else null

if ( buyerCountry?.text.toString().isNotBlank() ) {
payPalMessage.buyerCountry = buyerCountry?.text.toString()
} else {
payPalMessage.buyerCountry = "US"
}
val buyerCountry = buyerCountryEdit?.text.toString()
payPalMessage.buyerCountry = buyerCountry.ifBlank { "US" }

if ( color === PayPalMessageColor.WHITE ) {
payPalMessage.setBackgroundColor(Color.Black.hashCode())
} else {
payPalMessage.setBackgroundColor(Color.White.hashCode())
}
val backgroundColor = if (color === PayPalMessageColor.WHITE) Color.Black else Color.White
payPalMessage.setBackgroundColor(backgroundColor.hashCode())

if ( stageTag?.text.toString().isNotBlank() ) {
Api.stageTag = stageTag?.text.toString()
} else {
Api.stageTag = null
}
val stageTag = stageTagEdit?.text.toString()
Api.stageTag = stageTag.ifBlank { null }

payPalMessage.style = PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType)
payPalMessage.style =
PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType)
payPalMessage.refresh()
}

Expand All @@ -169,8 +165,8 @@ class XmlActivity : AppCompatActivity() {
updateOfferUi(null, false)
ignoreCache.isChecked = false
devTouchpoint.isChecked = false
amount.setText("")
buyerCountry.setText("")
amountEdit.setText("")
buyerCountryEdit.setText("")

updateMessageData()
}
Expand All @@ -193,10 +189,11 @@ class XmlActivity : AppCompatActivity() {
runOnUiThread {
resetButton.isEnabled = true
submitButton.isEnabled = true
Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.paypalDebugId, Toast.LENGTH_LONG).show()
Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.debugId, Toast.LENGTH_LONG)
.show()
}
it.message?.let { it1 -> Log.d("XmlActivity Error", it1) }
it.paypalDebugId?.let { it1 -> Log.d("XmlActivity Error", it1) }
it.debugId?.let { it1 -> Log.d("XmlActivity Error", it1) }
},
onSuccess = {
Log.d(TAG, "onSuccess")
Expand All @@ -219,7 +216,7 @@ class XmlActivity : AppCompatActivity() {
setContentView(binding.root)

val message = binding.payPalMessage
val config = PayPalMessageConfig()
val config = PayPalMessageConfig(data = PayPalMessageData())
config.setGlobalAnalytics("", "")
message.config = config

Expand Down
88 changes: 74 additions & 14 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'de.mannodermaus.android-junit5' version "1.9.3.0"
id 'org.jetbrains.kotlinx.kover' version '0.7.4'
}

android {
Expand All @@ -12,15 +14,15 @@ android {
targetSdk 34

versionCode 10000
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

buildConfigField("String", "INTEGRATION_TYPE", "\"NATIVE_ANDROID\"")
buildConfigField("String", "LIBRARY_VERSION", "\"${versionName}\"")
buildConfigField("String", "STAGE_URL", "\"${System.env.UPSTREAM_ANDROID_STAGE_URL}\"")
buildConfigField("String", "STAGE_VPN_URL", "\"${System.env.UPSTREAM_ANDROID_STAGE_VPN_URL}\"")
buildConfigField("String", "LOCAL_URL", "\"${System.env.UPSTREAM_ANDROID_LOCAL_URL}\"")
versionName '1.0.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles 'consumer-rules.pro'

buildConfigField('String', 'INTEGRATION_TYPE', "\"NATIVE_ANDROID\"")
buildConfigField('String', 'LIBRARY_VERSION', "\"${versionName}\"")
buildConfigField('String', 'STAGE_URL', "\"${System.env.UPSTREAM_ANDROID_STAGE_URL}\"")
buildConfigField('String', 'STAGE_VPN_URL', "\"${System.env.UPSTREAM_ANDROID_STAGE_VPN_URL}\"")
buildConfigField('String', 'LOCAL_URL', "\"${System.env.UPSTREAM_ANDROID_LOCAL_URL}\"")
}

buildFeatures {
Expand All @@ -39,18 +41,76 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

testOptions {
unitTests.all {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
}
}
}
}

tasks.withType(Test) {
useJUnitPlatform()
}

koverReport {
androidReports('debug') {
filters {
// includes {
// classes(
// 'PayPalErrors\$*'
// )
// }
excludes {
classes(
// config
'com.paypal.messages.config.message.PayPalMessageEventsCallbacks\$*',
'com.paypal.messages.config.message.PayPalMessageViewStateCallbacks\$*',
'com.paypal.messages.config.modal.ModalEvents\$*',
// extensions,
'com.paypal.messages.extensions.*',
// io
'com.paypal.messages.io.Api\$Endpoints',
'com.paypal.messages.io.ApiMessageData',
'com.paypal.messages.io.ApiHashData',
'com.paypal.messages.io.LocalStorage*',
// logger,
'com.paypal.messages.logger.Logger*',
// utils
'com.paypal.messages.utils.LogCat*',
'com.paypal.messages.utils.PayPalErrors',
// UI Stuff
'*Fragment',
'*Fragment\$*',
'*Activity',
'*Activity\$*',
'com.paypal.messages.PayPalMessageView*',
'com.paypal.messages.RoundedWebView',
'*.databinding.*',
'*.BuildConfig'
)
}
}
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'

testImplementation 'junit:junit:4.13.2'
testImplementation "com.squareup.okhttp3:mockwebserver:4.8.0"
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'
testImplementation 'org.mockito:mockito-core:5.5.0'
testImplementation 'org.mockito.kotlin:mockito-kotlin:5.1.0'
testImplementation 'io.mockk:mockk:1.13.7'

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "com.squareup.okhttp3:mockwebserver:4.8.0"
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.paypal.messages.extensions

import android.content.res.Resources
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.math.roundToInt

@RunWith(AndroidJUnit4::class)
class IntTest {
@Test
fun testDpExtension() {
val basicInteger = 10
val expectedDp = (basicInteger * Resources.getSystem().displayMetrics.density).roundToInt()
val actualDp = basicInteger.dp
assertEquals(expectedDp, actualDp)
}
}
Loading

0 comments on commit 8a22f0b

Please sign in to comment.