You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
5.6 KiB
204 lines
5.6 KiB
//
|
|
// FunctionTest.swift
|
|
// GMERemittanceTests
|
|
//
|
|
// Created by InKwon Devik Kim on 09/07/2019.
|
|
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import GME_Remit
|
|
|
|
class FunctionTest: XCTestCase {
|
|
func testExpireDate() {
|
|
guard let remindDay = Utility.calculateDDay(registDate: "7/12/2018 4:19:37 PM")
|
|
else {
|
|
XCTAssert(false)
|
|
return
|
|
}
|
|
print("remindDay: \(remindDay)")
|
|
XCTAssert(true)
|
|
}
|
|
|
|
func testDateFormat() {
|
|
let dateFormatter = DateFormatter()
|
|
|
|
dateFormatter.dateFormat = "M/d/yyyy h:mm:ss a"
|
|
dateFormatter.locale = Locale(identifier: "ko_kr")
|
|
dateFormatter.timeZone = TimeZone(abbreviation: "KST")
|
|
|
|
var dateComponent = DateComponents()
|
|
dateComponent.year = 1
|
|
|
|
let resigstDate = "7/11/2019 4:19:37 PM"
|
|
|
|
guard
|
|
let date = dateFormatter.date(from: resigstDate) else {
|
|
XCTAssert(false)
|
|
return
|
|
}
|
|
|
|
print("Date: \(date)")
|
|
}
|
|
|
|
func testIDValid() {
|
|
let extractID = "l.e ibn$iz@55_good-)(*&".extract(regex: "[A-Z0-9a-z._@-]")
|
|
print("Extract ID: \(extractID)")
|
|
|
|
XCTAssertEqual(extractID, "l.eibniz@55_good-")
|
|
}
|
|
|
|
func testASCIIAndSpace() {
|
|
let extractID = "l.e ibn$iz@55_good-)(*&".extract(regex: "[A-Z0-9a-z\\s]")
|
|
print("Extract ID: \(extractID)")
|
|
|
|
let textField = UITextField()
|
|
textField.text = "l.e ibn$iz@55_good-)(*&"
|
|
textField.filterBy(type: .alphabetNumberic, isSendAction: true)
|
|
|
|
XCTAssertEqual(extractID, "le ibniz55good")
|
|
XCTAssertEqual(textField.text ?? "", "le ibniz55good")
|
|
}
|
|
|
|
func testDynamicFieldMap() {
|
|
let models = [FieldModel]()
|
|
let textFields = [ValidationTextField]()
|
|
|
|
let dynamicField = [
|
|
"Bank Name": 0,
|
|
"Branch Name": 1,
|
|
"Account No.": 2,
|
|
|
|
"Id Type": 3,
|
|
"ID Number": 4,
|
|
|
|
"First Name": 5,
|
|
"Middle Name": 6,
|
|
"Last Name": 7,
|
|
"Full Name": 8,
|
|
|
|
"First Name in Local": 9,
|
|
"Middle Name in Local": 10,
|
|
"Last Name in Local": 11,
|
|
"Local Name": 12,
|
|
|
|
"Mobile Number": 13,
|
|
|
|
"Province": 14,
|
|
"State": 15,
|
|
"City": 16,
|
|
"Address": 17,
|
|
|
|
"Realation Group": 18,
|
|
"Transfer Reason": 19
|
|
]
|
|
|
|
models.forEach { property in
|
|
guard
|
|
let key = property.fieldName,
|
|
let tag = dynamicField[key],
|
|
let textField = textFields.filter({ $0.tag == tag }).first,
|
|
let isRequire = property.required,
|
|
let isHidden = isRequire == "H" ? true : false,
|
|
let min = property.minLength,
|
|
let max = property.maxLength,
|
|
let keyboardType = property.keyBoardType
|
|
else {return}
|
|
|
|
textField.isHidden = isHidden
|
|
textField.validCondition = { $0.count > min && $0.count < max }
|
|
|
|
switch keyboardType {
|
|
case "AN":
|
|
textField.keyboardType = .asciiCapable
|
|
textField.removeNonASCII()
|
|
case "N":
|
|
textField.keyboardType = .numberPad
|
|
case "ANS":
|
|
textField.keyboardType = .asciiCapable
|
|
|
|
default:
|
|
textField.keyboardType = .asciiCapable
|
|
textField.removeNonASCII()
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDecimalToCurrency() {
|
|
var amount = "10000"
|
|
XCTAssert(amount.decimalToCurrency() == "10,000", amount.decimalToCurrency())
|
|
|
|
amount = "10000.00"
|
|
XCTAssert(amount.decimalToCurrency() == "10,000", amount.decimalToCurrency())
|
|
|
|
amount = "11345.00"
|
|
XCTAssert(amount.decimalToCurrency() == "11,345", amount.decimalToCurrency())
|
|
|
|
amount = "11345.94"
|
|
XCTAssert(amount.decimalToCurrency() == "11,345.94", amount.decimalToCurrency())
|
|
|
|
amount = "0.11"
|
|
XCTAssert(amount.decimalToCurrency() == "0.11", amount.decimalToCurrency())
|
|
|
|
amount = "10000"
|
|
XCTAssert(
|
|
amount.decimalToCurrency(as: .krw, isFront: true) == "JPY 10,000",
|
|
amount.decimalToCurrency(as: .krw, isFront: true)
|
|
)
|
|
|
|
amount = "10000.00"
|
|
XCTAssert(
|
|
amount.decimalToCurrency(as: .krw, isFront: false) == "10,000 JPY",
|
|
amount.decimalToCurrency(as: .krw, isFront: false)
|
|
)
|
|
|
|
amount = "11345.00"
|
|
XCTAssert(
|
|
amount.decimalToCurrency(as: .usd, isFront: true) == "USD 11,345",
|
|
amount.decimalToCurrency(as: .usd, isFront: true)
|
|
)
|
|
|
|
amount = "11345.94"
|
|
XCTAssert(
|
|
amount.decimalToCurrency(as: .usd, isFront: false) == "11,345.94 USD",
|
|
amount.decimalToCurrency(as: .usd, isFront: false)
|
|
)
|
|
|
|
amount = "0.11"
|
|
XCTAssert(
|
|
amount.decimalToCurrency(as: .usd, isFront: true) == "USD 0.11",
|
|
amount.decimalToCurrency(as: .usd, isFront: true)
|
|
)
|
|
}
|
|
|
|
func testCurrencyToDecimal() {
|
|
var amount = "10,000"
|
|
XCTAssert(amount.currencyToDecimal() == "10000", amount.currencyToDecimal())
|
|
|
|
amount = "10,000.00"
|
|
XCTAssert(amount.currencyToDecimal() == "10000.00", amount.currencyToDecimal())
|
|
|
|
amount = "11,345.94"
|
|
XCTAssert(amount.currencyToDecimal() == "11345.94", amount.currencyToDecimal())
|
|
|
|
amount = "0.11"
|
|
XCTAssert(amount.currencyToDecimal() == "0.11", amount.currencyToDecimal())
|
|
|
|
amount = "JPY 10,000"
|
|
XCTAssert(amount.currencyToDecimal() == "10000", amount.currencyToDecimal())
|
|
|
|
amount = "USD 11,345"
|
|
XCTAssert(amount.currencyToDecimal() == "11345", amount.currencyToDecimal())
|
|
|
|
amount = "11,345.94 USD"
|
|
XCTAssert(amount.currencyToDecimal() == "11345.94", amount.currencyToDecimal())
|
|
|
|
amount = "USD 0.11"
|
|
XCTAssert(amount.currencyToDecimal() == "0.11", amount.currencyToDecimal())
|
|
}
|
|
|
|
func testCreditCard() {
|
|
XCTAssert(CreditCardType.validate(cardNumber: "5365100675887315") == Optional(.mastercard))
|
|
}
|
|
|
|
}
|