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

Add Integration Test #94

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 71 additions & 0 deletions .github/workflows/ios-test-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: iOS Tests

on:
pull_request:

jobs:
test:
name: Run Xcode Tests
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode.app

- name: Get Available Destination
id: get-destination
run: |
# Get all available destinations and save to a file
xcodebuild -scheme "Xendit-Package" -showdestinations | tee destinations.txt

# Print all destinations for debugging
echo "Available destinations:"
cat destinations.txt

# Extract simulator with latest OS (works for both iPhone and iPhone SE)
DESTINATION=$(grep -E "platform:iOS Simulator.*name:iPhone" destinations.txt | \
sort -t':' -k4,4V | \
tail -n1 | \
sed -e 's/^[[:space:]]*//' | \
sed -e 's/[[:space:]]*$//' | \
sed -e 's/[{}]//g' | \
sed -e 's/platform:/platform=/g' | \
sed -e 's/id:/id=/g' | \
sed -e 's/, /,/g' | \
sed -e 's/,OS.*//g' | \
xargs)

if [ -z "$DESTINATION" ]; then
echo "Error: No iPhone simulator destination found!"
echo "Available destinations were:"
cat destinations.txt
exit 1
fi

# Set the destination as an output
echo "DESTINATION=$DESTINATION" >> "$GITHUB_OUTPUT"

# Print the selected destination for logging
echo "Selected destination: $DESTINATION"

- name: Build and Test
run: |
DESTINATION="${{ steps.get-destination.outputs.DESTINATION }}"
echo "Using destination: $DESTINATION"

xcodebuild test \
-scheme "Xendit-Package" \
-configuration Debug \
-destination "$DESTINATION" \
-enableCodeCoverage YES \
-resultBundlePath TestResults.xcresult \
clean test | xcpretty

- name: Generate Test Report
uses: kishikawakatsumi/xcresulttool@v1
with:
path: TestResults.xcresult
if: success() || failure()
228 changes: 143 additions & 85 deletions Sources/Xendit/XDTCards.swift

Large diffs are not rendered by default.

156 changes: 136 additions & 20 deletions Sources/Xendit/Xendit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,85 +21,201 @@ import XenditObjC
public static var publishableKey: String?

