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.
 
 
 
 

130 lines
3.4 KiB

//
// DatabaseTest.swift
// GMERemittanceTests
//
// Created by InKwon James Kim on 17/07/2019.
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import XCTest
import RxSwift
import RxCocoa
@testable import GME_Remit
class DatabaseTest: XCTestCase {
let testUserJson =
"""
{
"Id" : "",
"Extra" : "",
"Extra2" : "",
"Data" : {
"accessCode" : null,
"accessTokenRegTime" : "",
"kyc" : false,
"mobileNumber" : "",
"provinceId" : "",
"availableBalance" : "0",
"country" : "",
"ErrorCode" : "0",
"pennyTestStatus" : "0",
"accessTokenExpTime" : "",
"Extra" : "",
"firstName" : "iosDemo@gmeremit.com",
"Data" : null,
"yearlyLimit" : "30,000",
"dob" : "1988-03-27",
"dpUrl" : null,
"email" : "iosDemo@gmeremit.com",
"sourceId" : "",
"countryCode" : "",
"senderId" : "17",
"active" : true,
"appUpdate" : [
{
"Info" : "",
"OS" : "IOS",
"Build" : "6",
"Version" : "2.2.2",
"Critical" : "Y"
},
{
"Info" : "",
"OS" : "ANDROID",
"Build" : "17",
"Version" : "2.3.0",
"Critical" : "Y"
}
],
"Extra2" : "",
"isReferred" : false,
"rewardPoint" : "0",
"province" : "",
"cmRegistrationId" : "",
"Msg" : "",
"primaryBankName" : "",
"Id" : "",
"verified" : false,
"walletNumber" : "",
"userId" : "iosDemo@gmeremit.com",
"kftcClientId" : null
},
"ErrorCode" : "0",
"Msg" : "success"
}
"""
func testSetUser() {
let object = UserContainer(JSONString: testUserJson)
GMEDB
.shared
.setUser(object?.data)
.debugPrintAllElement()
XCTAssert(GMEDB.shared.user.string(.availableBalance) == Optional("0"))
XCTAssert(GMEDB.shared.user.string(.country) == Optional(""))
XCTAssert(GMEDB.shared.user.string(.errorCode) == nil)
XCTAssert(GMEDB.shared.user.string(.pennyTestStatusCode) == Optional("0"))
XCTAssert(GMEDB.shared.user.string(.firstName) == Optional("iosDemo@gmeremit.com"))
XCTAssert(GMEDB.shared.user.string(.data) == nil)
XCTAssert(GMEDB.shared.user.string(.yearlyLimit) == Optional("30,000"))
XCTAssert(GMEDB.shared.user.string(.dateOfBirth) == Optional("1988-03-27"))
XCTAssert(GMEDB.shared.user.string(.senderId) == Optional("17"))
}
func testRemoveAll() {
GMEDB
.shared
.user
.removeAll()
.debugPrintAllElement()
XCTAssert(GMEDB.shared.user.string(.availableBalance) == nil)
XCTAssert(GMEDB.shared.user.string(.country) == nil)
XCTAssert(GMEDB.shared.user.string(.errorCode) == nil)
XCTAssert(GMEDB.shared.user.string(.pennyTestStatusCode) == nil)
XCTAssert(GMEDB.shared.user.string(.firstName) == nil)
XCTAssert(GMEDB.shared.user.string(.data) == nil)
XCTAssert(GMEDB.shared.user.string(.yearlyLimit) == nil)
XCTAssert(GMEDB.shared.user.string(.dateOfBirth) == nil)
XCTAssert(GMEDB.shared.user.string(.senderId) == nil)
}
func testGMEDBRx() {
let expt = expectation(description: "testGMEDBRx")
_ = GMEDB.shared.user.rx.string(key: .userId)
.subscribe(onNext: {
print("userID: \($0 ?? "nil")")
XCTAssert($0 == Optional("test2"), GMEDB.shared.user.string(.userId) ?? "")
expt.fulfill()
})
GMEDB.shared.user.set("test2", .userId)
wait(for: [expt], timeout: 5.0)
}
}