Skip to content

Commit 463df22

Browse files
author
cramsden@thoughtworks.com
committed
[Carson] code cleanup
1 parent 835ac82 commit 463df22

File tree

8 files changed

+43
-14
lines changed

8 files changed

+43
-14
lines changed

RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
680951131D24339000EF3F63 /* PeopleTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 680951121D24339000EF3F63 /* PeopleTransformer.swift */; };
1919
680951151D243C7100EF3F63 /* PeopleListViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 680951141D243C7100EF3F63 /* PeopleListViewModelTests.swift */; };
2020
680951171D243E0700EF3F63 /* PeopleServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 680951161D243E0700EF3F63 /* PeopleServiceMock.swift */; };
21+
68F3F63B1D257519007CD3A4 /* PeopleTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F3F63A1D257519007CD3A4 /* PeopleTransformerTests.swift */; };
2122
AD550FF41D1D5D33001B640B /* PeopleListViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD550FF31D1D5D33001B640B /* PeopleListViewControllerTests.swift */; };
2223
AD86366D1D1CA38000792EDC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD86366C1D1CA38000792EDC /* AppDelegate.swift */; };
2324
AD8636721D1CA38000792EDC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AD8636701D1CA38000792EDC /* Main.storyboard */; };
@@ -49,6 +50,7 @@
4950
680951121D24339000EF3F63 /* PeopleTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleTransformer.swift; sourceTree = "<group>"; };
5051
680951141D243C7100EF3F63 /* PeopleListViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleListViewModelTests.swift; sourceTree = "<group>"; };
5152
680951161D243E0700EF3F63 /* PeopleServiceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleServiceMock.swift; sourceTree = "<group>"; };
53+
68F3F63A1D257519007CD3A4 /* PeopleTransformerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleTransformerTests.swift; sourceTree = "<group>"; };
5254
AAA49A9A49AFCAAE85CD5DFA /* Pods_HelloRest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HelloRest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5355
AD550FF31D1D5D33001B640B /* PeopleListViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeopleListViewControllerTests.swift; sourceTree = "<group>"; };
5456
AD70B3D63BE2E643752101A6 /* Pods-HelloRestSpecs.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloRestSpecs.release.xcconfig"; path = "../Pods/Target Support Files/Pods-HelloRestSpecs/Pods-HelloRestSpecs.release.xcconfig"; sourceTree = "<group>"; };
@@ -144,6 +146,7 @@
144146
isa = PBXGroup;
145147
children = (
146148
680950F51D24216E00EF3F63 /* PeopleServiceTests.swift */,
149+
68F3F63A1D257519007CD3A4 /* PeopleTransformerTests.swift */,
147150
);
148151
name = Services;
149152
sourceTree = "<group>";
@@ -500,6 +503,7 @@
500503
isa = PBXSourcesBuildPhase;
501504
buildActionMask = 2147483647;
502505
files = (
506+
68F3F63B1D257519007CD3A4 /* PeopleTransformerTests.swift in Sources */,
503507
AD550FF41D1D5D33001B640B /* PeopleListViewControllerTests.swift in Sources */,
504508
680951151D243C7100EF3F63 /* PeopleListViewModelTests.swift in Sources */,
505509
680951111D24300200EF3F63 /* PersonTests.swift in Sources */,

RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct PeopleListViewModel {
88

99
init(peopleService: PeopleServiceType) {
1010
self.peopleService = peopleService
11-
peopleService.getAllPeopleJSON() { people in
11+
peopleService.getAllPeople() { people in
1212
self.people.value = people
1313
}
1414
}

RestExample/HelloRest/HelloRest/Services/PeopleService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import Alamofire
33
import SwiftyJSON
44

55
protocol PeopleServiceType {
6-
func getAllPeopleJSON(onCompletion: ([Person]) -> Void)
6+
func getAllPeople(onCompletion: ([Person]) -> Void)
77
}
88

99
class PeopleService : PeopleServiceType {
1010

11-
func getAllPeopleJSON(onCompletion: ([Person]) -> Void) {
11+
func getAllPeople(onCompletion: ([Person]) -> Void) {
1212
Alamofire
1313
.request(.GET, "http://localhost:8000/list")
1414
.validate(statusCode: 200..<400)
1515
.responseJSON { response in
1616
if let value = response.result.value {
1717
let json = JSON(value)
18-
let people = PeopleTransformer.transformListOfPeopleWithoutDetail(json)
18+
let people = PeopleTransformer.transformListOfPeople(json)
1919
onCompletion(people)
2020
}
2121
}

RestExample/HelloRest/HelloRest/Services/PeopleTransformer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Foundation
22
import SwiftyJSON
33

44
struct PeopleTransformer {
5-
static func transformListOfPeopleWithoutDetail(response: JSON) -> [Person] {
5+
static func transformListOfPeople(response: JSON) -> [Person] {
66
let jsonArray = response.arrayValue
77
return jsonArray.map { json in
8-
Person(id: json["id"].intValue, name: json["name"].stringValue)
8+
Person(id: json["id"].intValue, name: json["name"].stringValue, age: json["age"].int, phone: json["phone"].string)
99
}
1010
}
1111
}

RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PeopleServiceMock: PeopleServiceType {
66
var getAllPeopleCalled = false
77
var stubbedPeopleWithoutDetail = [Person(id: 1, name: "someName")]
88

9-
func getAllPeopleJSON(onCompletion: ([Person]) -> Void){
9+
func getAllPeople(onCompletion: ([Person]) -> Void){
1010
getAllPeopleCalled = true
1111
onCompletion(stubbedPeopleWithoutDetail)
1212
}

RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@ class PeopleServiceTests: QuickSpec {
2929
OHHTTPStubs.removeAllStubs()
3030
}
3131

32-
describe(".getAllPeopleJSON") {
33-
it("should get data from list all") {
32+
describe(".getAllPeople") {
33+
it("should get people with limited detail from list endpoint") {
3434
let peopleService = PeopleService()
3535
var completionCalled = false
36-
var actualResponse:[Person] = []
36+
var actualPeople:[Person] = []
3737

38-
peopleService.getAllPeopleJSON { response in
38+
peopleService.getAllPeople { people in
3939
completionCalled = true
40-
actualResponse = response
40+
actualPeople = people
4141
}
4242

4343
expect(completionCalled).toEventually(beTrue())
44-
expect(actualResponse).toEventually(haveCount(2))
44+
expect(actualPeople).toEventually(haveCount(2))
45+
46+
let firstPerson = actualPeople.first
47+
48+
expect(firstPerson?.id).toNot(beNil())
49+
expect(firstPerson?.name).toNot(beNil())
50+
expect(firstPerson?.phone).to(beNil())
4551
}
4652

4753
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
import Quick
3+
import Nimble
4+
import SwiftyJSON
5+
6+
@testable import HelloRest
7+
8+
class PeopleTransformerTests: QuickSpec {
9+
override func spec() {
10+
describe("TransformListOfPeople") {
11+
it("should take a json response without detail and transform it into a person") {
12+
let expectedPerson = Person(id: 1, name: "someName")
13+
let jsonResponse = JSON([["id": 1, "name":"someName"]])
14+
let actualPerson = PeopleTransformer.transformListOfPeople(jsonResponse).first
15+
expect(expectedPerson) == actualPerson
16+
}
17+
}
18+
}
19+
}

RestExample/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ SPEC CHECKSUMS:
5151

5252
PODFILE CHECKSUM: b9f03359ee098d97f977bed85815ef8ccce755da
5353

54-
COCOAPODS: 1.0.1
54+
COCOAPODS: 1.0.0

0 commit comments

Comments
 (0)