Skip to content

Commit

Permalink
feat(predict): implemented recommendProducts on api
Browse files Browse the repository at this point in the history
SUITEDEV-35484

Co-authored-by: Andras Sarro <[email protected]>
  • Loading branch information
davidSchuppa and LordAndras committed Apr 10, 2024
1 parent f7c32bd commit f650312
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Sources/EmarsysSDK/API/Predict/Predict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class Predict<LoggingInstance: PredictInstance, GathererInstance: PredictInstanc
}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return []
return if let active = self.active as? PredictApi {
await active.recommendProducts(logic: logic, filters: filters, limit: limit, availabilityZone: availabilityZone)
} else {
[]
}
}
}
2 changes: 1 addition & 1 deletion Sources/EmarsysSDK/Model/Predict/RecommendedProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation


struct RecommendedProduct: Product {
struct RecommendedProduct: Product, Equatable {
let productId: String
let title: String
let linkUrl: String
Expand Down
27 changes: 27 additions & 0 deletions Sources/EmarsysSDKTests/API/Predict/PredictTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ final class PredictTests: EmarsysTestCase {
.verify(\.fnTrackRecommendationClick)
.wasCalled(Arg.eq(product))
}

func testRecommendProducts_shouldDelegateToInstance() async throws {
let logicName = "testLogic"
let data = ["key1": "value1"]
let variants = ["var1", "var2"]
let logic = Logic(logicName: logicName, data: data, variants: variants)
let filters = [Filter(type: .include, field: "testField", comparison: .in, value: "test")]
let limit = 100
let availabilityZone = "testZone"
let expectedProducts = [
RecommendedProduct(productId: "testId", title: "title", linkUrl: "linkURL", feature: "feature", cohort: "cohort"),
RecommendedProduct(productId: "testId2", title: "title2", linkUrl: "linkURL2", feature: "feature2", cohort: "cohort2")
]

self.fakePredictInternal.when(\.fnRecommendProducts).thenReturn(expectedProducts)

let result = await self.predict.recommendProducts(logic: logic, filters: filters, limit: limit, availabilityZone: availabilityZone)

let _ = try! self.fakePredictInternal
.verify(\.fnRecommendProducts)
.wasCalled(Arg.eq(logic),
Arg.eq(filters),
Arg.eq(limit),
Arg.eq(availabilityZone)
)
XCTAssertEqual(result as! [RecommendedProduct], expectedProducts)
}
}

struct TestCartItem: CartItem {
Expand Down

0 comments on commit f650312

Please sign in to comment.