Skip to content

Commit 9b39f19

Browse files
committed
split test class
1 parent cd5d48c commit 9b39f19

File tree

3 files changed

+267
-69
lines changed

3 files changed

+267
-69
lines changed

AlgoliaSearch.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/* Begin PBXBuildFile section */
1010
5D74958A1A8E25A600B0263F /* AlgoliaSearch.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D74957E1A8E25A600B0263F /* AlgoliaSearch.framework */; };
11-
5D7495911A8E25A600B0263F /* AlgoliaSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D7495901A8E25A600B0263F /* AlgoliaSearchTests.swift */; };
1211
5D7495A11A8E277400B0263F /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D74959F1A8E277400B0263F /* Extension.swift */; };
1312
5D7495A21A8E277400B0263F /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D7495A01A8E277400B0263F /* Client.swift */; };
1413
5D7495A71A8E499B00B0263F /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D7495A61A8E499B00B0263F /* Query.swift */; };
14+
5D8FFA381AAB08830078869E /* ClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D8FFA371AAB08830078869E /* ClientTests.swift */; };
15+
5D8FFA3A1AAB0AB80078869E /* IndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D8FFA391AAB0AB80078869E /* IndexTests.swift */; };
1516
5D9F70821A93B4BE004B751B /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D9F70811A93B4BE004B751B /* Alamofire.framework */; };
1617
5D9F70851A93B9C9004B751B /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D9F70811A93B4BE004B751B /* Alamofire.framework */; };
1718
5D9F70871A93BE2A004B751B /* Alamofire.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5D9F70811A93B4BE004B751B /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -47,10 +48,11 @@
4748
5D7495821A8E25A600B0263F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4849
5D7495891A8E25A600B0263F /* AlgoliaSearchTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AlgoliaSearchTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4950
5D74958F1A8E25A600B0263F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
50-
5D7495901A8E25A600B0263F /* AlgoliaSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlgoliaSearchTests.swift; sourceTree = "<group>"; };
5151
5D74959F1A8E277400B0263F /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
5252
5D7495A01A8E277400B0263F /* Client.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
5353
5D7495A61A8E499B00B0263F /* Query.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Query.swift; sourceTree = "<group>"; };
54+
5D8FFA371AAB08830078869E /* ClientTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientTests.swift; sourceTree = "<group>"; };
55+
5D8FFA391AAB0AB80078869E /* IndexTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexTests.swift; sourceTree = "<group>"; };
5456
5D9F70811A93B4BE004B751B /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/Mac/Alamofire.framework; sourceTree = "<group>"; };
5557
5DECA2D91A960BC5001A6088 /* Index.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Index.swift; sourceTree = "<group>"; };
5658
5DF8C1301A9CA354006E107B /* Type.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Type.swift; sourceTree = "<group>"; };
@@ -120,7 +122,8 @@
120122
5D74958D1A8E25A600B0263F /* Tests */ = {
121123
isa = PBXGroup;
122124
children = (
123-
5D7495901A8E25A600B0263F /* AlgoliaSearchTests.swift */,
125+
5D8FFA391AAB0AB80078869E /* IndexTests.swift */,
126+
5D8FFA371AAB08830078869E /* ClientTests.swift */,
124127
5D74958E1A8E25A600B0263F /* Supporting Files */,
125128
);
126129
path = Tests;
@@ -253,7 +256,8 @@
253256
isa = PBXSourcesBuildPhase;
254257
buildActionMask = 2147483647;
255258
files = (
256-
5D7495911A8E25A600B0263F /* AlgoliaSearchTests.swift in Sources */,
259+
5D8FFA381AAB08830078869E /* ClientTests.swift in Sources */,
260+
5D8FFA3A1AAB0AB80078869E /* IndexTests.swift in Sources */,
257261
);
258262
runOnlyForDeploymentPostprocessing = 0;
259263
};

