Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tests for android & ios #23

Merged
merged 42 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
54ea0eb
chore: initial test setup
mhochsto Aug 2, 2024
a36b677
chore: added test cases for web and Kotlin Crypto Module
mhochsto Aug 7, 2024
7cba9f1
chore: initial test setup
mhochsto Aug 2, 2024
a62e001
chore: added test cases for web and Kotlin Crypto Module
mhochsto Aug 7, 2024
8eb07d0
chore: fix linting, type errors
0x7061 Aug 8, 2024
4446c12
build: add test execution in workflows
axi92 Aug 9, 2024
1192749
chore: added crypto ios tests
mhochsto Aug 9, 2024
fa5323b
Merge branch 'feature/tests' of github.com:evva-sfw/abrevva-react-nat…
mhochsto Aug 9, 2024
0f41299
chore: added ble tests for swift
mhochsto Aug 9, 2024
26f7cf3
chore: added some testcases for android ble
mhochsto Aug 12, 2024
0ab52df
chore: update README
axi92 Aug 12, 2024
b8a5521
Update README.md
mhochsto Aug 13, 2024
b18baa4
chore: changed function names to non-backtick-names
mhochsto Aug 13, 2024
f5aa33d
Merge commit main into feature/tests
mhochsto Aug 13, 2024
e0c8495
chore: resolved issues from previous merge
mhochsto Aug 13, 2024
574d330
chore: added startNotification() testcase
mhochsto Aug 14, 2024
b050077
chore: README.md from main
mhochsto Aug 14, 2024
9848ff5
chore: merged latest changes from main
mhochsto Aug 14, 2024
abafe8c
Merge branch 'main' into feature/tests
axi92 Aug 19, 2024
45145b1
chore: update AbrevvaSDK version; add Makefile for ios test-command
0x7061 Aug 22, 2024
062d56c
chore: merge main into feature/test
0x7061 Aug 22, 2024
f116d43
ci: add ios test workflow
0x7061 Aug 22, 2024
a6a0934
ci: add quiet flag for ios test command
0x7061 Aug 22, 2024
22c8adb
ci: add ruby version & cache; add swift version & cache
0x7061 Aug 22, 2024
0e0910d
chore: bump deps
0x7061 Aug 22, 2024
cb2ff07
Merge branch 'main' into feature/tests
0x7061 Aug 22, 2024
ee6126f
chore: disable unsupported devices; remove xcode github workflow step
0x7061 Aug 22, 2024
bebc7d0
chore: adapt makefile and github ios workflow
0x7061 Aug 22, 2024
ec93e42
ci: display xcodebuild version
0x7061 Aug 23, 2024
7d713ff
ci: list xcode versions
0x7061 Aug 23, 2024
a667454
ci: set xcode version
0x7061 Aug 23, 2024
bf9cbe0
ci: use sudo due to xcode-select error
0x7061 Aug 23, 2024
af01f04
ci: show available software
0x7061 Aug 23, 2024
bfb769c
ci: print env.toolchains
0x7061 Aug 23, 2024
3141efd
ci: try developer_dir env var
0x7061 Aug 23, 2024
ae7d9ab
ci: set proper xcode version for test command
0x7061 Aug 23, 2024
014c9e6
chore: bump readme
0x7061 Aug 23, 2024
5a2b7bc
ci: add android test step
0x7061 Aug 23, 2024
c9f406d
ci: add exit 1 for all other exit types on android
0x7061 Aug 23, 2024
4385799
ci: add npm cache
0x7061 Aug 23, 2024
6006289
ci: streamline node_modules cache; add derived-data cache
0x7061 Aug 23, 2024
d0ac466
ci: add cache for pods
0x7061 Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
branches: [ "main" ]
jobs:
test:
test-web:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -22,3 +22,36 @@ jobs:
cache: 'yarn'
- run: yarn
- run: yarn test

