@@ -12,12 +12,41 @@ import XCTest
1212class 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