Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions DemoApp/Rees46DemoTests/SearchServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ class SearchServiceImplTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}

func testSearchBlank_popularFields() {
let expectation = self.expectation(description: "searchBlank completion")

sdk?.searchBlank { result in
switch result {
case .success(let response):
XCTAssertFalse(response.popularLinks.isEmpty, "popular_links should not be empty for this shop")
for item in response.popularLinks {
XCTAssertFalse(item.name.isEmpty, "popular_links item must have a name")
XCTAssertFalse(item.url.isEmpty, "popular_links item must have a url")
}
for item in response.popularCategories {
XCTAssertFalse(item.name.isEmpty, "popular_categories item must have a name")
XCTAssertFalse(item.url.isEmpty, "popular_categories item must have a url")
}
for item in response.popularBrands {
XCTAssertFalse(item.name.isEmpty, "popular_brands item must have a name")
XCTAssertFalse(item.url.isEmpty, "popular_brands item must have a url")
}
case .failure(let error):
XCTFail("searchBlank failed with error: \(error)")
}
expectation.fulfill()
}

waitForExpectations(timeout: 10, handler: nil)
}

func testSearch_withMinimalFields() {
let query = "minimal query"

Expand Down
25 changes: 21 additions & 4 deletions REES46/Classes/Model/SearchResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,52 @@ public struct Suggest {
}
}

public struct PopularItem {
public var name: String
public var url: String

init(json: [String: Any]) {
self.name = json["name"] as? String ?? ""
self.url = json["url"] as? String ?? ""
}
}

public struct SearchBlankResponse {
public var lastQueries: [Query]
public var suggests: [Suggest]
public var lastProducts: Bool
public var products: [Product]

public var popularCategories: [PopularItem]
public var popularBrands: [PopularItem]
public var popularLinks: [PopularItem]

init(json: [String: Any]) {
let lastQueriesTemp = json["last_queries"] as? [[String: Any]] ?? []
var quyArr = [Query]()
for item in lastQueriesTemp {
quyArr.append(Query(json: item))
}
lastQueries = quyArr

let suggestsTemp = json["suggests"] as? [[String: Any]] ?? []
var sugArr = [Suggest]()
for item in suggestsTemp {
sugArr.append(Suggest(json: item))
}
suggests = sugArr

lastProducts = json["last_products"] as? Bool ?? true

let productsTemp = json["products"] as? [[String: Any]] ?? []
var productArr = [Product]()
for item in productsTemp {
productArr.append(Product(json: item))
}
products = productArr

popularCategories = (json["popular_categories"] as? [[String: Any]] ?? []).map { PopularItem(json: $0) }
popularBrands = (json["popular_brands"] as? [[String: Any]] ?? []).map { PopularItem(json: $0) }
popularLinks = (json["popular_links"] as? [[String: Any]] ?? []).map { PopularItem(json: $0) }
}
}

Expand Down
Loading