test-ios:
runs-on: macos-latest
strategy:
matrix:
node-version: [lts/*]
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: "Get Ruby Version"
run: ruby --version
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: "5.10.0"
- name: Get Swift Version
run: swift --version
- name: Set Swift Version
if: runner.os == 'macOS'
run: xcrun --toolchain ${{ env.TOOLCHAINS }} swift --version
- run: corepack enable
- run: yarn
- run: cd example; bundle; cd -
- run: cd example/ios; bundle exec pod install; cd -
- run: make test
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test:
$(MAKE) test-ios

test-ios:
xcodebuild -quiet \
-workspace example/ios/ExampleAppExample.xcworkspace \
-scheme ExampleAppExample \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15,OS=17.4' \
test || exit 1
2 changes: 1 addition & 1 deletion abrevva-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pod::Spec.new do |s|

s.dependency "CocoaMQTT"
s.dependency "CryptoSwift"
s.dependency "AbrevvaSDK", '~> 1.0.20'
s.dependency "AbrevvaSDK", '~> 1.0.23'

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand Down
7 changes: 6 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}

repositories {
Expand Down Expand Up @@ -102,4 +107,4 @@ dependencies {

androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :

private fun runInitialization(options: ReadableMap, promise: Promise) {
if (!currentActivity!!.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
return promise.reject("runInitialization(): BLE is not supported")
return promise.reject(Exception("runInitialization(): BLE is not supported"))
}

if (!manager.isBleEnabled()) {
return promise.reject("runInitialization(): BLE is not available")
return promise.reject(Exception("runInitialization(): BLE is not available"))
}
promise.resolve("success")
}
Expand Down Expand Up @@ -114,8 +114,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
}

if (!success) {
promise.reject("startEnabledNotifications(): Failed to set handler")
return
return promise.reject(Exception("startEnabledNotifications(): Failed to set handler"))
}
promise.resolve("success")
}
Expand Down Expand Up @@ -165,7 +164,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("requestLEScan(): failed to start")
promise.reject(Exception("requestLEScan(): failed to start"))
}
}, { result: BleScanResult ->
val scanResult = getScanResultFromNordic(result)
Expand Down Expand Up @@ -199,7 +198,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("connect(): failed to connect")
promise.reject(Exception("connect(): failed to connect"))
}
}, timeout)
}
Expand All @@ -213,7 +212,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("disconnect(): failed to disconnect")
promise.reject(Exception("disconnect(): failed to disconnect"))
}
}
}
Expand All @@ -229,7 +228,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
}

val characteristic = getCharacteristic(options, promise)
?: return promise.reject("read(): bad characteristic")
?: return promise.reject(Exception("read(): bad characteristic"))

manager.read(
deviceId,
Expand Down Expand Up @@ -262,7 +261,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
getCharacteristic(options, promise)
?: return promise.reject("read(): bad characteristic")
val value =
options.getString("value") ?: return promise.reject("write(): missing value for write")
options.getString("value") ?: return promise.reject(Exception("write(): missing value for write"))

manager.write(
deviceId,
Expand All @@ -273,7 +272,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("write(): failed to write to device")
promise.reject(Exception("write(): failed to write to device"))
}
},
timeout
Expand Down Expand Up @@ -315,7 +314,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
val deviceId = options.getString("deviceId") ?: ""
val characteristic =
getCharacteristic(options, promise)
?: return promise.reject("startNotifications(): bad characteristic")
?: return promise.reject(Exception("startNotifications(): bad characteristic"))

manager.startNotifications(
deviceId,
Expand All @@ -325,7 +324,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("startNotifications(): failed to set notifications")
promise.reject(Exception("startNotifications(): failed to set notifications"))
}
}, { data: ByteArray ->
val key =
Expand All @@ -343,7 +342,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
val deviceId = options.getString("deviceId") ?: ""
val characteristic =
getCharacteristic(options, promise)
?: return promise.reject("stopNotifications(): bad characteristic")
?: return promise.reject(Exception("stopNotifications(): bad characteristic"))

manager.stopNotifications(
deviceId,
Expand All @@ -353,7 +352,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
if (success) {
promise.resolve("success")
} else {
promise.reject("stopNotifications(): failed to unset notifications")
promise.reject(Exception("stopNotifications(): failed to unset notifications"))
}
}
}
Expand All @@ -365,12 +364,12 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
try {
serviceUUID = UUID.fromString(serviceString)
} catch (e: IllegalArgumentException) {
promise.reject("getCharacteristic(): invalid service uuid")
promise.reject(Exception("getCharacteristic(): invalid service uuid"))
return null
}

if (serviceUUID == null) {
promise.reject("getCharacteristic(): service uuid required")
promise.reject(Exception("getCharacteristic(): service uuid required"))
return null
}

Expand All @@ -380,19 +379,19 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
try {
characteristicUUID = UUID.fromString(characteristicString)
} catch (e: IllegalArgumentException) {
promise.reject("getCharacteristic(): invalid characteristic uuid")
promise.reject(Exception("getCharacteristic(): invalid characteristic uuid"))
return null
}

if (characteristicUUID == null) {
promise.reject("getCharacteristic(): characteristic uuid required")
promise.reject(Exception("getCharacteristic(): characteristic uuid required"))
return null
}

return Pair(serviceUUID, characteristicUUID)
}

private fun getBleDeviceFromNordic(result: BleScanResult): ReadableMap {
fun getBleDeviceFromNordic(result: BleScanResult): ReadableMap {
val bleDevice = Arguments.createMap()

bleDevice.putString("deviceId", result.device.address)
Expand All @@ -410,7 +409,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
return bleDevice
}

private fun getScanResultFromNordic(result: BleScanResult): ReadableMap {
fun getScanResultFromNordic(result: BleScanResult): ReadableMap {
val scanResult = Arguments.createMap()
val bleDevice = getBleDeviceFromNordic(result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient.Mqtt3SubscribeAndCallbackBuilder.Call.Ex
import org.bouncycastle.util.encoders.Base64
import org.bouncycastle.util.encoders.Hex
import java.io.BufferedInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.net.URL
import java.nio.file.Paths

Expand Down Expand Up @@ -72,8 +75,8 @@ class AbrevvaCryptoModule(reactContext: ReactApplicationContext) :
val keyPair: X25519Wrapper.KeyPair = X25519Wrapper.generateKeyPair()

val ret = Arguments.createMap()
ret.putString("privateKey", Base64.toBase64String(keyPair.privateKey))
ret.putString("publicKey", Base64.toBase64String(keyPair.publicKey))
ret.putString("privateKey", Hex.toHexString(keyPair.privateKey))
ret.putString("publicKey", Hex.toHexString(keyPair.publicKey))
promise.resolve(ret)
} catch (e: Exception) {
promise.reject(Exception("generateKeyPair(): private key creation failed"))
Expand All @@ -94,8 +97,8 @@ class AbrevvaCryptoModule(reactContext: ReactApplicationContext) :
return
}
val sharedSecret: ByteArray = X25519Wrapper.computeSharedSecret(
Base64.decode(privateKey),
Base64.decode(peerPublicKey)
Hex.decode(privateKey),
Hex.decode(peerPublicKey)
)

val ret = Arguments.createMap()
Expand Down Expand Up @@ -165,7 +168,6 @@ class AbrevvaCryptoModule(reactContext: ReactApplicationContext) :
promise.reject(e)
}
}

fun writeToFile(ctPath: String, url: String) {

BufferedInputStream(URL(url).openStream()).use { `in` ->
Expand Down
Loading
Loading