// Create token method with billing details and customer object
public static func createToken(fromViewController: UIViewController, tokenizationRequest: XenditTokenizationRequest, onBehalfOf: String?, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
public static func createToken(
fromViewController: UIViewController,
tokenizationRequest: XenditTokenizationRequest,
onBehalfOf: String?,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.createToken(fromViewController: fromViewController, tokenizationRequest: tokenizationRequest, onBehalfOf: onBehalfOf, completion: completion)
XDTCards.createToken(
fromViewController: fromViewController,
tokenizationRequest: tokenizationRequest,
onBehalfOf: onBehalfOf,
completion: completion
)
}

// Retokenize method with billing details and customer object
@available(*, deprecated, message: "Use storeCVN(UIViewController, XenditStoreCVNRequest, String, Callback) instead")
public static func createToken(fromViewController: UIViewController, retokenizationRequest: XenditRetokenizationRequest, onBehalfOf: String?, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
public static func createToken(
fromViewController: UIViewController,
retokenizationRequest: XenditRetokenizationRequest,
onBehalfOf: String?,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.createToken(fromViewController: fromViewController, retokenizationRequest: retokenizationRequest, onBehalfOf: onBehalfOf, completion: completion)
XDTCards.createToken(
fromViewController: fromViewController,
retokenizationRequest: retokenizationRequest,
onBehalfOf: onBehalfOf,
completion: completion
)
}

// Store CVN with existing token method with billing details and customer object
public static func storeCVN(
fromViewController: UIViewController,
storeCVNRequest: XenditStoreCVNRequest,
onBehalfOf: String?,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.storeCVN(fromViewController: fromViewController, storeCVNRequest: storeCVNRequest, onBehalfOf: onBehalfOf, completion: completion)
XDTCards.storeCVN(
fromViewController: fromViewController,
storeCVNRequest: storeCVNRequest,
onBehalfOf: onBehalfOf,
completion: completion
)
}

public static func createAuthentication(fromViewController: UIViewController, authenticationRequest: XenditAuthenticationRequest, onBehalfOf: String?, completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void) {
public static func createAuthentication(
fromViewController: UIViewController,
authenticationRequest: XenditAuthenticationRequest,
onBehalfOf: String?,
completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
let tokenId = authenticationRequest.tokenId
let amount = authenticationRequest.amount
let customer = authenticationRequest.customer
let currency = authenticationRequest.currency
let cardData = authenticationRequest.cardData
XDTCards.createAuthentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: currency, onBehalfOf: onBehalfOf, customer: customer, cardCvn: authenticationRequest.cardCvn, cardData: cardData, completion: completion)
XDTCards.createAuthentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: currency,
onBehalfOf: onBehalfOf,
customer: customer,
cardCvn: authenticationRequest.cardCvn,
cardData: cardData,
completion: completion
)
}

@available(*, deprecated, message: "Use createToken(UIViewController, XenditTokenizationRequest, String, Callback) instead")
public static func createToken(fromViewController: UIViewController, cardData: CardData!, shouldAuthenticate: Bool, onBehalfOf: String, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
public static func createToken(
fromViewController: UIViewController,
cardData: CardData!,
shouldAuthenticate: Bool,
onBehalfOf: String,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
let tokenizationRequest = XenditTokenizationRequest(cardData: cardData, shouldAuthenticate: shouldAuthenticate)
XDTCards.createToken(fromViewController: fromViewController, tokenizationRequest: tokenizationRequest, onBehalfOf: onBehalfOf, completion: completion)
XDTCards.createToken(
fromViewController: fromViewController,
tokenizationRequest: tokenizationRequest,
onBehalfOf: onBehalfOf,
completion: completion
)
}

@available(*, deprecated, message: "Use createToken(UIViewController, XenditTokenizationRequest, String, Callback) instead")
public static func createToken(fromViewController: UIViewController, cardData: CardData!, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
public static func createToken(
fromViewController: UIViewController,
cardData: CardData!,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
let tokenizationRequest = XenditTokenizationRequest(cardData: cardData, shouldAuthenticate: true)
XDTCards.createToken(fromViewController: fromViewController, tokenizationRequest: tokenizationRequest, onBehalfOf: nil, completion: completion)
XDTCards.createToken(
fromViewController: fromViewController,
tokenizationRequest: tokenizationRequest,
onBehalfOf: nil,
completion: completion
)
}

@available(*, deprecated, message: "Use createToken(UIViewController, XenditTokenizationRequest, String, Callback) instead")
public static func createToken(fromViewController: UIViewController, cardData: CardData!, shouldAuthenticate: Bool!, completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void) {
public static func createToken(
fromViewController: UIViewController,
cardData: CardData!,
shouldAuthenticate: Bool!,
completion:@escaping (_ : XenditCCToken?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
let tokenizationRequest = XenditTokenizationRequest(cardData: cardData, shouldAuthenticate: shouldAuthenticate)
XDTCards.createToken(fromViewController: fromViewController, tokenizationRequest: tokenizationRequest, onBehalfOf: nil, completion: completion)
XDTCards.createToken(
fromViewController: fromViewController,
tokenizationRequest: tokenizationRequest,
onBehalfOf: nil,
completion: completion
)
}

@available(*, deprecated, message: "Use createAuthentication(UIViewController, XenditAuthenticationRequest, Callback) instead")
public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, onBehalfOf: String, completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void) {
public static func createAuthentication(
fromViewController: UIViewController,
tokenId: String,
amount: NSNumber,
onBehalfOf: String,
completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.createAuthentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: nil, onBehalfOf: onBehalfOf, customer: nil, cardCvn: nil, completion: completion)
XDTCards.createAuthentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: nil,
onBehalfOf: onBehalfOf,
customer: nil,
cardCvn: nil,
completion: completion
)
}

@available(*, deprecated, message: "Use createAuthentication(UIViewController, XenditAuthenticationRequest, Callback) instead")
public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void) {
public static func createAuthentication(
fromViewController: UIViewController,
tokenId: String,
amount: NSNumber,
completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.createAuthentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: nil, onBehalfOf: nil, customer: nil, cardCvn: nil, completion: completion)
XDTCards.createAuthentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: nil,
onBehalfOf: nil,
customer: nil,
cardCvn: nil,
completion: completion
)
}

@available(*, deprecated, message: "Use createAuthentication(UIViewController, XenditAuthenticationRequest, Callback) instead")
public static func createAuthentication(fromViewController: UIViewController, tokenId: String, amount: NSNumber, cardCVN: String, completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void) {
public static func createAuthentication(
fromViewController: UIViewController,
tokenId: String,
amount: NSNumber,
cardCVN: String,
completion:@escaping (_ : XenditAuthentication?, _ : XenditError?) -> Void
) {
XDTSentry.shared.configure()
XDTCards.setup(publishableKey: publishableKey!)
XDTCards.createAuthentication(fromViewController: fromViewController, tokenId: tokenId, amount: amount, currency: nil, onBehalfOf: nil, customer: nil, cardCvn: cardCVN, completion: completion) }
XDTCards.createAuthentication(
fromViewController: fromViewController,
tokenId: tokenId,
amount: amount,
currency: nil,
onBehalfOf: nil,
customer: nil,
cardCvn: cardCVN,
completion: completion
)
}

// Card data validation method
public static func isCardNumberValid(cardNumber: String) -> Bool {
Expand Down
64 changes: 64 additions & 0 deletions Tests/XenditTests.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"configurations" : [
{
"id" : "DEF526EB-CC7C-4E75-A22F-D0C92A9BA319",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {

},
"testTargets" : [
{
"skippedTests" : [
"CardDataTest",
"CardDataTest\/testCardCVNInvalid()",
"CardDataTest\/testCardCVNValid()",
"CardDataTest\/testCardExpirationInvalid()",
"CardDataTest\/testCardExpirationValid()",
"CardDataTest\/testCardNumberForInvalidAmex()",
"CardDataTest\/testCardNumberForValidAmex()",
"CardDataTest\/testCardNumberValidationForInvalidDankortCard()",
"CardDataTest\/testCardNumberValidationForInvalidDiscoverCard()",
"CardDataTest\/testCardNumberValidationForInvalidJBCCard()",
"CardDataTest\/testCardNumberValidationForInvalidMaestro()",
"CardDataTest\/testCardNumberValidationForInvalidMasterCard()",
"CardDataTest\/testCardNumberValidationForInvalidVisaCard()",
"CardDataTest\/testCardNumberValidationForValidDankortCard()",
"CardDataTest\/testCardNumberValidationForValidDiscoverCard()",
"CardDataTest\/testCardNumberValidationForValidJBCCard()",
"CardDataTest\/testCardNumberValidationForValidMaestro()",
"CardDataTest\/testCardNumberValidationForValidMasterCard()",
"CardDataTest\/testCardNumberValidationForValidVisaCard()",
"CardDataTest\/testCardNumberValidationForValidVisaElectronCard()",
"CardDataTest\/testCreateCardDataModel()",
"CardDataTest\/testPerformanceExample()",
"CreditCardTests",
"CreditCardTests\/testIsValidCardNumber()",
"FingerprintTests",
"FingerprintTests\/testReturnsPayload()",
"JsonEncodeTests",
"JsonEncodeTests\/testEncodeXenditCCToken()",
"LogSanitizerTest",
"LogSanitizerTest\/testArray()",
"LogSanitizerTest\/testDictionary()",
"LogSanitizerTest\/testNestedDictionary()",
"LogSanitizerTest\/testNonJsonBody()",
"XenditIntegrationTests",
"XenditIntegrationTests\/testCreateAuthentication()",
"XenditIntegrationTests\/testCreateToken()",
"XenditIntegrationTests\/testCreateTokenInvalid()",
"XenditIntegrationTestsV3\/testAuthenticationWithSingleUseToken()"
],
"target" : {
"containerPath" : "container:",
"identifier" : "XenditTests",
"name" : "XenditTests"
}
}
],
"version" : 1
}
2 changes: 2 additions & 0 deletions Tests/XenditTests/Helpers/TestCards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ import Foundation
enum TestCard {
static let validCardNo3ds = "5200000000000056"
static let validCardWith3ds = "4000000000000002"
static let validCard = "4000000000001091"
static let invalidCard = "4000000000001099"
}
Loading
Loading