Skip to content

Commit

Permalink
Merge pull request #63 from uphold/feature/add-verifications
Browse files Browse the repository at this point in the history
Add verifications to User model
  • Loading branch information
ruipenso authored Nov 23, 2017
2 parents e96ccc5 + 9b3c27b commit 251e05c
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Source/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ open class User: BaseModel, Mappable {
/// The user username.
public private(set) final var username: String?

/// The user verifications.
public private(set) final var verifications: Verifications?

/**
Constructor.

Expand All @@ -53,8 +56,9 @@ open class User: BaseModel, Mappable {
- parameter state: The user state.
- parameter status: The user status.
- parameter username: The user username.
- parameter verifications: The user verifications.
*/
public init(country: String, currencies: [String], email: String, firstName: String, lastName: String, memberAt: String, name: String, settings: UserSettings, state: String, status: String, username: String) {
public init(country: String, currencies: [String], email: String, firstName: String, lastName: String, memberAt: String, name: String, settings: UserSettings, state: String, status: String, username: String, verifications: Verifications) {
self.country = country
self.currencies = currencies
self.email = email
Expand All @@ -66,6 +70,7 @@ open class User: BaseModel, Mappable {
self.state = state
self.status = status
self.username = username
self.verifications = verifications
}

// MARK: Required by the ObjectMapper.
Expand Down Expand Up @@ -95,6 +100,7 @@ open class User: BaseModel, Mappable {
self.state <- map["state"]
self.status <- map["status"]
self.username <- map["username"]
self.verifications <- map["verifications"]
}

/**
Expand Down
44 changes: 44 additions & 0 deletions Source/Model/User/VerificationParameter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Foundation
import ObjectMapper

/// Verification parameter model.
open class VerificationParameter: Mappable {

/// The reason of the verification.
public private(set) final var reason: String?

/// The status of the verification.
public private(set) final var status: String?

/**
Constructor.

- parameter reason: The reason for the verification.
- parameter status: The status of the verification.
*/
public init(reason: String, status: String) {
self.reason = reason
self.status = status
}

// MARK: Required by the ObjectMapper.

/**
Constructor.

- parameter map: Mapping data object.
*/
required public init?(map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
open func mapping(map: Map) {
reason <- map["reason"]
status <- map["status"]
}

}
80 changes: 80 additions & 0 deletions Source/Model/User/Verifications.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Foundation
import ObjectMapper

/// Verifications model.
open class Verifications: Mappable {

/// The address verification.
public private(set) final var address: VerificationParameter?

/// The birthdate verification.
public private(set) final var birthdate: VerificationParameter?

/// The documents verification.
public private(set) final var documents: VerificationParameter?

/// The email verification.
public private(set) final var email: VerificationParameter?

/// The identity verification.
public private(set) final var identity: VerificationParameter?

/// The location verification.
public private(set) final var location: VerificationParameter?

/// The phone verification.
public private(set) final var phone: VerificationParameter?

/// The terms verification.
public private(set) final var terms: VerificationParameter?

/**
Constructor.

- parameter address: The address verification.
- parameter birthdate: The birthdate verification.
- parameter documents: The documents verification.
- parameter email: The email verification.
- parameter identity: The identity verification.
- parameter location: The location verification.
- parameter phone: The phone verification.
- parameter terms: The terms verification.
*/
public init(address: VerificationParameter?, birthdate: VerificationParameter?, documents: VerificationParameter?, email: VerificationParameter?, identity: VerificationParameter?, location: VerificationParameter?, phone: VerificationParameter?, terms: VerificationParameter?) {
self.address = address
self.birthdate = birthdate
self.documents = documents
self.email = email
self.identity = identity
self.location = location
self.phone = phone
self.terms = terms
}

// MARK: Required by the ObjectMapper.

/**
Constructor.

- parameter map: Mapping data object.
*/
required public init?(map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
open func mapping(map: Map) {
address <- map["address"]
birthdate <- map["birthdate"]
documents <- map["documents"]
email <- map["email"]
identity <- map["identity"]
location <- map["location"]
phone <- map["phone"]
terms <- map["terms"]
}

}
50 changes: 50 additions & 0 deletions Tests/IntegrationTests/ClientTests/UpholdClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ class UpholdClientTest: UpholdTestCase {
"}" +
"}" +
"}" +
"}," +
"\"verifications\": {" +
"\"address\": {" +
"\"reason\": \"foo\"," +
"\"status\": \"bar\"" +
"}," +
"\"birthdate\": {" +
"\"reason\": \"fiz\"," +
"\"status\": \"biz\"" +
"}," +
"\"documents\": {" +
"\"reason\": \"fuz\"," +
"\"status\": \"buz\"" +
"}," +
"\"email\": {" +
"\"reason\": \"foobar\"," +
"\"status\": \"foobuz\"" +
"}," +
"\"identity\": {" +
"\"reason\": \"bar\"," +
"\"status\": \"biz\"" +
"}," +
"\"location\": {" +
"\"reason\": \"biz\"," +
"\"status\": \"buz\"" +
"}," +
"\"phone\": {" +
"\"reason\": \"fizbuz\"," +
"\"status\": \"fuzbuz\"" +
"}," +
"\"terms\": {" +
"\"reason\": \"foobar\"," +
"\"status\": \"fizbiz\"" +
"}" +
"}" +
"}"
let client = MockUpholdClient(bearerToken: "foobar")
Expand Down Expand Up @@ -242,6 +276,22 @@ class UpholdClientTest: UpholdTestCase {
XCTAssertEqual(user.state, "FOO", "Failed: User name didn't match.")
XCTAssertEqual(user.status, "ok", "Failed: User name didn't match.")
XCTAssertEqual(user.username, "foobar", "Failed: User name didn't match.")
XCTAssertEqual(user.verifications!.address?.reason, "foo", "Failed: Address reason didn't match.")
XCTAssertEqual(user.verifications!.address?.status, "bar", "Failed: Address status didn't match.")
XCTAssertEqual(user.verifications!.birthdate?.reason, "fiz", "Failed: Birthdate reason didn't match.")
XCTAssertEqual(user.verifications!.birthdate?.status, "biz", "Failed: Birthdate status didn't match.")
XCTAssertEqual(user.verifications!.documents?.reason, "fuz", "Failed: Documents reason didn't match.")
XCTAssertEqual(user.verifications!.documents?.status, "buz", "Failed: Documents status didn't match.")
XCTAssertEqual(user.verifications!.email?.reason, "foobar", "Failed: Email reason didn't match.")
XCTAssertEqual(user.verifications!.email?.status, "foobuz", "Failed: Email status didn't match.")
XCTAssertEqual(user.verifications!.identity?.reason, "bar", "Failed: Identity reason didn't match.")
XCTAssertEqual(user.verifications!.identity?.status, "biz", "Failed: Identity status didn't match.")
XCTAssertEqual(user.verifications!.location?.reason, "biz", "Failed: Location reason didn't match.")
XCTAssertEqual(user.verifications!.location?.status, "buz", "Failed: Location status didn't match.")
XCTAssertEqual(user.verifications!.phone?.reason, "fizbuz", "Failed: Phone reason didn't match.")
XCTAssertEqual(user.verifications!.phone?.status, "fuzbuz", "Failed: Phone status didn't match.")
XCTAssertEqual(user.verifications!.terms?.reason, "foobar", "Failed: Terms reason didn't match.")
XCTAssertEqual(user.verifications!.terms?.status, "fizbiz", "Failed: Terms status didn't match.")

testExpectation.fulfill()
}.catch(execute: { (_: Error) in
Expand Down
50 changes: 50 additions & 0 deletions Tests/IntegrationTests/ModelTests/UserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,40 @@ class UserTest: UpholdTestCase {
"}" +
"}" +
"}" +
"}," +
"\"verifications\": {" +
"\"address\": {" +
"\"reason\": \"foo\"," +
"\"status\": \"bar\"" +
"}," +
"\"birthdate\": {" +
"\"reason\": \"fiz\"," +
"\"status\": \"biz\"" +
"}," +
"\"documents\": {" +
"\"reason\": \"fuz\"," +
"\"status\": \"buz\"" +
"}," +
"\"email\": {" +
"\"reason\": \"foobar\"," +
"\"status\": \"foobuz\"" +
"}," +
"\"identity\": {" +
"\"reason\": \"bar\"," +
"\"status\": \"biz\"" +
"}," +
"\"location\": {" +
"\"reason\": \"biz\"," +
"\"status\": \"buz\"" +
"}," +
"\"phone\": {" +
"\"reason\": \"fizbuz\"," +
"\"status\": \"fuzbuz\"" +
"}," +
"\"terms\": {" +
"\"reason\": \"foobar\"," +
"\"status\": \"fizbiz\"" +
"}" +
"}" +
"}"
let user = Mapper<User>().map(JSONString: json)
Expand All @@ -751,6 +785,22 @@ class UserTest: UpholdTestCase {
XCTAssertEqual(user!.state!, "FOO", "Failed: User name didn't match.")
XCTAssertEqual(user!.status!, "ok", "Failed: User name didn't match.")
XCTAssertEqual(user!.username!, "foobar", "Failed: User name didn't match.")
XCTAssertEqual(user!.verifications!.address!.reason, "foo", "Failed: Address reason didn't match.")
XCTAssertEqual(user!.verifications!.address!.status, "bar", "Failed: Address status didn't match.")
XCTAssertEqual(user!.verifications!.birthdate!.reason, "fiz", "Failed: Birthdate reason didn't match.")
XCTAssertEqual(user!.verifications!.birthdate!.status, "biz", "Failed: Birthdate status didn't match.")
XCTAssertEqual(user!.verifications!.documents!.reason, "fuz", "Failed: Documents reason didn't match.")
XCTAssertEqual(user!.verifications!.documents!.status, "buz", "Failed: Documents status didn't match.")
XCTAssertEqual(user!.verifications!.email!.reason, "foobar", "Failed: Email reason didn't match.")
XCTAssertEqual(user!.verifications!.email!.status, "foobuz", "Failed: Email status didn't match.")
XCTAssertEqual(user!.verifications!.identity!.reason, "bar", "Failed: Identity reason didn't match.")
XCTAssertEqual(user!.verifications!.identity!.status, "biz", "Failed: Identity status didn't match.")
XCTAssertEqual(user!.verifications!.location!.reason, "biz", "Failed: Location reason didn't match.")
XCTAssertEqual(user!.verifications!.location!.status, "buz", "Failed: Location status didn't match.")
XCTAssertEqual(user!.verifications!.phone!.reason, "fizbuz", "Failed: Phone reason didn't match.")
XCTAssertEqual(user!.verifications!.phone!.status, "fuzbuz", "Failed: Phone status didn't match.")
XCTAssertEqual(user!.verifications!.terms!.reason, "foobar", "Failed: Terms reason didn't match.")
XCTAssertEqual(user!.verifications!.terms!.status, "fizbiz", "Failed: Terms status didn't match.")
}

}
31 changes: 28 additions & 3 deletions Tests/UtilTests/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,23 @@ public class Fixtures {
"state": faker.address.stateAbbreviation(),
"status": faker.lorem.characters(amount: 10),
"theme": faker.lorem.characters(amount: 10),
"username": faker.lorem.characters(amount: 10)
"username": faker.lorem.characters(amount: 10),
"verificationsReasonAddress": faker.lorem.characters(amount: 10),
"verificationsReasonBirthdate": faker.lorem.characters(amount: 10),
"verificationsReasonDocuments": faker.lorem.characters(amount: 10),
"verificationsReasonEmail": faker.lorem.characters(amount: 10),
"verificationsReasonIdentity": faker.lorem.characters(amount: 10),
"verificationsReasonLocation": faker.lorem.characters(amount: 10),
"verificationsReasonPhone": faker.lorem.characters(amount: 10),
"verificationsReasonTerms": faker.lorem.characters(amount: 10),
"verificationsStatusAddress": faker.lorem.characters(amount: 10),
"verificationsStatusBirthdate": faker.lorem.characters(amount: 10),
"verificationsStatusDocuments": faker.lorem.characters(amount: 10),
"verificationsStatusEmail": faker.lorem.characters(amount: 10),
"verificationsStatusIdentity": faker.lorem.characters(amount: 10),
"verificationsStatusLocation": faker.lorem.characters(amount: 10),
"verificationsStatusPhone": faker.lorem.characters(amount: 10),
"verificationsStatusTerms": faker.lorem.characters(amount: 10)
]

if let fields = fields {
Expand All @@ -258,8 +274,17 @@ public class Fixtures {
let internationalizationUserSettings = InternationalizationUserSettings(language: internationalizationUserSettingLanguage, dateTimeFormat: internationalizationUserSettingDateTimeFormat, numberFormat: internationalizationUserSettingNumberFormat)
let otp = Otp(login: Login(enabled: NSString(string: fakerFields["settingsOTPLogin"]!).boolValue), transactions: Transactions(send: Send(enabled: NSString(string: fakerFields["settingsOTPTransactionsSend"]!).boolValue), transfer: Transfer(enabled: NSString(string: fakerFields["settingsOTPTransactionsTransfer"]!).boolValue), withdraw: Withdraw(crypto: Crypto(enabled: NSString(string: fakerFields["settingsOTPTransactionsWithdrawCrypto"]!).boolValue))))
let userSettings = UserSettings(currency: fakerFields["currency"]!, hasNewsSubscription: NSString(string: fakerFields["hasNewsSubscription"]!).boolValue, intl: internationalizationUserSettings, otp: otp, theme: fakerFields["theme"]!)

return User(country: fakerFields["country"]!, currencies: fakerFields["currencies"]!.components(separatedBy: ","), email: fakerFields["email"]!, firstName: fakerFields["firstName"]!, lastName: fakerFields["lastName"]!, memberAt: fakerFields["memberAt"]!, name: fakerFields["name"]!, settings: userSettings, state: fakerFields["state"]!, status: fakerFields["status"]!, username: fakerFields["username"]!)
let addressVerifications = VerificationParameter(reason: fakerFields["verificationsReasonAddress"]!, status: fakerFields["verificationsStatusAddress"]!)
let birthdateVerifications = VerificationParameter(reason: fakerFields["verificationsReasonBirthdate"]!, status: fakerFields["verificationsStatusBirthdate"]!)
let documentsVerifications = VerificationParameter(reason: fakerFields["verificationsReasonDocuments"]!, status: fakerFields["verificationsStatusDocuments"]!)
let emailVerifications = VerificationParameter(reason: fakerFields["verificationsReasonEmail"]!, status: fakerFields["verificationsStatusEmail"]!)
let identityVerifications = VerificationParameter(reason: fakerFields["verificationsReasonIdentity"]!, status: fakerFields["verificationsStatusIdentity"]!)
let locationVerifications = VerificationParameter(reason: fakerFields["verificationsReasonLocation"]!, status: fakerFields["verificationsStatusLocation"]!)
let phoneVerifications = VerificationParameter(reason: fakerFields["verificationsReasonPhone"]!, status: fakerFields["verificationsStatusPhone"]!)
let termsVerifications = VerificationParameter(reason: fakerFields["verificationsReasonTerms"]!, status: fakerFields["verificationsStatusTerms"]!)
let verifications = Verifications(address: addressVerifications, birthdate: birthdateVerifications, documents: documentsVerifications, email: emailVerifications, identity: identityVerifications, location: locationVerifications, phone: phoneVerifications, terms: termsVerifications)

return User(country: fakerFields["country"]!, currencies: fakerFields["currencies"]!.components(separatedBy: ","), email: fakerFields["email"]!, firstName: fakerFields["firstName"]!, lastName: fakerFields["lastName"]!, memberAt: fakerFields["memberAt"]!, name: fakerFields["name"]!, settings: userSettings, state: fakerFields["state"]!, status: fakerFields["status"]!, username: fakerFields["username"]!, verifications: verifications)
}

}
Loading

0 comments on commit 251e05c

Please sign in to comment.