FSTDatastoreTests.mm 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Remote/FSTDatastore.h"
  17. #import <FirebaseFirestore/FIRFirestoreErrors.h>
  18. #import <XCTest/XCTest.h>
  19. @interface FSTDatastoreTests : XCTestCase
  20. @end
  21. @implementation FSTDatastoreTests
  22. - (NSError *)errorForCode:(FIRFirestoreErrorCode)code {
  23. return [NSError errorWithDomain:FIRFirestoreErrorDomain code:code userInfo:nil];
  24. }
  25. - (void)testIsPermanentError {
  26. // From GRPCCall -cancel
  27. NSError *error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  28. code:FIRFirestoreErrorCodeCancelled
  29. userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}];
  30. XCTAssertFalse([FSTDatastore isPermanentError:error]);
  31. // From GRPCCall -startNextRead
  32. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  33. code:FIRFirestoreErrorCodeResourceExhausted
  34. userInfo:@{
  35. NSLocalizedDescriptionKey :
  36. @"Client does not have enough memory to hold the server response."
  37. }];
  38. XCTAssertFalse([FSTDatastore isPermanentError:error]);
  39. // From GRPCCall -startWithWriteable
  40. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  41. code:FIRFirestoreErrorCodeUnavailable
  42. userInfo:@{NSLocalizedDescriptionKey : @"Connectivity lost."}];
  43. XCTAssertFalse([FSTDatastore isPermanentError:error]);
  44. // User info doesn't matter:
  45. error = [self errorForCode:FIRFirestoreErrorCodeUnavailable];
  46. XCTAssertFalse([FSTDatastore isPermanentError:error]);
  47. // "unauthenticated" is considered a recoverable error due to expired token.
  48. error = [self errorForCode:FIRFirestoreErrorCodeUnauthenticated];
  49. XCTAssertFalse([FSTDatastore isPermanentError:error]);
  50. error = [self errorForCode:FIRFirestoreErrorCodeDataLoss];
  51. XCTAssertTrue([FSTDatastore isPermanentError:error]);
  52. error = [self errorForCode:FIRFirestoreErrorCodeAborted];
  53. XCTAssertTrue([FSTDatastore isPermanentError:error]);
  54. }
  55. - (void)testIsPermanentWriteError {
  56. NSError *error = [self errorForCode:FIRFirestoreErrorCodeUnauthenticated];
  57. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  58. error = [self errorForCode:FIRFirestoreErrorCodeDataLoss];
  59. XCTAssertTrue([FSTDatastore isPermanentWriteError:error]);
  60. error = [self errorForCode:FIRFirestoreErrorCodeAborted];
  61. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  62. }
  63. @end