Skip to content

Commit 15d5709

Browse files
committed
Add set personalisation strategy test ignoring error 429 (too many requests)
1 parent f827dbb commit 15d5709

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Sources/AlgoliaSearchClient/Models/Internal/HTTP/HTTPStatusCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension HTTPStatusСode {
1313

1414
static let notFound: HTTPStatusСode = 404
1515
static let requestTimeout: HTTPStatusСode = 408
16+
static let tooManyRequests: HTTPStatusСode = 429
1617

1718
func belongs(to categories: HTTPStatusCategory...) -> Bool {
1819
return categories.map { $0.contains(self) }.contains(true)

Tests/AlgoliaSearchClientTests/Integration/PersonalizationIntegrationTests.swift

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,41 @@ import XCTest
1212
class PersonalizationIntegrationTests: OnlineTestCase {
1313

1414
override var retryableTests: [() throws -> Void] {
15-
[personalization]
15+
[
16+
getStrategy,
17+
setStrategy
18+
]
1619
}
1720

18-
func personalization() throws {
21+
func getStrategy() throws {
1922
let recommendationClient = RecommendationClient(appID: client.applicationID, apiKey: client.apiKey, region: .custom("eu"))
2023
let _ = try recommendationClient.getPersonalizationStrategy()
2124
}
2225

26+
func setStrategy() throws {
27+
28+
let recommendationClient = RecommendationClient(appID: client.applicationID, apiKey: client.apiKey, region: .custom("us"))
29+
30+
let strategy = PersonalizationStrategy(
31+
eventsScoring: [
32+
.init(eventName: "Add to cart", eventType: .conversion, score: 50),
33+
.init(eventName: "Purchase", eventType: .conversion, score: 100)
34+
],
35+
facetsScoring: [
36+
.init(facetName: "brand", score: 100),
37+
.init(facetName: "categories", score: 10)
38+
],
39+
personalizationImpact: 0
40+
)
41+
42+
do {
43+
try recommendationClient.setPersonalizationStrategy(strategy)
44+
} catch let httpError as HTTPError where httpError.statusCode == HTTPStatusСode.tooManyRequests {
45+
// The personalization API is now limiting the number of setPersonalizationStrategy()` successful calls
46+
// to 15 per day. If the 429 error is returned, the response is considered a "success".
47+
} catch let error {
48+
throw error
49+
}
50+
}
51+
2352
}

0 commit comments

Comments
 (0)