Skip to content

Commit 8567242

Browse files
author
William Templeton
committed
Added test for groupSearch
1 parent 24ddf11 commit 8567242

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Tests/TypesenseTests/DocumentTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@ final class DocumentTests: XCTestCase {
220220

221221
}
222222

223+
func testDocumentGroupSearch() async {
224+
let config = Configuration(nodes: [Node(host: "localhost", port: "8108", nodeProtocol: "http")], apiKey: "xyz", logger: Logger(debugMode: true))
225+
226+
let client = Client(config: config)
227+
228+
let searchParams = SearchParameters(q: "*", queryBy: "company_name", groupBy: "num_employees")
229+
230+
do {
231+
let (data, _) = try await client.collection(name: "companies").documents().search(searchParams, for: Company.self)
232+
233+
XCTAssertNotNil(data)
234+
guard let validResp = data else {
235+
throw DataError.dataNotFound
236+
}
237+
if let gotSomeGroupedHits = validResp.groupedHits {
238+
XCTAssertNotNil(validResp.groupedHits)
239+
XCTAssertNotNil(validResp.found)
240+
XCTAssertNotNil(gotSomeGroupedHits.first)
241+
XCTAssertNotNil(gotSomeGroupedHits.first?.found)
242+
}
243+
} catch HTTPError.serverError(let code, let desc) {
244+
print(desc)
245+
print("The response status code is \(code)")
246+
XCTAssertTrue(false)
247+
} catch (let error) {
248+
print(error.localizedDescription)
249+
XCTAssertTrue(false)
250+
}
251+
}
252+
223253
func testDocumentImport() async {
224254
let config = Configuration(nodes: [Node(host: "localhost", port: "8108", nodeProtocol: "http")], apiKey: "xyz", logger: Logger(debugMode: true))
225255

0 commit comments

Comments
 (0)