forked from MobileWorkshop/iOS
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPeopleServiceTests.swift
More file actions
94 lines (73 loc) · 2.84 KB
/
PeopleServiceTests.swift
File metadata and controls
94 lines (73 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import Foundation
import Quick
import Nimble
import OHHTTPStubs
import SwiftyJSON
@testable import HelloRest
class PeopleServiceTests: QuickSpec {
override func spec() {
beforeEach {
stub(isHost("localhost") && isPath("/list") && isMethodGET()) { request in
let obj = [[
"id": 7,
"name": "Ballard Craig",
],
[
"id": 8,
"name": "Brown Holt",
]]
return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G)
}
stub(isHost("localhost") && isPath("/listAll") && isMethodGET()) { request in
let obj = [[
"id": 7,
"name": "Ballard Craig",
"age": 19,
"phone": "somePhone"
],
[
"id": 8,
"name": "Brown Holt",
"age": 10,
"phone" : "somePhone"
]]
return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G)
}
}
afterEach {
OHHTTPStubs.removeAllStubs()
}
describe(".getAllPeople") {
it("should get people with limited detail from list endpoint") {
let peopleService = PeopleService()
var completionCalled = false
var actualPeople:[Person] = []
peopleService.getAllPeople { people in
completionCalled = true
actualPeople = people
}
expect(completionCalled).toEventually(beTrue())
expect(actualPeople).toEventually(haveCount(2))
let firstPerson = actualPeople.first
expect(firstPerson?.id).toNot(beNil())
expect(firstPerson?.name).toNot(beNil())
expect(firstPerson?.phone).to(beNil())
}
}
describe(".getAllPeopleWithDetails"){
it("should get people with details from listAll endpoint") {
let peopleService = PeopleService()
var completionCalled = false
var actualPeople:[Person] = []
peopleService.getAllPeopleWithDetails { people in
completionCalled = true
actualPeople = people
}
expect(completionCalled).toEventually(beTrue())
expect(actualPeople).toEventually(haveCount(2))
let firstPerson = actualPeople.first
expect(firstPerson?.phone).toNot(beNil())
}
}
}
}