Skip to content

Commit

Permalink
Refactor OmiseError for SonarCloud warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Solovev committed Jun 17, 2024
1 parent a16e398 commit d34c238
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions OmiseSDKTests/OmiseErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,54 @@ class OmiseErrorTests: XCTestCase {
}
}
}

typealias BadRequestReason = OmiseError.APIErrorCode.BadRequestReason
func testParseBadRequestReasonsFromMessage() {
// Array of tuples for test cases
let currency: Currency = .thb
let testCases: [(message: String, expected: Set<BadRequestReason>)] = [
(
"amount must be at least 100 THB",
[.amountIsLessThanValidAmount(validAmount: 100, currency: currency)]
),
(
"amount must be less than 5000 USD",
[.amountIsGreaterThanValidAmount(validAmount: 5000, currency: currency)]
),
(
"currency must be.., empty name",
[.invalidCurrency, .nameIsTooLong(maximum: nil)]
),
(
"other currency error, empty name",
[.currencyNotSupported, .nameIsTooLong(maximum: nil)]
),
(
"name is too long (maximum is 25 characters), invalid email",
[.nameIsTooLong(maximum: 25), .invalidEmail]
),
(
"invalid phone number",
[.invalidPhoneNumber]
),
(
"type not supported, currency not supported",
[.typeNotSupported, .currencyNotSupported]
),
(
"unknown issue",
[.other("unknown issue")]
)
]

for (message, expected) in testCases {
do {
let results = try BadRequestReason.parseBadRequestReasonsFromMessage(message, currency: currency)
XCTAssertEqual(Set(results), expected, "Failed to parse or incorrect order for message: \(message)")
} catch {
XCTFail("Unexpected error for message: \(message): \(error)")
}
}
}

}

0 comments on commit d34c238

Please sign in to comment.