Skip to content

Commit

Permalink
added 404 changes from Attribution PR (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboedo authored Sep 2, 2020
1 parent c03c935 commit 3727c95
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Purchases/Networking/RCBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,10 @@ - (void)handleSubscriberAttributesResultWithStatusCode:(NSInteger)statusCode
- (NSDictionary *)attributesUserInfoFromResponse:(NSDictionary *)response statusCode:(NSInteger)statusCode {
NSMutableDictionary *resultDict = [[NSMutableDictionary alloc] init];
BOOL isInternalServerError = statusCode >= RC_INTERNAL_SERVER_ERROR;
resultDict[RCSuccessfullySyncedKey] = @(!isInternalServerError);

BOOL isNotFoundError = statusCode == RC_NOT_FOUND_ERROR;
BOOL successfullySynced = !(isInternalServerError || isNotFoundError);
resultDict[RCSuccessfullySyncedKey] = @(successfullySynced);

BOOL hasAttributesResponseContainerKey = (response[RCAttributeErrorsResponseKey] != nil);
NSDictionary *attributesResponseDict = hasAttributesResponseContainerKey
? response[RCAttributeErrorsResponseKey]
Expand Down
1 change: 1 addition & 0 deletions Purchases/Networking/RCHTTPStatusCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, RCHTTPStatusCodes) {
RC_REDIRECT = 300,
RC_NOT_FOUND_ERROR = 404,
RC_INTERNAL_SERVER_ERROR = 500,
RC_NETWORK_CONNECT_TIMEOUT_ERROR = 599
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,35 @@ class BackendSubscriberAttributesTests: XCTestCase {
expect(self.mockHTTPClient.invokedPerformRequestCount) == 0
}

func testPostSubscriberAttributesCallsCompletionWithErrorInNotFoundCase() {
var completionCallCount = 0
mockHTTPClient.shouldInvokeCompletion = true
mockHTTPClient.stubbedCompletionStatusCode = 404
mockHTTPClient.stubbedCompletionError = nil

var receivedError: Error? = nil
backend.postSubscriberAttributes([
subscriberAttribute1.key: subscriberAttribute1,
subscriberAttribute2.key: subscriberAttribute2
],
appUserID: appUserID,
completion: { (error: Error!) in
completionCallCount += 1
receivedError = error
})

expect(self.mockHTTPClient.invokedPerformRequestCount) == 1
expect(completionCallCount).toEventually(equal(1))
expect(receivedError).toNot(beNil())
expect(receivedError).to(beAKindOf(Error.self))

let receivedNSError = receivedError! as NSError
expect(receivedNSError.code) == Purchases.ErrorCode.unknownBackendError.rawValue
expect(receivedNSError.successfullySynced()) == false
expect(receivedNSError.userInfo[RCSuccessfullySyncedKey]).toNot(beNil())
expect((receivedNSError.userInfo[RCSuccessfullySyncedKey] as! NSNumber).boolValue) == false
}

// MARK: PostReceipt with subscriberAttributes

func testPostReceiptWithSubscriberAttributesSendsThemCorrectly() {
Expand Down

0 comments on commit 3727c95

Please sign in to comment.