Tests/ClientTests.swift

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
//
2+
// Copyright (c) 2015 Algolia
3+
// http://www.algolia.com/
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
//
23+
24+
import XCTest
25+
import AlgoliaSearch
26+
import Alamofire
27+
28+
class ClientTests: XCTestCase {
29+
let expectationTimeout: NSTimeInterval = 100
30+
31+
var client: Client!
32+
var index: Index!
33+
34+
override func setUp() {
35+
super.setUp()
36+
let appID = NSProcessInfo.processInfo().environment["ALGOLIA_APPLICATION_ID"] as String
37+
let apiKey = NSProcessInfo.processInfo().environment["ALGOLIA_API_KEY"] as String
38+
client = AlgoliaSearch.Client(appID: appID, apiKey: apiKey)
39+
index = client.getIndex("algol?à-swift")
40+
41+
let expectation = expectationWithDescription("Delete index")
42+
client.deleteIndex(index.indexName, block: { (JSON, error) -> Void in
43+
XCTAssertNil(error, "Error during deleteIndex: \(error?.description)")
44+
expectation.fulfill()
45+
})
46+
47+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
48+
}
49+
50+
override func tearDown() {
51+
super.tearDown()
52+
53+
let expectation = expectationWithDescription("Delete index")
54+
client.deleteIndex(index.indexName, block: { (JSON, error) -> Void in
55+
XCTAssertNil(error, "Error during deleteIndex: \(error?.description)")
56+
expectation.fulfill()
57+
})
58+
59+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
60+
}
61+
62+
func testListIndexes() {
63+
let expectation = expectationWithDescription("testListIndexes")
64+
let object = ["city": "San Francisco", "objectID": "a/go/?à"]
65+
66+
index.addObject(object, block: { (JSON, error) -> Void in
67+
if let error = error {
68+
XCTFail("Error during addObject: \(error)")
69+
expectation.fulfill()
70+
} else {
71+
self.index.waitTask(JSON!["taskID"] as Int, block: { (JSON, error) -> Void in
72+
if let error = error {
73+
XCTFail("Error during waitTask: \(error)")
74+
expectation.fulfill()
75+
} else {
76+
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
77+
78+
self.client.listIndexes({ (JSON, error) -> Void in
79+
if let error = error {
80+
XCTFail("Error during listIndexes: \(error)")
81+
} else {
82+
let items = JSON!["items"] as [[String: AnyObject]]
83+
84+
var find = false
85+
for item in items {
86+
if (item["name"] as String) == self.index.indexName {
87+
find = true
88+
}
89+
}
90+
91+
XCTAssertTrue(find, "List indexes failed")
92+
}
93+
94+
expectation.fulfill()
95+
})
96+
}
97+
})
98+
}
99+
})
100+
101+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
102+
}
103+
104+
func testMoveIndex() {
105+
let expecation = expectationWithDescription("testMoveIndex")
106+
let object = ["city": "San Francisco", "objectID": "a/go/?à"]
107+
108+
index.addObject(object, block: { (JSON, error) -> Void in
109+
if let error = error {
110+
XCTFail("Error during addObject: \(error)")
111+
expecation.fulfill()
112+
} else {
113+
self.index.waitTask(JSON!["taskID"] as Int, block: { (JSON, error) -> Void in
114+
if let error = error {
115+
XCTFail("Error during waitTask: \(error)")
116+
expecation.fulfill()
117+
} else {
118+
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
119+
120+
self.client.moveIndex(self.index.indexName, dstIndexName: "algol?à-swift2", block: { (JSON, error) -> Void in
121+
if let error = error {
122+
XCTFail("Error during moveIndex: \(error)")
123+
expecation.fulfill()
124+
} else {
125+
self.index.waitTask(JSON!["taskID"] as Int, block: { (JSON, error) -> Void in
126+
if let error = error {
127+
XCTFail("Error during waitTask: \(error)")
128+
expecation.fulfill()
129+
} else {
130+
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
131+
132+
let dstIndex = self.client.getIndex("algol?à-swift2")
133+
dstIndex.search(Query(), block: { (JSON, error) -> Void in
134+
if let error = error {
135+
XCTFail("Error during search: \(error)")
136+
} else {
137+
let nbHits = JSON!["nbHits"] as Int
138+
XCTAssertEqual(nbHits, 1, "Wrong number of object in the index")
139+
}
140+
141+
expecation.fulfill()
142+
})
143+
}
144+
})
145+
}
146+
})
147+
}
148+
})
149+
}
150+
})
151+
152+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
153+
154+
let deleteExpectation = expectationWithDescription("Delete index")
155+
client.deleteIndex("algol?à-swift2", block: { (JSON, error) -> Void in
156+
XCTAssertNil(error, "Error during deleteIndex: \(error?.description)")
157+
deleteExpectation.fulfill()
158+
})
159+
160+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
161+
}
162+
163+
func testCopyIndex() {
164+
let expecation = expectationWithDescription("testCopyIndex")
165+
let srcIndexExpectation = expectationWithDescription("srcIndex")
166+
let dstIndexExpectation = expectationWithDescription("dstIndex")
167+
168+
let object = ["city": "San Francisco", "objectID": "a/go/?à"]
169+
170+
index.addObject(object, block: { (JSON, error) -> Void in
171+
if let error = error {
172+
XCTFail("Error during addObject: \(error)")
173+
expecation.fulfill()
174+
} else {
175+
self.index.waitTask(JSON!["taskID"] as Int, block: { (JSON, error) -> Void in
176+
if let error = error {
177+
XCTFail("Error during waitTask: \(error)")
178+
expecation.fulfill()
179+
} else {
180+
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
181+
182+
self.client.copyIndex(self.index.indexName, dstIndexName: "algol?à-swift2", block: { (JSON, error) -> Void in
183+
if let error = error {
184+
XCTFail("Error during copyIndex: \(error)")
185+
expecation.fulfill()
186+
} else {
187+
self.index.waitTask(JSON!["taskID"] as Int, block: { (JSON, error) -> Void in
188+
if let error = error {
189+
XCTFail("Error during waitTask: \(error)")
190+
expecation.fulfill()
191+
} else {
192+
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
193+
expecation.fulfill()
194+
195+
self.index.search(Query(), block: { (JSON, error) -> Void in
196+
if let error = error {
197+
XCTFail("Error during search: \(error)")
198+
} else {
199+
let nbHits = JSON!["nbHits"] as Int
200+
XCTAssertEqual(nbHits, 1, "Wrong number of object in the index")
201+
}
202+
203+
srcIndexExpectation.fulfill()
204+
})
205+
206+
let dstIndex = self.client.getIndex("algol?à-swift2")
207+
dstIndex.search(Query(), block: { (JSON, error) -> Void in
208+
if let error = error {
209+
XCTFail("Error during search: \(error)")
210+
} else {
211+
let nbHits = JSON!["nbHits"] as Int
212+
XCTAssertEqual(nbHits, 1, "Wrong number of object in the index")
213+
}
214+
215+
dstIndexExpectation.fulfill()
216+
})
217+
}
218+
})
219+
}
220+
})
221+
}
222+
})
223+
}
224+
})
225+
226+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
227+
228+
let deleteExpectation = expectationWithDescription("Delete index")
229+
client.deleteIndex("algol?à-swift2", block: { (JSON, error) -> Void in
230+
XCTAssertNil(error, "Error during deleteIndex: \(error?.description)")
231+
deleteExpectation.fulfill()
232+
})
233+
234+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
235+
}
236+
}

0 commit comments

Comments
 (0)