TF-2871 Fix validate expire time in swift code

This commit is contained in:
dab246
2024-06-04 16:57:05 +07:00
committed by Dat H. Pham
parent ef159c78c5
commit d2ee12c2ae
9 changed files with 142 additions and 16 deletions
@@ -0,0 +1,47 @@
import XCTest
@testable import Runner
final class AuthenticationSSOTests: XCTestCase {
func testIsExpiredTimeMethodWithValidExpireTime() {
let currentDate = CoreUtils.shared.getCurrentDate()
let expireDate = currentDate.addingTimeInterval(3600)
let authenticationSSO = AuthenticationSSO(
type: AuthenticationType.oidc,
accessToken: "abcxyz",
refreshToken: "abcxyz",
expireTime: expireDate.convertDateToISO8601String()
)
XCTAssertFalse(authenticationSSO.isExpiredTime(currentDate: currentDate))
}
func testIsExpiredTimeMethodWithExpireTime() {
let currentDate = CoreUtils.shared.getCurrentDate()
let expireDate = currentDate.addingTimeInterval(-3600)
let authenticationSSO = AuthenticationSSO(
type: AuthenticationType.oidc,
accessToken: "abcxyz",
refreshToken: "abcxyz",
expireTime: expireDate.convertDateToISO8601String()
)
XCTAssertTrue(authenticationSSO.isExpiredTime(currentDate: currentDate))
}
func testIsExpiredTimeMethodNilExpireTime() {
let currentDate = CoreUtils.shared.getCurrentDate()
let authenticationSSO = AuthenticationSSO(
type: AuthenticationType.oidc,
accessToken: "abcxyz",
refreshToken: "abcxyz",
expireTime: nil
)
XCTAssertFalse(authenticationSSO.isExpiredTime(currentDate: currentDate))
}
}
@@ -22,4 +22,24 @@ class DateConversionTests: XCTestCase {
let date = invalidDateString.convertISO8601StringToDate()
XCTAssertNil(date, "The conversion should return nil for an invalid date string.")
}
func testConvertValidDateToISO8601String() {
let validDate = Calendar.current.date(
from: DateComponents(
year: 2024,
month: 5,
day: 20,
hour: 22,
minute: 54,
second: 57,
nanosecond: 958000000
)
)
let expectedDateString = "2024-05-20T22:54:57.958"
let validDateString = validDate!.convertDateToISO8601String()
XCTAssertEqual(validDateString, expectedDateString, "Converted date string does not match expected date string")
}
}