Skip to content

Commit

Permalink
Add protected to the settings model
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMachado committed Sep 7, 2017
1 parent 8a42cc7 commit 24f4691
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Source/Model/Card/CardSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ public class CardSettings: Mappable {
/// The position of the card.
public private(set) final var position: Int?

/// A boolean indicating if the card is protected.
public private(set) final var protected: Bool?

/// A boolean indicating if the card is starred.
public private(set) final var starred: Bool?

/**
Constructor.

- parameter position: The position of the card.
- parameter protected: A boolean indicating if the card is protected.
- parameter starred: A boolean indicating if the card is starred.
*/
public init(position: Int, starred: Bool) {
public init(position: Int, protected: Bool, starred: Bool) {
self.position = position
self.protected = protected
self.starred = starred
}

Expand All @@ -38,6 +43,7 @@ public class CardSettings: Mappable {
*/
public func mapping(map: Map) {
position <- map["position"]
protected <- map["protected"]
starred <- map["starred"]
}

Expand Down
2 changes: 2 additions & 0 deletions Tests/Integration/Model/CardTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CardTest: UpholdTestCase {
"\"lastTransactionAt\": \"foobiz\"," +
"\"settings\": {" +
"\"position\": 4," +
"\"protected\": true," +
"\"starred\": true" +
"}," +
"\"addresses\": [{" +
Expand Down Expand Up @@ -47,6 +48,7 @@ class CardTest: UpholdTestCase {
XCTAssertEqual(card!.normalized![0].balance!, "99.04", "Failed: Balance didn't match.")
XCTAssertEqual(card!.normalized![0].currency!, "USD", "Failed: Currency didn't match.")
XCTAssertEqual(card!.settings!.position!, 4, "Failed: Position didn't match.")
XCTAssertTrue(card!.settings!.protected!, "Failed: Protected didn't match.")
XCTAssertTrue(card!.settings!.starred!, "Failed: Starred didn't match.")
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/Model/UserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UserTest: UpholdTestCase {
}

func testCreateCardWithSettingsShouldReturnTheCard() {
let cardSettings: CardSettings = CardSettings(position: 1, starred: true)
let cardSettings: CardSettings = CardSettings(position: 1, protected: true, starred: true)
let expectation = expectationWithDescription("User test: create card.")
let user: User = Fixtures.loadUser()
user.adapter = MockRestAdapter(body: Mapper().toJSONString(Fixtures.loadCard(["id": "foobar"]))!)
Expand Down
3 changes: 2 additions & 1 deletion Tests/Util/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class Fixtures {
"normalizedBalance": String(format: "%@,%@,%@", faker.lorem.numerify("123456789"), faker.lorem.numerify("123456789"), faker.lorem.numerify("123456789")),
"normalizedCurrencies": String(format: "%@,%@,%@", faker.lorem.characters(amount: 3), faker.lorem.characters(amount: 3), faker.lorem.characters(amount: 3)),
"settingsPosition": faker.lorem.numerify("#"),
"settingsProtected": "true",
"settingsStarred": "true"
]

Expand All @@ -90,7 +91,7 @@ public class Fixtures {
normalized.append(NormalizedCard(available: available, balance: fakerFields["normalizedBalance"]!.componentsSeparatedByString(",")[index], currency: fakerFields["normalizedCurrencies"]!.componentsSeparatedByString(",")[index]))
}

let cardSettings = CardSettings(position: NSString(string: fakerFields["settingsPosition"]!).integerValue, starred: NSString(string: fakerFields["settingsStarred"]!).boolValue)
let cardSettings = CardSettings(position: NSString(string: fakerFields["settingsPosition"]!).integerValue, protected: NSString(string: fakerFields["settingsProtected"]!).boolValue, starred: NSString(string: fakerFields["settingsStarred"]!).boolValue)

return Card(id: fakerFields["id"]!, address: address, available: fakerFields["available"]!, balance: fakerFields["balance"]!, currency: fakerFields["currency"]!, label: fakerFields["label"]!, lastTransactionAt: fakerFields["lastTransactionAt"], normalized: normalized, settings: cardSettings)
}
Expand Down

0 comments on commit 24f4691

Please sign in to comment.