diff --git a/BVSDK.podspec b/BVSDK.podspec index 58d6400e..fd83b5cc 100644 --- a/BVSDK.podspec +++ b/BVSDK.podspec @@ -62,7 +62,7 @@ Pod::Spec.new do |s| curationsui.source_files = 'Pod/BVCurationsUI/**/*.{h,m}' curationsui.dependency 'BVSDK/BVCurations' curationsui.dependency 'BVSDK/BVCommonUI' - curationsui.resources = ["Pod/BVCurationsUI/Assets/*.xcassets"] + curationsui.resources = ["Pod/BVCurationsUI/SocialMediaIcons/*.xcassets"] end s.subspec 'BVNotifications' do |notifications| diff --git a/Pod/BVConversations/Display/Requests/BVCommentsRequest.h b/Pod/BVConversations/Display/Requests/BVCommentsRequest.h index fbe6f323..dbac15db 100644 --- a/Pod/BVConversations/Display/Requests/BVCommentsRequest.h +++ b/Pod/BVConversations/Display/Requests/BVCommentsRequest.h @@ -17,7 +17,9 @@ @interface BVCommentsRequest : BVConversationsRequest -@property(nonnull, readonly) NSString *reviewId; +@property(nonnull, readonly) NSString *productId; +@property(nullable, readonly) NSString *reviewId; +@property(nullable, readonly) NSString *commentId; @property(nonatomic, assign, readonly) UInt16 limit; @property(nonatomic, assign, readonly) UInt16 offset; @property(nonnull, nonatomic, strong, readonly) NSMutableArray *sorts; @@ -25,12 +27,13 @@ NSMutableArray *filters; @property(nonnull, nonatomic, strong, readonly) NSMutableArray *includes; -@property(nonnull, readonly) NSString *commentId; -- (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId - limit:(UInt16)limit - offset:(UInt16)offset; -- (nonnull instancetype)initWithCommentId:(nonnull NSString *)commentId; +- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId + andReviewId:(nonnull NSString *)reviewId + limit:(UInt16)limit + offset:(UInt16)offset; +- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId + andCommentId:(nonnull NSString *)commentId; - (nonnull instancetype)__unavailable init; diff --git a/Pod/BVConversations/Display/Requests/BVCommentsRequest.m b/Pod/BVConversations/Display/Requests/BVCommentsRequest.m index 58c27eb3..9ac9c3e8 100644 --- a/Pod/BVConversations/Display/Requests/BVCommentsRequest.m +++ b/Pod/BVConversations/Display/Requests/BVCommentsRequest.m @@ -13,11 +13,13 @@ @implementation BVCommentsRequest -- (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId - limit:(UInt16)limit - offset:(UInt16)offset { +- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId + andReviewId:(nonnull NSString *)reviewId + limit:(UInt16)limit + offset:(UInt16)offset { self = [super init]; if (self) { + _productId = productId; _reviewId = reviewId; _limit = limit; _offset = offset; @@ -29,9 +31,11 @@ - (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId return self; } -- (nonnull instancetype)initWithCommentId:(nonnull NSString *)commentId { +- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId + andCommentId:(nonnull NSString *)commentId { self = [super init]; if (self) { + _productId = productId; _commentId = commentId; _filters = [NSMutableArray array]; _sorts = [NSMutableArray array]; @@ -96,15 +100,32 @@ - (void)sendCommentImpressionAnalytics:(NSArray *)comments { } - (nonnull NSMutableArray *)createParams { + NSMutableArray *params = [super createParams]; - // There are two ways to make a request: 1) with a review Id to get a bunch - // of comments or 2) just get single review. + // There are two ways to make a request with a product identifier: 1) with a + // review identifier to get a bunch of comments or 2) with a comment + // identifier to just get single review. + NSAssert(self.productId, @"You must supply a valid product identifier in the " + @"supplied initiaizers."); + + NSAssert(self.commentId || self.reviewId, @"You must also supply a valid " + @"comment or review identifier in " + @"the supplied initiaizers."); + + if (self.productId) { + [params + addObject:[BVStringKeyValuePair + pairWithKey:@"Filter" + value:[NSString stringWithFormat:@"ProductId:%@", + self.productId]]]; + } + if (self.reviewId) { [params addObject:[BVStringKeyValuePair pairWithKey:@"Filter" - value:[NSString stringWithFormat:@"reviewId:%@", + value:[NSString stringWithFormat:@"ReviewId:%@", self.reviewId]]]; [params addObject:[BVStringKeyValuePair pairWithKey:@"Limit" @@ -114,8 +135,9 @@ - (nonnull NSMutableArray *)createParams { pairWithKey:@"Offset" value:[NSString stringWithFormat:@"%i", self.offset]]]; + } - } else if (self.commentId) { + if (self.commentId) { BVFilter *commentIdFilter = [[BVFilter alloc] initWithType:BVProductFilterTypeId filterOperator:BVFilterOperatorEqualTo @@ -123,10 +145,6 @@ - (nonnull NSMutableArray *)createParams { [params addObject:[BVStringKeyValuePair pairWithKey:@"Filter" value:[commentIdFilter toParameterString]]]; - - } else { - NSAssert(NO, @"You must supply a valid comment or review ID in the " - @"supplied initiaizers."); } for (BVFilter *filter in self.filters) { diff --git a/Pod/BVConversations/Display/Requests/BVConversationsRequest.m b/Pod/BVConversations/Display/Requests/BVConversationsRequest.m index 1a917a2b..b33b7b8b 100644 --- a/Pod/BVConversations/Display/Requests/BVConversationsRequest.m +++ b/Pod/BVConversations/Display/Requests/BVConversationsRequest.m @@ -11,7 +11,6 @@ #import "BVDiagnosticHelpers.h" #import "BVSDKConfiguration.h" #import "BVSDKManager.h" -#import "BVStoreReviewsResponse.h" @interface BVConversationsRequest () @property(strong, nonatomic) diff --git a/Tests/Tests/ConversationsTests/DisplayTests/CommentsDisplayTests.swift b/Tests/Tests/ConversationsTests/DisplayTests/CommentsDisplayTests.swift index f5e41a5a..22938495 100644 --- a/Tests/Tests/ConversationsTests/DisplayTests/CommentsDisplayTests.swift +++ b/Tests/Tests/ConversationsTests/DisplayTests/CommentsDisplayTests.swift @@ -9,200 +9,198 @@ import XCTest @testable import BVSDK class CommentsDisplayTests: XCTestCase { + + override func setUp() { + super.setUp() - override func setUp() { - super.setUp() - - let configDict = ["clientId": "apitestcustomer", - "apiKeyConversations": "kuy3zj9pr3n7i0wxajrzj04xo"]; - BVSDKManager.configure(withConfiguration: configDict, configType: .staging) - BVSDKManager.shared().setLogLevel(BVLogLevel.verbose) + let configDict = ["clientId": "apitestcustomer", + "apiKeyConversations": "kuy3zj9pr3n7i0wxajrzj04xo"]; + BVSDKManager.configure(withConfiguration: configDict, configType: .staging) + BVSDKManager.shared().setLogLevel(BVLogLevel.verbose) + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testCommentDisplayByReviewId() { + let expectation = self.expectation(description: "testCommentDisplayByReviewId") + + let limit : UInt16 = 99 + let offset : UInt16 = 0 + + let request = BVCommentsRequest(productId: "1000001", andReviewId: "192548", limit: limit, offset: offset) + + request.load({ (response) in + + XCTAssertEqual(response.results.count, 5) + XCTAssertEqual(response.limit?.uint16Value, limit) + XCTAssertEqual(response.offset?.uint16Value, offset) + XCTAssertGreaterThan(response.totalResults!.intValue, 4) + XCTAssertEqual(response.locale, "en_US") + + expectation.fulfill() + + }) { (error) in + + XCTFail("comments by product id display request error: \(error)") + } - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() + self.waitForExpectations(timeout: 10) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") } - func testCommentDisplayByReviewId() { - let expectation = self.expectation(description: "testCommentDisplayByReviewId") - - let limit : UInt16 = 99 - let offset : UInt16 = 0 - - let request = BVCommentsRequest(reviewId: "192548", limit: limit, offset: offset) - - request.load({ (response) in - - XCTAssertEqual(response.results.count, 5) - XCTAssertEqual(response.limit?.uint16Value, limit) - XCTAssertEqual(response.offset?.uint16Value, offset) - XCTAssertGreaterThan(response.totalResults!.intValue, 4) - XCTAssertEqual(response.locale, "en_US") - - expectation.fulfill() - - }) { (error) in - - XCTFail("comments by product id display request error: \(error)") - - } - - self.waitForExpectations(timeout: 10) { (error) in - XCTAssertNil(error, "Something went horribly wrong, request took too long.") - } - + } + + func testCommentDisplayByCommentId() { + let expectation = self.expectation(description: "testCommentDisplayByCommentId") + + let request = BVCommentsRequest(productId: "1000001", andCommentId: "12024") + + + request.load({ (response) in + + XCTAssertEqual(response.results.count, 1) + + let theComment = response.results.first! + + XCTAssertEqual(theComment.title, "TEST>> I came in the store wanting to try 4 other") + XCTAssertEqual(theComment.authorId, "63kfce2dchdd2f8te9en4xx5y") + XCTAssertEqual(theComment.isSyndicated, false) + XCTAssertEqual(theComment.reviewId, "192548") + XCTAssertEqual(theComment.userLocation, nil) + XCTAssertEqual(theComment.commentText, "TEST>> I came in the store wanting to try 4 other dresses, and didnt even notice this one. I walked by a huge poster, and this beautiful dress caught my eye! It ended up being the first dress I tried on, and it was right then, that I knew this was the right dress. After this dress, I tried on 4 other ones, but decided on buying this one. It fits sooooo perfectly, and it gives your body a wonderful shape.test\nI love this dress sooooooo much!!") + + let calendar = Calendar.current + + let year = calendar.component(.year, from: theComment.submissionTime!) + let month = calendar.component(.month, from: theComment.submissionTime!) + let day = calendar.component(.day, from: theComment.submissionTime!) + + XCTAssertEqual(2011, year) + XCTAssertEqual(6, month) + XCTAssertEqual(27, day) + + XCTAssertNotNil(theComment.lastModeratedTime) + XCTAssertNotNil(theComment.lastModificationTime) + + expectation.fulfill() + + }) { (error) in + + XCTFail("comments by product id display request error: \(error)") + } - func testCommentDisplayByCommentId() { - let expectation = self.expectation(description: "testCommentDisplayByCommentId") - - let request = BVCommentsRequest(commentId: "12024") - - - request.load({ (response) in - - XCTAssertEqual(response.results.count, 1) - - let theComment = response.results.first! - - XCTAssertEqual(theComment.title, "TEST>> I came in the store wanting to try 4 other") - XCTAssertEqual(theComment.authorId, "63kfce2dchdd2f8te9en4xx5y") - XCTAssertEqual(theComment.isSyndicated, false) - XCTAssertEqual(theComment.reviewId, "192548") - XCTAssertEqual(theComment.userLocation, nil) - XCTAssertEqual(theComment.commentText, "TEST>> I came in the store wanting to try 4 other dresses, and didnt even notice this one. I walked by a huge poster, and this beautiful dress caught my eye! It ended up being the first dress I tried on, and it was right then, that I knew this was the right dress. After this dress, I tried on 4 other ones, but decided on buying this one. It fits sooooo perfectly, and it gives your body a wonderful shape.test\nI love this dress sooooooo much!!") - - let calendar = Calendar.current - - let year = calendar.component(.year, from: theComment.submissionTime!) - let month = calendar.component(.month, from: theComment.submissionTime!) - let day = calendar.component(.day, from: theComment.submissionTime!) - - XCTAssertEqual(2011, year) - XCTAssertEqual(6, month) - XCTAssertEqual(27, day) - - XCTAssertNotNil(theComment.lastModeratedTime) - XCTAssertNotNil(theComment.lastModificationTime) - - expectation.fulfill() - - }) { (error) in - - XCTFail("comments by product id display request error: \(error)") - - } - - self.waitForExpectations(timeout: 10) { (error) in - XCTAssertNil(error, "Something went horribly wrong, request took too long.") - } - - + self.waitForExpectations(timeout: 10) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") } - - func testCommentIncludes() { - let expectation = self.expectation(description: "testCommentDisplayByCommentId") - - let request = BVCommentsRequest(commentId: "12024") - request.addInclude(.authors) - request.addInclude(.products) - request.addInclude(.reviews) - - request.load({ (response) in - - XCTAssertEqual(response.results.count, 1) - - let theComment : BVComment = response.results.first! - - // Test included reviews - let theReview : BVReview = (theComment.includes?.getReviewById(theComment.reviewId!))! - XCTAssertNotNil(theReview) - XCTAssertNotNil(theReview.title) - - // Test included products - let theProduct : BVProduct = (theComment.includes?.getProductById(theReview.productId!))! - XCTAssertNotNil(theProduct) - XCTAssertNotNil(theProduct.name) - - // Test included authors - let theAuthor : BVAuthor = (theComment.includes?.getAuthorById(theComment.authorId!))! - XCTAssertNotNil(theAuthor) - XCTAssertNotNil(theAuthor.userNickname) - XCTAssertNotNil(theAuthor.authorId) - - expectation.fulfill() - - }) { (error) in - - XCTFail("comments by product id display request error: \(error)") - - } - - self.waitForExpectations(timeout: 10) { (error) in - XCTAssertNil(error, "Something went horribly wrong, request took too long.") - } - - + + } + + + func testCommentIncludes() { + let expectation = self.expectation(description: "testCommentDisplayByCommentId") + + let request = BVCommentsRequest(productId: "1000001", andCommentId: "12024") + request.addInclude(.authors) + request.addInclude(.products) + request.addInclude(.reviews) + + request.load({ (response) in + + XCTAssertEqual(response.results.count, 1) + + let theComment : BVComment = response.results.first! + + // Test included reviews + let theReview : BVReview = (theComment.includes?.getReviewById(theComment.reviewId!))! + XCTAssertNotNil(theReview) + XCTAssertNotNil(theReview.title) + + // Test included products + let theProduct : BVProduct = (theComment.includes?.getProductById(theReview.productId!))! + XCTAssertNotNil(theProduct) + XCTAssertNotNil(theProduct.name) + + // Test included authors + let theAuthor : BVAuthor = (theComment.includes?.getAuthorById(theComment.authorId!))! + XCTAssertNotNil(theAuthor) + XCTAssertNotNil(theAuthor.userNickname) + XCTAssertNotNil(theAuthor.authorId) + + expectation.fulfill() + + }) { (error) in + + XCTFail("comments by product id display request error: \(error)") + } - - func testCommentFilteringSorting() { - let expectation = self.expectation(description: "testCommentDisplayByCommentId") - - let limit : UInt16 = 90 - let offset : UInt16 = 0 - - let request = BVCommentsRequest(reviewId: "192548", limit: limit, offset: offset) - request.addFilter(.contentLocale, filterOperator: .equalTo, value: "en_US") - request.addCommentSort(.commentsSubmissionTime, order: .descending) - - request.load({ (response) in - - XCTAssertEqual(response.results.count, 5) - - expectation.fulfill() - - }) { (error) in - - XCTFail("comments by product id display request error: \(error)") - - } - - self.waitForExpectations(timeout: 10) { (error) in - XCTAssertNil(error, "Something went horribly wrong, request took too long.") - } - - + + self.waitForExpectations(timeout: 10) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") } - - func testCommentWithErrors() { - let expectation = self.expectation(description: "testCommentWithErrors") - - let request = BVCommentsRequest(commentId: "snoochieboochies") - request.addCustomDisplayParameter("bar", withValue: "food") - - request.load({ (response) in - - XCTFail("Call should have failed") - - expectation.fulfill() - - }) { (error) in - - XCTAssertTrue((error.first?.localizedDescription.contains("ERROR_PARAM_INVALID_FILTER_ATTRIBUTE"))!) - - expectation.fulfill() - - } - - self.waitForExpectations(timeout: 10) { (error) in - XCTAssertNil(error, "Something went horribly wrong, request took too long.") - } - + } + + func testCommentFilteringSorting() { + let expectation = self.expectation(description: "testCommentDisplayByCommentId") + + let limit : UInt16 = 90 + let offset : UInt16 = 0 + + let request = BVCommentsRequest(productId: "1000001", andReviewId: "192548", limit: limit, offset: offset) + request.addFilter(.contentLocale, filterOperator: .equalTo, value: "en_US") + request.addCommentSort(.commentsSubmissionTime, order: .descending) + + request.load({ (response) in + + XCTAssertEqual(response.results.count, 5) + + expectation.fulfill() + + }) { (error) in + + XCTFail("comments by product id display request error: \(error)") + + } + + self.waitForExpectations(timeout: 10) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") + } + + + } + + + + func testCommentWithErrors() { + let expectation = self.expectation(description: "testCommentWithErrors") + + let request = BVCommentsRequest(productId: "1000001", andCommentId: "snoochieboochies") + request.addCustomDisplayParameter("bar", withValue: "food") + + request.load({ (response) in + + XCTFail("Call should have failed") + + expectation.fulfill() + + }) { (error) in + + XCTAssertTrue((error.first?.localizedDescription.contains("ERROR_PARAM_INVALID_FILTER_ATTRIBUTE"))!) + + expectation.fulfill() + + } + + self.waitForExpectations(timeout: 10) { (error) in + XCTAssertNil(error, "Something went horribly wrong, request took too long.") } - + } }