Skip to content

Commit 5b0e000

Browse files
authored
refact: Remove addObject|s methods and refactor the UT (#600)
* refact: Deprecate addObject|s methods and refactor the UT
1 parent 492cffd commit 5b0e000

File tree

9 files changed

+124
-122
lines changed

9 files changed

+124
-122
lines changed

Gemfile.lock

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
11
GEM
2+
remote: https://rubygems.org/
23
specs:
34
CFPropertyList (3.0.0)
5+
activesupport (4.2.11)
6+
i18n (~> 0.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
410
addressable (2.5.2)
511
public_suffix (>= 2.0.2, < 4.0)
612
atomos (0.1.3)
713
babosa (1.0.2)
814
claide (1.0.2)
15+
cocoapods (1.6.0.beta.2)
16+
activesupport (>= 4.0.2, < 5)
17+
claide (>= 1.0.2, < 2.0)
18+
cocoapods-core (= 1.6.0.beta.2)
19+
cocoapods-deintegrate (>= 1.0.2, < 2.0)
20+
cocoapods-downloader (>= 1.2.2, < 2.0)
21+
cocoapods-plugins (>= 1.0.0, < 2.0)
22+
cocoapods-search (>= 1.0.0, < 2.0)
23+
cocoapods-stats (>= 1.0.0, < 2.0)
24+
cocoapods-trunk (>= 1.3.1, < 2.0)
25+
cocoapods-try (>= 1.1.0, < 2.0)
26+
colored2 (~> 3.1)
27+
escape (~> 0.0.4)
28+
fourflusher (~> 2.0.1)
29+
gh_inspector (~> 1.0)
30+
molinillo (~> 0.6.6)
31+
nap (~> 1.0)
32+
ruby-macho (~> 1.3, >= 1.3.1)
33+
xcodeproj (>= 1.7.0, < 2.0)
34+
cocoapods-core (1.6.0.beta.2)
35+
activesupport (>= 4.0.2, < 6)
36+
fuzzy_match (~> 2.0.4)
37+
nap (~> 1.0)
38+
cocoapods-deintegrate (1.0.2)
39+
cocoapods-downloader (1.2.2)
40+
cocoapods-plugins (1.0.0)
41+
nap
42+
cocoapods-search (1.0.0)
43+
cocoapods-stats (1.1.0)
44+
cocoapods-trunk (1.3.1)
45+
nap (>= 0.8, < 2.0)
46+
netrc (~> 0.11)
47+
cocoapods-try (1.1.0)
948
colored (1.2)
1049
colored2 (3.1.2)
1150
commander-fastlane (4.4.6)
1251
highline (~> 1.7.2)
52+
concurrent-ruby (1.1.4)
1353
declarative (0.0.10)
1454
declarative-option (0.1.0)
1555
domain_name (0.5.20180417)
1656
unf (>= 0.0.5, < 1.0.0)
1757
dotenv (2.5.0)
1858
emoji_regex (0.1.1)
59+
escape (0.0.4)
1960
excon (0.62.0)
2061
faraday (0.15.3)
2162
multipart-post (>= 1.2, < 3)
@@ -61,6 +102,8 @@ GEM
61102
xcodeproj (>= 1.6.0, < 2.0.0)
62103
xcpretty (~> 0.3.0)
63104
xcpretty-travis-formatter (>= 0.0.3)
105+
fourflusher (2.0.1)
106+
fuzzy_match (2.0.4)
64107
gh_inspector (1.1.3)
65108
google-api-client (0.23.9)
66109
addressable (~> 2.5, >= 2.5.1)
@@ -81,18 +124,24 @@ GEM
81124
http-cookie (1.0.3)
82125
domain_name (~> 0.5)
83126
httpclient (2.8.3)
127+
i18n (0.9.5)
128+
concurrent-ruby (~> 1.0)
84129
json (2.1.0)
85130
jwt (2.1.0)
86131
memoist (0.16.0)
87132
mime-types (3.2.2)
88133
mime-types-data (~> 3.2015)
89134
mime-types-data (3.2018.0812)
90135
mini_magick (4.5.1)
136+
minitest (5.11.3)
137+
molinillo (0.6.6)
91138
multi_json (1.13.1)
92139
multi_xml (0.6.0)
93140
multipart-post (2.0.0)
94141
nanaimo (0.2.6)
142+
nap (1.1.0)
95143
naturally (2.2.0)
144+
netrc (0.11.0)
96145
os (1.0.0)
97146
plist (3.4.0)
98147
public_suffix (2.0.5)
@@ -102,6 +151,7 @@ GEM
102151
uber (< 0.2.0)
103152
retriable (3.1.2)
104153
rouge (2.0.7)
154+
ruby-macho (1.3.1)
105155
rubyzip (1.2.2)
106156
security (0.1.3)
107157
signet (0.11.0)
@@ -116,10 +166,13 @@ GEM
116166
terminal-notifier (1.8.0)
117167
terminal-table (1.8.0)
118168
unicode-display_width (~> 1.1, >= 1.1.1)
169+
thread_safe (0.3.6)
119170
tty-cursor (0.6.0)
120171
tty-screen (0.6.5)
121172
tty-spinner (0.8.0)
122173
tty-cursor (>= 0.5.0)
174+
tzinfo (1.2.5)
175+
thread_safe (~> 0.1)
123176
uber (0.1.0)
124177
unf (0.1.4)
125178
unf_ext
@@ -147,7 +200,9 @@ PLATFORMS
147200
ruby
148201

149202
DEPENDENCIES
203+
cocoapods (~> 1.6.0.beta.1)
204+
fastlane
150205
xcov
151206

152207
BUNDLED WITH
153-
1.16.6
208+
1.17.2

Podfile.lock

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

2828
PODFILE CHECKSUM: 6a84a4eada474315f0e394fa18031f32df0658a4
2929

30-
COCOAPODS: 1.6.0.beta.1
30+
COCOAPODS: 1.6.0.beta.2

Sources/AlgoliaSearch-Client/Index.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ import Foundation
6161
/// - parameter requestOptions: Request-specific options.
6262
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
6363
/// - returns: A cancellable operation.
64+
/// + Warning: Deprecated, use saveObject(_:) instead.
6465
///
66+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
6567
@objc
6668
@discardableResult public func addObject(_ object: [String: Any], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> Operation {
6769
let path = "1/indexes/\(urlEncodedName)"
6870
return client.performHTTPQuery(path: path, method: .POST, body: object, hostnames: client.writeHosts, requestOptions: requestOptions, completionHandler: completionHandler)
6971
}
7072

73+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
7174
@objc(addObject:completionHandler:)
7275
@discardableResult public func z_objc_addObject(_ object: [String: Any], completionHandler: CompletionHandler?) -> Operation {
7376
return addObject(object, requestOptions: nil, completionHandler: completionHandler)
@@ -81,14 +84,16 @@ import Foundation
8184
/// - parameter requestOptions: Request-specific options.
8285
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
8386
/// - returns: A cancellable operation.
84-
/// + Warning: Deprecated, use addObject(_:) instead.
87+
/// + Warning: Deprecated, use saveObject(_:) instead.
8588
///
89+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
8690
@objc
8791
@discardableResult public func addObject(_ object: [String: Any], withID objectID: String, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> Operation {
8892
let path = "1/indexes/\(urlEncodedName)/\(objectID.urlEncodedPathComponent())"
8993
return client.performHTTPQuery(path: path, method: .PUT, body: object, hostnames: client.writeHosts, requestOptions: requestOptions, completionHandler: completionHandler)
9094
}
9195

96+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
9297
@objc(addObject:withID:completionHandler:)
9398
@discardableResult public func z_objc_addObject(_ object: [String: Any], withID objectID: String, completionHandler: CompletionHandler?) -> Operation {
9499
return addObject(object, withID: objectID, completionHandler: completionHandler)
@@ -100,7 +105,9 @@ import Foundation
100105
/// - parameter requestOptions: Request-specific options.
101106
/// - parameter completionHandler: Completion handler to be notified of the request's outcome.
102107
/// - returns: A cancellable operation.
108+
/// + Warning: Deprecated, use saveObjects(_:) instead.
103109
///
110+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
104111
@objc
105112
@discardableResult public func addObjects(_ objects: [[String: Any]], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> Operation {
106113
let path = "1/indexes/\(urlEncodedName)/batch"
@@ -115,6 +122,7 @@ import Foundation
115122
return client.performHTTPQuery(path: path, method: .POST, body: request, hostnames: client.writeHosts, requestOptions: requestOptions, completionHandler: completionHandler)
116123
}
117124

125+
@available(*, deprecated: 6.0, message: "Deprecated, use saveObject(_:) instead")
118126
@objc(addObjects:completionHandler:)
119127
@discardableResult public func z_objc_addObjects(_ objects: [[String: Any]], completionHandler: CompletionHandler?) -> Operation {
120128
return addObjects(objects, completionHandler: completionHandler)

Tests/Helpers/TestHelpers.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ import PromiseKit
1212
import XCTest
1313

1414
extension OnlineTestCase {
15-
func addObject(_ object: [String: Any]) -> Promise<[String: Any]> {
16-
return promiseWrap({ fulfill, reject in
17-
self.index.addObject(object, completionHandler: completionWrap(fulfill: fulfill, reject: reject))
18-
})
19-
}
20-
21-
func addObjects(_ objects: [[String: Any]]) -> Promise<[String: Any]> {
22-
return promiseWrap({ fulfill, reject in
23-
self.index.addObjects(objects, completionHandler: completionWrap(fulfill: fulfill, reject: reject))
24-
})
25-
}
2615

2716
func saveObject(_ object: [String: Any]) -> Promise<[String: Any]> {
2817
return promiseWrap({ fulfill, reject in

Tests/Integration Tests/BrowseIteratorTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ class BrowseIteratorTests: OnlineTestCase {
3434
let expectation = self.expectation(description: "Add objects")
3535
var objects = [[String: Any]]()
3636
for i in 0 ... 1500 {
37-
objects.append(["i": i])
37+
objects.append(["i": i,
38+
"objectID": NSUUID().uuidString
39+
])
3840
}
39-
index.addObjects(objects) { (content, error) -> Void in
41+
index.saveObjects(objects) { (content, error) -> Void in
4042
if error != nil {
41-
XCTFail("Error during addObjects: \(error!)")
43+
XCTFail("Error during saveObjects: \(error!)")
4244
expectation.fulfill()
4345
} else {
4446
self.index.waitTask(withID: content!["taskID"] as! Int) { (_, error) -> Void in

Tests/Integration Tests/ClientTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ClientTests: OnlineTestCase {
3636
}
3737

3838
let promise = firstly {
39-
self.addObject(mockObject)
39+
self.saveObject(mockObject)
4040
}.then { object in
4141
self.waitTask(object)
4242
}.then { _ in
@@ -60,7 +60,7 @@ class ClientTests: OnlineTestCase {
6060
let dstIndex = client.index(withName: safeIndexName("algol?à-swift2"))
6161

6262
let promise = firstly {
63-
self.addObject(object)
63+
self.saveObject(object)
6464
}.then { object in
6565
self.waitTask(object)
6666
}
@@ -100,7 +100,7 @@ class ClientTests: OnlineTestCase {
100100
let dstIndex = client.index(withName: safeIndexName("algol?à-swift2"))
101101

102102
let promise = firstly {
103-
self.addObject(object)
103+
self.saveObject(object)
104104
}.then { object in
105105
self.waitTask(object)
106106
}
@@ -141,11 +141,11 @@ class ClientTests: OnlineTestCase {
141141

142142
func testMultipleQueries() {
143143
let expectation = self.expectation(description: "testMultipleQueries")
144-
let object = ["city": "San Francisco"]
144+
let object = ["city": "San Francisco", "objectID": NSUUID().uuidString]
145145
let queries = [IndexQuery(index: self.index, query: Query())]
146146

147147
let promise = firstly {
148-
self.addObject(object)
148+
self.saveObject(object)
149149
}.then { object in
150150
self.waitTask(object)
151151
}
@@ -170,7 +170,7 @@ class ClientTests: OnlineTestCase {
170170

171171
func testMultipleQueries_stopIfEnoughMatches() {
172172
let expectation = self.expectation(description: "testMultipleQueries")
173-
let object = ["city": "San Francisco"]
173+
let object = ["city": "San Francisco", "objectID": NSUUID().uuidString]
174174
let query = Query()
175175
query.hitsPerPage = 1
176176
let queries = [
@@ -179,7 +179,7 @@ class ClientTests: OnlineTestCase {
179179
]
180180

181181
let promise = firstly {
182-
self.addObject(object)
182+
self.saveObject(object)
183183
}.then { object in
184184
self.waitTask(object)
185185
}
@@ -257,12 +257,12 @@ class ClientTests: OnlineTestCase {
257257
[
258258
"indexName": index.name,
259259
"action": "addObject",
260-
"body": ["city": "San Francisco"],
260+
"body": ["city": "San Francisco", "objectID": NSUUID().uuidString],
261261
],
262262
[
263263
"indexName": index.name,
264264
"action": "addObject",
265-
"body": ["city": "Paris"],
265+
"body": ["city": "Paris", "objectID": NSUUID().uuidString],
266266
],
267267
]
268268

0 commit comments

Comments
 (0)