diff --git a/BVSDK.xcodeproj/project.pbxproj b/BVSDK.xcodeproj/project.pbxproj index 9ae3fb01..9982a11a 100644 --- a/BVSDK.xcodeproj/project.pbxproj +++ b/BVSDK.xcodeproj/project.pbxproj @@ -44,6 +44,8 @@ 2E371E5A2808226B008D9223 /* BVSecondaryRatingsDistributionElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E371E582808226B008D9223 /* BVSecondaryRatingsDistributionElement.m */; }; 2E371E5D280824BE008D9223 /* BVSecondaryRatingsDistributionValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E371E5B280824BE008D9223 /* BVSecondaryRatingsDistributionValue.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E371E5E280824BE008D9223 /* BVSecondaryRatingsDistributionValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E371E5C280824BE008D9223 /* BVSecondaryRatingsDistributionValue.m */; }; + 2E88C046282A38C4007B77B0 /* BVCustomSortOrder.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E88C044282A38C4007B77B0 /* BVCustomSortOrder.h */; }; + 2E88C047282A38C4007B77B0 /* BVCustomSortOrder.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E88C045282A38C4007B77B0 /* BVCustomSortOrder.m */; }; 2E998AC82789963D0036DE64 /* BVFeaturesRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E998AC72789963D0036DE64 /* BVFeaturesRequest.m */; }; 2E998ACB2789967E0036DE64 /* BVFeaturesResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E998ACA2789967E0036DE64 /* BVFeaturesResponse.m */; }; 2E998ACD278996940036DE64 /* BVFeaturesRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E998ACC278996940036DE64 /* BVFeaturesRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -53,6 +55,9 @@ 2E998AD52789B4990036DE64 /* BVFeature.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E998AD42789B4990036DE64 /* BVFeature.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E998AD72789B4C20036DE64 /* BVFeature.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E998AD62789B4C20036DE64 /* BVFeature.m */; }; 2E998AD9278BF02A0036DE64 /* FeatureDisplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E998AD8278BF02A0036DE64 /* FeatureDisplayTests.swift */; }; + 2EA5DD962824FDA4006B0949 /* BVReviewsCustomOrderSortOptionValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EA5DD952824FDA4006B0949 /* BVReviewsCustomOrderSortOptionValue.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2EA5DD992825110E006B0949 /* BVReviewsCustomOrderSortOption.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EA5DD972825110E006B0949 /* BVReviewsCustomOrderSortOption.h */; }; + 2EA5DD9A2825110E006B0949 /* BVReviewsCustomOrderSortOption.m in Sources */ = {isa = PBXBuildFile; fileRef = 2EA5DD982825110E006B0949 /* BVReviewsCustomOrderSortOption.m */; }; 2EAD31C326DCAC8600903208 /* BVAuthenticatedUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 2EAD31C226DCAC8600903208 /* BVAuthenticatedUser.m */; }; 2EE2579127F23EE300E6DBDE /* BVReviewFilterFieldType.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EE2579027F23EE300E6DBDE /* BVReviewFilterFieldType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5F140C5D1F9553FE00905828 /* skelly_android.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F140C5C1F9553FE00905828 /* skelly_android.jpg */; }; @@ -692,6 +697,8 @@ 2E371E582808226B008D9223 /* BVSecondaryRatingsDistributionElement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVSecondaryRatingsDistributionElement.m; sourceTree = ""; }; 2E371E5B280824BE008D9223 /* BVSecondaryRatingsDistributionValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVSecondaryRatingsDistributionValue.h; sourceTree = ""; }; 2E371E5C280824BE008D9223 /* BVSecondaryRatingsDistributionValue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVSecondaryRatingsDistributionValue.m; sourceTree = ""; }; + 2E88C044282A38C4007B77B0 /* BVCustomSortOrder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVCustomSortOrder.h; sourceTree = ""; }; + 2E88C045282A38C4007B77B0 /* BVCustomSortOrder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVCustomSortOrder.m; sourceTree = ""; }; 2E998AC72789963D0036DE64 /* BVFeaturesRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVFeaturesRequest.m; sourceTree = ""; }; 2E998ACA2789967E0036DE64 /* BVFeaturesResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVFeaturesResponse.m; sourceTree = ""; }; 2E998ACC278996940036DE64 /* BVFeaturesRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVFeaturesRequest.h; sourceTree = ""; }; @@ -701,6 +708,9 @@ 2E998AD42789B4990036DE64 /* BVFeature.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVFeature.h; sourceTree = ""; }; 2E998AD62789B4C20036DE64 /* BVFeature.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVFeature.m; sourceTree = ""; }; 2E998AD8278BF02A0036DE64 /* FeatureDisplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureDisplayTests.swift; sourceTree = ""; }; + 2EA5DD952824FDA4006B0949 /* BVReviewsCustomOrderSortOptionValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVReviewsCustomOrderSortOptionValue.h; sourceTree = ""; }; + 2EA5DD972825110E006B0949 /* BVReviewsCustomOrderSortOption.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVReviewsCustomOrderSortOption.h; sourceTree = ""; }; + 2EA5DD982825110E006B0949 /* BVReviewsCustomOrderSortOption.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BVReviewsCustomOrderSortOption.m; sourceTree = ""; }; 2EAD31C226DCAC8600903208 /* BVAuthenticatedUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BVAuthenticatedUser.m; sourceTree = ""; }; 2EE2579027F23EE300E6DBDE /* BVReviewFilterFieldType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BVReviewFilterFieldType.h; sourceTree = ""; }; 3462CE8D50CC0B93A458E62C /* Pods-BVSDKTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BVSDKTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BVSDKTests/Pods-BVSDKTests.debug.xcconfig"; sourceTree = ""; }; @@ -1758,6 +1768,7 @@ 2EE2579027F23EE300E6DBDE /* BVReviewFilterFieldType.h */, B5BE76A5200EA666002BA818 /* BVReviewIncludeTypeValue.h */, B5BE76A7200EA6B4002BA818 /* BVReviewsSortOptionValue.h */, + 2EA5DD952824FDA4006B0949 /* BVReviewsCustomOrderSortOptionValue.h */, B583B124200E8ABE001E9548 /* BVSortOptionValues.h */, B583B121200E8ABD001E9548 /* BVSortOrderValues.h */, B583B11E200E888C001E9548 /* Private */, @@ -2304,6 +2315,8 @@ B583AEE82009486C001E9548 /* BVIncludeType.m */, B583AEDB2007FB59001E9548 /* BVMonotonicSortOrder.h */, B583AEDC2007FB59001E9548 /* BVMonotonicSortOrder.m */, + 2E88C044282A38C4007B77B0 /* BVCustomSortOrder.h */, + 2E88C045282A38C4007B77B0 /* BVCustomSortOrder.m */, 87F2DB781DAD585E00FB43F3 /* BVProductFilterType.h */, 87F2DB791DAD585E00FB43F3 /* BVProductFilterType.m */, B583AEEB20094A58001E9548 /* BVProductIncludeType.h */, @@ -2328,6 +2341,8 @@ B583AEE0200816A4001E9548 /* BVSortOption.m */, B583AED72007F80A001E9548 /* BVSortOrder.h */, B583AED82007F80A001E9548 /* BVSortOrder.m */, + 2EA5DD972825110E006B0949 /* BVReviewsCustomOrderSortOption.h */, + 2EA5DD982825110E006B0949 /* BVReviewsCustomOrderSortOption.m */, ); path = Private; sourceTree = ""; @@ -2781,6 +2796,7 @@ B58639C5214AFE8700EFD763 /* BVLocaleServiceManager.h in Headers */, B5BE768E200EA025002BA818 /* BVProductFilterValue.h in Headers */, B583B12A200E8ABE001E9548 /* BVSortOptionValues.h in Headers */, + 2E88C046282A38C4007B77B0 /* BVCustomSortOrder.h in Headers */, 87F2DCAD1DAD585E00FB43F3 /* BVQuestionsAndAnswersRequest.h in Headers */, 87F2DCBD1DAD585E00FB43F3 /* BVQuestionFilterType.h in Headers */, 87F2DCE11DAD585E00FB43F3 /* BVPhotoSubmission.h in Headers */, @@ -2905,6 +2921,7 @@ 873DC49B1E7482840080FA03 /* BVPersonalizationEvent.h in Headers */, B5BE76A0200EA53D002BA818 /* BVProductIncludeTypeValue.h in Headers */, B58639B2214AFE0A00EFD763 /* BVSDKManager+Private.h in Headers */, + 2EA5DD962824FDA4006B0949 /* BVReviewsCustomOrderSortOptionValue.h in Headers */, 2EE2579127F23EE300E6DBDE /* BVReviewFilterFieldType.h in Headers */, 982B607522EA125C0041D40B /* BVProgressiveSubmissionReview.h in Headers */, B5BE769C200EA473002BA818 /* BVCommentsSortOptionValue.h in Headers */, @@ -2968,6 +2985,7 @@ B575C38A1FBE02FE000F890B /* BVUASSubmissionErrorResponse.h in Headers */, B575C38E1FBE1A4F000F890B /* BVUASSubmissionResponse.h in Headers */, 5F51EA501F5F2BB4002FA8FD /* BVFormInputType.h in Headers */, + 2EA5DD992825110E006B0949 /* BVReviewsCustomOrderSortOption.h in Headers */, B583B129200E8ABE001E9548 /* BVFilterOperatorValues.h in Headers */, 5F6201DC1F7030FA00454D77 /* NSError+BVErrorCodeParser.h in Headers */, 5F608FF41F6AF3E100E197CE /* BVSubmissionErrorCode.h in Headers */, @@ -3297,6 +3315,7 @@ B57B8335215E8A58006B378E /* BVPhotoSubmissionErrorResponse.m in Sources */, B5A764E71FE191BA00B5DC9A /* BVStoreReviewSubmission.m in Sources */, 87C5FEBF1E22A05D004EE6E8 /* BVLogger.m in Sources */, + 2EA5DD9A2825110E006B0949 /* BVReviewsCustomOrderSortOption.m in Sources */, 873DC4981E7482840080FA03 /* BVInViewEvent.m in Sources */, B57B8329215E8054006B378E /* BVPhotoSubmissionResponse.m in Sources */, 87F2DD101DAD585E00FB43F3 /* BVReviewsCollectionView.m in Sources */, @@ -3377,6 +3396,7 @@ 87F2DC721DAD585E00FB43F3 /* BVDistributionElement.m in Sources */, 87C5FEC61E22A05D004EE6E8 /* BVStringKeyValuePair.m in Sources */, 87F2DC7D1DAD585E00FB43F3 /* BVProductsResponse.m in Sources */, + 2E88C047282A38C4007B77B0 /* BVCustomSortOrder.m in Sources */, B583AEF2200956D0001E9548 /* BVAuthorIncludeType.m in Sources */, 875411841E1F201E006C5C6E /* BVStoreReviewNotificationProperties.m in Sources */, 87F2DCBE1DAD585E00FB43F3 /* BVQuestionFilterType.m in Sources */, diff --git a/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.h b/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.h index 52b98141..b7eea9cb 100644 --- a/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.h +++ b/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.h @@ -35,6 +35,10 @@ sortByReviewsSortOptionValue:(BVReviewsSortOptionValue)reviewsSortOptionValue monotonicSortOrderValue:(BVMonotonicSortOrderValue)monotonicSortOrderValue; +- (nonnull instancetype) +sortByReviewsCustomOrderSortOptionValue:(BVReviewsCustomOrderSortOptionValue)reviewsCustomOrderSortOptionValue +customSortOrder:(nonnull NSArray *)customSortOrder; + - (nonnull instancetype) filterOnReviewFilterValue:(BVReviewFilterValue)reviewFilterValue relationalFilterOperatorValue: diff --git a/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.m b/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.m index 61a305cc..29832c3d 100644 --- a/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.m +++ b/BVSDK/BVConversations/Display/Requests/Review/BVBaseReviewsRequest.m @@ -13,12 +13,14 @@ #import "BVConversationsRequest+Private.h" #import "BVFilter.h" #import "BVMonotonicSortOrder.h" +#import "BVCustomSortOrder.h" #import "BVProduct.h" #import "BVRelationalFilterOperator.h" #import "BVReview.h" #import "BVReviewFilterType.h" #import "BVReviewIncludeType.h" #import "BVReviewsSortOption.h" +#import "BVReviewsCustomOrderSortOption.h" #import "BVSort.h" #import "BVStringKeyValuePair.h" @@ -157,6 +159,16 @@ - (nonnull instancetype)includeReviewIncludeTypeValue: return self; } +- (nonnull instancetype) +sortByReviewsCustomOrderSortOptionValue:(BVReviewsCustomOrderSortOptionValue)reviewsCustomOrderSortOptionValue + customSortOrder:(nonnull NSArray *)customSortOrder{ + BVSort *sort = [[BVSort alloc] initWithCustomOrderSortOption:[BVReviewsCustomOrderSortOption + sortOptionWithRawValue:reviewsCustomOrderSortOptionValue] + customSortOrder:[BVCustomSortOrder customSortOrderWithValues:customSortOrder]]; + [self.sorts addObject:sort]; + return self; +} + - (nonnull instancetype) filterOnReviewFilterValue:(BVReviewFilterValue)reviewFilterValue relationalFilterOperatorValue: diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/BVReviewsCustomOrderSortOptionValue.h b/BVSDK/BVConversations/Display/Sorting & Filtering/BVReviewsCustomOrderSortOptionValue.h new file mode 100644 index 00000000..b885e63d --- /dev/null +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/BVReviewsCustomOrderSortOptionValue.h @@ -0,0 +1,11 @@ +// +// BVReviewsCustomOrderSortOptionValue.h +// BVSDK +// +// Copyright © 2022 Bazaarvoice. All rights reserved. +// +#import + +typedef NS_ENUM(NSInteger, BVReviewsCustomOrderSortOptionValue) { + BVReviewsCustomOrderSortOptionValueContentLocale +}; diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/BVSortOptionValues.h b/BVSDK/BVConversations/Display/Sorting & Filtering/BVSortOptionValues.h index 6a5fcfa1..aff2c6cb 100644 --- a/BVSDK/BVConversations/Display/Sorting & Filtering/BVSortOptionValues.h +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/BVSortOptionValues.h @@ -16,4 +16,6 @@ #import "BVQuestionsSortOptionValue.h" #import "BVReviewsSortOptionValue.h" +#import "BVReviewsCustomOrderSortOptionValue.h" + #endif /* BVSORTOPTIONVALUES_H */ diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.h b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.h new file mode 100644 index 00000000..8a24db24 --- /dev/null +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.h @@ -0,0 +1,17 @@ +// +// BVCustomSortOrder.h +// BVSDK +// +// Copyright © 2022 Bazaarvoice. All rights reserved. +// +#import "BVSort.h" + +@interface BVCustomSortOrder : NSObject + ++ (nonnull instancetype)customSortOrderWithValues:(nonnull NSArray *)values; +- (nonnull instancetype)initWithCustomSortOrderValues: + (nonnull NSArray *)values; +- (nonnull instancetype)__unavailable init; + + +@end diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.m b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.m new file mode 100644 index 00000000..4c3441f5 --- /dev/null +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVCustomSortOrder.m @@ -0,0 +1,38 @@ +// +// BVCustomSortOrder.m +// BVSDK +// +// Copyright © 2022 Bazaarvoice. All rights reserved. +// + +#import "BVCustomSortOrder.h" +#import "BVCommaUtil.h" + +@interface BVCustomSortOrder () +@property(nonnull, nonatomic, strong) NSString *value; +@end + +@implementation BVCustomSortOrder + ++ (nonnull NSString *)toCustomSortOrderParameterStringWithValues:(nonnull NSArray *)values +{ + return [BVCustomSortOrder customSortOrderWithValues:values].value; +} + ++ (nonnull instancetype)customSortOrderWithValues:(nonnull NSArray *)values { + return [[BVCustomSortOrder alloc] initWithCustomSortOrderValues:values]; +} + +- (nonnull NSString *)toCustomSortOrderParameterString { + return self.value; +} + +- (nonnull instancetype)initWithCustomSortOrderValues: +(nonnull NSArray *)values { + if ((self = [super init])) { + self.value = [[BVCommaUtil escapeMultiple:values] componentsJoinedByString:@","]; + } + return self; +} + +@end diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.h b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.h new file mode 100644 index 00000000..0c37af61 --- /dev/null +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.h @@ -0,0 +1,16 @@ +// +// BVReviewsCustomOrderCustomOrderSortOption.h +// BVSDK +// +// Copyright © 2022 Bazaarvoice. All rights reserved. +// + +#import "BVReviewsCustomOrderSortOptionValue.h" +#import "BVSortOption.h" + +@interface BVReviewsCustomOrderSortOption : BVSortOption + +- (nonnull instancetype)initWithReviewsSortOptionValue: + (BVReviewsCustomOrderSortOptionValue)reviewsSortOptionValue; + +@end diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.m b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.m new file mode 100644 index 00000000..ff176a60 --- /dev/null +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVReviewsCustomOrderSortOption.m @@ -0,0 +1,38 @@ +#import "BVReviewsCustomOrderSortOption.h" + +@interface BVReviewsCustomOrderSortOption () +@property(nonnull, nonatomic, strong) NSString *value; +@end + +@implementation BVReviewsCustomOrderSortOption + ++ (nonnull NSString *)toSortOptionParameterStringWithRawValue: + (NSInteger)rawValue { + return [BVReviewsCustomOrderSortOption sortOptionWithRawValue:rawValue].value; +} + ++ (nonnull instancetype)sortOptionWithRawValue:(NSInteger)rawValue { + return [[BVReviewsCustomOrderSortOption alloc] initWithRawValue:rawValue]; +} + +- (nonnull instancetype)initWithRawValue:(NSInteger)rawValue { + if ((self = [super initWithRawValue:rawValue])) { + switch (rawValue) { + case BVReviewsCustomOrderSortOptionValueContentLocale: + self.value = @"ContentLocale"; + break; + } + } + return self; +} + +- (nonnull NSString *)toSortOptionParameterString { + return self.value; +} + +- (nonnull instancetype)initWithReviewsSortOptionValue: + (BVReviewsCustomOrderSortOptionValue)reviewsSortOptionValue { + return [BVReviewsCustomOrderSortOption sortOptionWithRawValue:reviewsSortOptionValue]; +} + +@end diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.h b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.h index fe0a7934..a1061fc5 100644 --- a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.h +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.h @@ -19,6 +19,12 @@ - (nonnull NSString *)toSortOrderParameterString; @end +@protocol BVCustomSortOrderProtocol ++ (nonnull NSString *)toCustomSortOrderParameterStringWithValues: + (nonnull NSArray *)values; +- (nonnull NSString *)toCustomSortOrderParameterString; +@end + @interface BVSort : NSObject - (nonnull id)initWithSortOption:(nonnull id)sortOption @@ -26,6 +32,8 @@ - (nonnull id)initWithSortOptionString:(nonnull NSString *)sortOptionString sortOrder: (nonnull id)sortOrder; +- (nonnull id)initWithCustomOrderSortOption:(nonnull id)customOrderSortOption + customSortOrder:(nonnull id)customSortOrder; - (nonnull NSString *)toParameterString; @end diff --git a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.m b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.m index 39d491b2..260dc401 100644 --- a/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.m +++ b/BVSDK/BVConversations/Display/Sorting & Filtering/Private/BVSort.m @@ -35,6 +35,15 @@ - (nonnull id)initWithSortOptionString:(nonnull NSString *)sortOptionString return self; } +- (nonnull id)initWithCustomOrderSortOption:(nonnull id)customOrderSortOption + customSortOrder:(nonnull id)customSortOrder{ + if ((self = [super init])) { + self.sortOption = [customOrderSortOption toSortOptionParameterString]; + self.sortOrder = [customSortOrder toCustomSortOrderParameterString]; + } + return self; +} + - (nonnull NSString *)toParameterString { return [NSString stringWithFormat:@"%@:%@", self.sortOption, self.sortOrder]; } diff --git a/BVSDKTests/ConversationsTests/DisplayTests/ReviewDisplayTests.swift b/BVSDKTests/ConversationsTests/DisplayTests/ReviewDisplayTests.swift index 7cb9337e..4923a55a 100644 --- a/BVSDKTests/ConversationsTests/DisplayTests/ReviewDisplayTests.swift +++ b/BVSDKTests/ConversationsTests/DisplayTests/ReviewDisplayTests.swift @@ -727,4 +727,73 @@ class ReviewDisplayTests: XCTestCase { XCTAssertNil(error, "Something went horribly wrong, request took too long.") } } + + func testReviewCustomSortOrder() { + + let configDict = ["clientId": "testcustomermobilesdk", + "apiKeyConversations": "cavNO70oED9uDIo3971pfLc9IJET3eaozVNHJhL1vnAK4"]; + BVSDKManager.configure(withConfiguration: configDict, configType: .staging) + + let expectation = self.expectation(description: "testReviewCustomSortOrder") + + let request = BVReviewsRequest(productId: "product1", limit: 20, offset: 0) + .sort(by: .contentLocale, customSortOrder: ["es_US","en_US"]) + + + request.load({ (response) in + + let reviews = response.results + let ContentLocales = reviews.map { review in + review.contentLocale + } + + XCTAssertTrue(ContentLocales.index(of: "es_US")! < ContentLocales.index(of: "en_US")!); + expectation.fulfill() + + }) { (error) in + + XCTFail("review display request error: \(error)") + expectation.fulfill() + } + + self.waitForExpectations(timeout: 1000) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") + } + + } + + func testReviewCustomSortOrderOver5Values() { + + let configDict = ["clientId": "testcustomermobilesdk", + "apiKeyConversations": "cavNO70oED9uDIo3971pfLc9IJET3eaozVNHJhL1vnAK4"]; + BVSDKManager.configure(withConfiguration: configDict, configType: .staging) + + + let expectation = self.expectation(description: "testReviewCustomSortOrderOver5Values") + + let request = BVReviewsRequest(productId: "product1", limit: 10, offset: 5) + .sort(by: .contentLocale, customSortOrder: ["fr_FR","en_GB","en_US","en_ZH","en_CA","en_DE"]) + + request.load({ (response) in + + XCTFail("Only 5 locales are allowed") + expectation.fulfill() + + }) { (errors) in + for error in errors as [NSError] { + + let errorCode = error.userInfo["BVKeyErrorCode"] as! String + let errorMessage = error.userInfo["BVKeyErrorMessage"] as! String + + XCTAssertEqual(errorCode, "ERROR_PARAM_INVALID_SORT_ATTRIBUTE") + XCTAssertEqual(errorMessage, "Sort by contentlocale cannot have more than 5 values") + } + expectation.fulfill() + } + + self.waitForExpectations(timeout: 1000) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") + } + + } }